ROS与javascript入门教程-ros3djs-可视化交互标记
ROS与javascript入门教程-ros3djs-可视化交互标记
说明:
- 介绍如何利用ros3djs进行可视化交互标记
步骤:
- 新建 interactive_markers.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 : '/rotating_frame'
});
// Setup the marker client.
var imClient = new ROS3D.InteractiveMarkerClient({
ros : ros,
tfClient : tfClient,
topic : '/basic_controls',
camera : viewer.camera,
rootObject : viewer.selectableObjects
});
}
</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
});
解释:
- 创建ROS3D.Viewer对象,用于放置内容
代码段:
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0,
fixedFrame : '/rotating_frame'
});
解释:
- 创建ROSLIB.TFClien对象,订阅TF树的变换
代码段:
var imClient = new ROS3D.InteractiveMarkerClient({
ros : ros,
tfClient : tfClient,
topic : '/basic_controls',
camera : viewer.camera,
rootObject : viewer.selectableObjects
});
- 解释:
- 创建ROS3D.InteractiveMarkerClient,用于显示交互内容
运行:
- 需要 interactive_marker_tutorials, interactive_marker_proxy, rosbridge_server和tf2_web_republisher包
- 服务器,新终端,运行
rosrun interactive_marker_tutorials basic_controls
- 服务器,新终端,运行
rosrun interactive_marker_proxy proxy topic_ns:=/basic_controls target_frame:=/rotating_frame
- 服务器,新终端,运行
rosrun tf2_web_republisher tf2_web_republisher
- 服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
- 浏览器运行interactive_markers.html
参考:
- http://wiki.ros.org/ros3djs/Tutorials/VisualizingInteractiveMarkers
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号