ROS与javascript入门教程-ros3djs-可视化Map
ROS与javascript入门教程-ros3djs-可视化Map
说明:
- 介绍如何通过ros3djs可视化Map
github
步骤:
新建map.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 : 'map',
width : 800,
height : 600,
antialias : true
});
// Setup the map client.
var gridClient = new ROS3D.OccupancyGridClient({
ros : ros,
rootObject : viewer.scene
});
}
</script>
</head>
<body onload="init()">
<h1>Simple Map Example</h1>
<div id="map"></div>
</body>
</html>
代码解析:
- 代码段:
var viewer = new ROS3D.Viewer({
divID : 'map',
width : 800,
height : 600,
antialias : true
});
解释:创建ROS3D.Viewer对象,用于视图放置
代码段:
var gridClient = new ROS3D.OccupancyGridClient({
ros : ros,
rootObject : viewer.scene
});
- 解释:创建ROS3D.OccupancyGridClient对象,用于保存场景
运行:
需要 map_server, rail_maps, and rosbridge_server包
服务器,新终端, 运行
rosrun map_server map_server /opt/ros/groovy/share/rail_maps/maps/ilab.pgm 0.05
- 服务器,新终端, 运行
roslaunch rosbridge_server rosbridge_websocket.launch
- 浏览器运行map.html
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号