ROS与javascript入门教程-roslibjs-使用TF
ROS与javascript入门教程-roslibjs-使用TF
说明:
- 介绍如何在roslibjs中使用TF
github:
步骤:
- 新建 tf.html 文件
- 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" type="text/javascript">
var ros = new ROSLIB.Ros({
url : 'ws://localhost:9090'
});
var tfClient = new ROSLIB.TFClient({
ros : ros,
fixedFrame : 'world',
angularThres : 0.01,
transThres : 0.01
});
tfClient.subscribe('turtle1', function(tf) {
console.log(tf);
});
ros.on('connection', function() {
console.log('Connected to websocket server.');
});
ros.on('error', function(error) {
console.log('Error connecting to websocket server: ', error);
});
ros.on('close', function() {
console.log('Connection to websocket server closed.');
});
</script>
</head>
<body>
<h1>Simple TF Example</h1>
<p>Check the JavaScript console for the output.</p>
</body>
</html>
代码解析:
- 代码段:
var tfClient = new ROSLIB.TFClient({
ros : ros,
fixedFrame : 'world',
angularThres : 0.01,
transThres : 0.01
});
解释:
- 利用ROSLIB.TFClient对象订阅TF
- 更多ROSLIB.TFClient参考文档:http://robotwebtools.org/jsdoc/roslibjs/current/TFClient.html
代码段:
tfClient.subscribe('turtle1', function(tf) {
console.log(tf);
});
解释:
- 订阅坐标系world和turtle1之间的变换
运行:
- 服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
- 服务器端,新终端,运行
rosrun tf2_web_republisher tf2_web_republisher
- 服务器端,新终端,运行
roslaunch turtle_tf turtle_tf_demo.launch
- chrome浏览器运行tf.html
参考:
- http://wiki.ros.org/roslibjs/Tutorials/TfClient
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号