ROS与javascript入门教程-ros3djs-可视化URDF模型
ROS与javascript入门教程-ros3djs-可视化URDF模型
说明:
- 介绍如果通过ros3djs可视化URDF模型
github:
步骤:
新建urdf.html
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://cdn.robotwebtools.org/threejs/current/three.min.js"></script>
<script src="http://cdn.robotwebtools.org/threejs/current/ColladaLoader.min.js"></script>
<script src="http://cdn.robotwebtools.org/ColladaAnimationCompress/current/ColladaLoader2.min.js"></script>
<script src="http://cdn.robotwebtools.org/threejs/current/STLLoader.min.js"></script>
<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 src="http://cdn.robotwebtools.org/ros3djs/current/ros3d.min.js"></script>
<script>
/**
* 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 : 'urdf',
width : 800,
height : 600,
antialias : true
});
// Add a grid.
viewer.addObject(new ROS3D.Grid());
// Setup a client to listen to TFs.
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0
});
// Setup the URDF client.
var urdfClient = new ROS3D.UrdfClient({
ros : ros,
tfClient : tfClient,
path : 'http://resources.robotwebtools.org/',
rootObject : viewer.scene,
loader : ROS3D.COLLADA_LOADER_2
});
}
</script>
</head>
<body onload="init()">
<h1>Simple URDF Example</h1>
<div id="urdf"></div>
</body>
</html>
代码解析:
- 代码段:
var viewer = new ROS3D.Viewer({
divID : 'urdf',
width : 800,
height : 600,
antialias : true
});
- 解释:
- 创建ROS3D.Viewer对象,用于放置视图内容
- 代码段:
viewer.addObject(new ROS3D.Grid());
解释:增加网格显示xy轴
代码段:
var tfClient = new ROSLIB.TFClient({
ros : ros,
angularThres : 0.01,
transThres : 0.01,
rate : 10.0
});解释:创建ROSLIB.TFClient对象,默认使用/base_link作为固定坐标系
代码段:
var urdfClient = new ROS3D.UrdfClient({
ros : ros,
tfClient : tfClient,
path : 'http://resources.robotwebtools.org/',
rootObject : viewer.scene,
loader : ROS3D.COLLADA_LOADER_2
});
- 解释:
- 创建ROS3D.UrdfClient对象,用于整合内容
- path:提供urdf来源路径,package:// 来源本地或meshes,如:package:///body/meshes/body.dae
- 或者使用http://,如http://localhost:8000/body/meshes/body.dae
- 载入器会使用robot_description参数作为URDF模型
- loader:会使用两种Collada载入器, PR2使用ColladaLoader2,其他 ColladaLoader,来自THREE.js (ROS3D.COLLADA_LOADER)
浏览器要求png格式,urdf的为tiff格式,两种处理方法:
- 进行格式转换
convert myimage.tiff myimage.png
- URDF直接使用png格式
运行:
需要 pr2_description, robot_state_publisher, joint_state_publisher, rosbridge_server, 和tf2_web_republisher 包
服务器,新终端,运行
roslaunch pr2_description upload_pr2.launch
- 服务器,新终端,运行
rosrun robot_state_publisher robot_state_publisher
- 服务器,新终端,运行
rosparam set use_gui true
- 服务器,新终端,运行
rosrun joint_state_publisher joint_state_publisher
- 服务器,新终端,运行
rosrun tf2_web_republisher tf2_web_republisher
- 服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
- 浏览器执行urdf.html
参考:
- http://wiki.ros.org/ros3djs/Tutorials/VisualizingAURDF
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号