ROS与javascript入门教程-ros3djs-可视化标记话题
ROS与javascript入门教程-ros3djs-可视化标记话题
说明:
- 介绍如何通过ros3djs可视化标记话题
步骤:
新建marker_topic.html
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="http://cdn.robotwebtools.org/threejs/current/three.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/EventEmitter2/current/eventemitter2.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/roslibjs/current/roslib.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/ros3djs/current/ros3d.min.js"></script>
<script type="text/javascript" type="text/javascript">
/**
* Setup all visualization elements when the page is loaded.
*/
function init() {
// Connect to ROS.
var ros = new ROSLIB.Ros({
url : 'ws://localhost:9090'
});
// Create the main viewer.
var viewer = new ROS3D.Viewer({
divID : 'markers',
width : 800,
height : 600,
antialias : true
});
// Setup a client to listen to TFs.
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0,
fixedFrame : '/my_frame'
});
// Setup the marker client.
var markerClient = new ROS3D.MarkerClient({
ros : ros,
tfClient : tfClient,
topic : '/visualization_marker',
rootObject : viewer.scene
});
}
</script>
</head>
<body onload="init()">
<h1>Simple Marker Example</h1>
<div id="markers"></div>
</body>
</html>
代码解析:
- 代码段:
var viewer = new ROS3D.Viewer({
divID : 'markers',
width : 800,
height : 600,
antialias : true
});
解释:用于显示标记内容
代码段:
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0,
fixedFrame : '/my_frame'
});
解释:创建ROSLIB.TFClient对象,用于订阅相应的变换
代码段:
var markerClient = new ROS3D.MarkerClient({
ros : ros,
tfClient : tfClient,
topic : '/visualization_marker',
rootObject : viewer.scene
});
解释:
- 创建ROS3D.MarkerClient对象,用于获取标记内容和显示标记
运行:
需要 visualization_marker_tutorials, rosbridge_server, and tf2_web_republisher 包
服务器,新终端,运行
rosrun visualization_marker_tutorials basic_shapes
- 服务器,新终端,运行
rosrun tf2_web_republisher tf2_web_republisher
- 服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
- 浏览器访问marker_topic.html
参考:
- http://wiki.ros.org/ros3djs/Tutorials/VisualizingAMarkerTopic
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号