< >
Home » ROS与JS入门教程 » ROS与javascript入门教程-nav2djs-2D导航组件

ROS与javascript入门教程-nav2djs-2D导航组件

ROS与javascript入门教程-nav2djs-2D导航组件

说明:

  • 介绍创建简单2D导航组件

步骤:

  • 新建nav2d.html
  • 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />

<script type="text/javascript" src="http://cdn.robotwebtools.org/EaselJS/current/easeljs.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/ros2djs/current/ros2d.min.js"></script>
<script type="text/javascript" src="http://cdn.robotwebtools.org/nav2djs/current/nav2d.min.js"></script>

<script type="text/javascript">
  /**
   * Setup all GUI 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 ROS2D.Viewer({
      divID : 'nav',
      width : 750,
      height : 800
    });

    // Setup the nav client.
    var nav = NAV2D.OccupancyGridClientNav({
      ros : ros,
      rootObject : viewer.scene,
      viewer : viewer,
      serverName : '/pr2_move_base'
    });
  }
</script>
</head>

<body onload="init()">
  <h1>Simple Navigation Example</h1>
  <div id="nav"></div>
</body>
</html>

代码解析:

  • 代码段:
var viewer = new ROS2D.Viewer({
  divID : 'nav',
  width : 750,
  height : 800
});
  • 解释:
    • 创建ROS2D.Viewer对象,用于放在导航地图
  • 代码段:
 var nav = NAV2D.OccupancyGridClientNav({
  ros : ros,
  rootObject : viewer.scene,
  viewer : viewer,
  serverName : '/pr2_move_base'
});
  • 解释:
    • 创建NAV2D.OccupancyGridClientNav对象,用于获取导航地图内容

运行:

  • 需要安装pr2_simulator, rosbridge_server, pr2_2dnav, willow_maps, 和robot_pose_publisher包

  • 服务器,新终端,运行gazebo

roslaunch pr2_gazebo pr2_wg_world.launch
  • 服务器,新终端,运行
export ROBOT=sim
rosrun map_server map_server /opt/ros/xxx/stacks/wg_common/willow_maps/willow-sans-whitelab-2010-02-18-0.025.pgm 0.025
  • 服务器,新终端,运行
roslaunch pr2_2dnav pr2_2dnav.launch
  • 服务器,新终端,运行
roslaunch pr2_tuckarm tuck_arms.launch
  • 服务器,新终端,运行
rosrun robot_pose_publisher robot_pose_publisher
  • 服务器,新终端,运行
roslaunch rosbridge_server rosbridge_websocket.launch
  • 浏览器运行nav2d.html

参考:

  • http://wiki.ros.org/nav2djs/Tutorials/CreatingABasicNav2DWidget

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros与javascript入门教程