借助ROS的工具箱让turtlebot在gazebo中运行起来.
Part 1.1: 让turtlebot跑起来
1. 在gazebo中显示机器人
roslaunch turtlebot_gazebo turtlebot_world.launch
2. 用键盘进行控制机器人
<code class="hljs applescript has-numbering">roslaunch turtlebot_teleop keyboard_teleop.<span class="hljs-command">launch</span> <span class="hljs-comment">--screen </span></code>
<code class="hljs vbnet has-numbering">Moving around: u i o j k l m , . q/z : increase/decrease max speeds <span class="hljs-keyword">by</span> <span class="hljs-number">10</span>% w/x : increase/decrease only linear speed <span class="hljs-keyword">by</span> <span class="hljs-number">10</span>% e/c : increase/decrease only angular speed <span class="hljs-keyword">by</span> <span class="hljs-number">10</span>% space <span class="hljs-keyword">key</span>, k : force <span class="hljs-keyword">stop</span> anything <span class="hljs-keyword">else</span> : <span class="hljs-keyword">stop</span> smoothly </code>
可以通过以上方式控制机器人的运动了.
3. 在rviz中显示
<code class="hljs applescript has-numbering">roslaunch turtlebot_rviz_launchers view_robot.<span class="hljs-command">launch</span> <span class="hljs-comment">--screen </span></code>
在rviz的现实中,为了便于显示我只添加了camera rgb图像 (topic: /camera/rgb/image_raw)和 PointCloud2 (topic:/camera/depth/points). 同样也可以在左边的列表中添加laserscan (topic: /scan), DepthCloud (topic:/camera/depth/image_raw)等等. 关于Kinect2 (RGBD) 如何转换成laserscan, 以及点云转换都会在接下来的部分有所介绍.
part 1.2: 解释与扩展
1. gazebo启动文件
<code class="hljs has-numbering">roscd turtlebot_gazebo </code>
进入
<code class="hljs has-numbering">/opt/ros/indigo/share/turtlebot_gazebo </code>
<code class="hljs avrasm has-numbering">├── cmake │ ├── turtlebot_gazeboConfig<span class="hljs-preprocessor">.cmake</span> │ └── turtlebot_gazeboConfig-version<span class="hljs-preprocessor">.cmake</span> ├── launch │ ├── amcl_demo<span class="hljs-preprocessor">.launch</span> │ ├── gmapping_demo<span class="hljs-preprocessor">.launch</span> │ ├── includes │ │ ├── create<span class="hljs-preprocessor">.launch</span><span class="hljs-preprocessor">.xml</span> │ │ ├── kobuki<span class="hljs-preprocessor">.launch</span><span class="hljs-preprocessor">.xml</span> │ │ └── roomba<span class="hljs-preprocessor">.launch</span><span class="hljs-preprocessor">.xml</span> │ └── turtlebot_world<span class="hljs-preprocessor">.launch</span> ├── maps │ ├── playground<span class="hljs-preprocessor">.pgm</span> │ └── playground<span class="hljs-preprocessor">.yaml</span> ├── package<span class="hljs-preprocessor">.xml</span> └── worlds ├── corridor<span class="hljs-preprocessor">.world</span> ├── empty<span class="hljs-preprocessor">.world</span> └── playground<span class="hljs-preprocessor">.world </span></code>
可以找到我们加载的playground.world的文件. 在* turtlebot_world.launch*文件中, 通过加载gazebo_ros包中的empty.launch启动Gazebo, 通过名为world_name 的参数可以修改仿真的Gazebo环境. 将
<code class="hljs bash has-numbering"><arg name=<span class="hljs-string">"world_name"</span> value=<span class="hljs-string">"<span class="hljs-variable">$(arg world_file)</span>"</span>/> </code>
替换为
<code class="hljs bash has-numbering"><arg name=<span class="hljs-string">"world_name"</span> value=<span class="hljs-string">"<span class="hljs-variable">$(find turtlebot_gazebo)</span>/worlds/corridor.world"</span>/> </code>
可将Gazebo仿真环境替换为corridor. 通过在Gazebo中编辑环境也可以很轻松的可以生成自己的world. 哈哈, 现在可以不同的Gazebo物理环境中实现仿真了, 满足感溢出. 接下来我们看看Kinect2 (RGBD) 如何转换成laserscan, 我们会在下面发现name = "depthimage_to_laserscan"
, 通过remap
<code class="hljs livecodeserver has-numbering"><remap <span class="hljs-built_in">from</span>=<span class="hljs-string">"image"</span> <span class="hljs-built_in">to</span>=<span class="hljs-string">"/camera/depth/image_raw"</span>/> <remap <span class="hljs-built_in">from</span>=<span class="hljs-string">"scan"</span> <span class="hljs-built_in">to</span>=<span class="hljs-string">"/scan"</span>/> </code>
我们找到了在rviz中显示的topic了.
2. 机器人控制
除了上述提到的控制方法外,也可以采用
<code class="hljs avrasm has-numbering">roslaunch kobuki_keyop keyop<span class="hljs-preprocessor">.launch </span></code>
查看keyboard_teleop.launch文件,
<code class="hljs xml has-numbering"><span class="hljs-pi"><?xml version="1.0"?></span> <span class="hljs-tag"><<span class="hljs-title">launch</span>></span> <span class="hljs-tag"><<span class="hljs-title">node</span> <span class="hljs-attribute">pkg</span>=<span class="hljs-value">"turtlebot_teleop"</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"turtlebot_teleop_key"</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"turtlebot_teleop_keyboard"</span> <span class="hljs-attribute">output</span>=<span class="hljs-value">"screen"</span>></span> <span class="hljs-tag"><<span class="hljs-title">param</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"scale_linear"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"0.5"</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"double"</span>/></span> <span class="hljs-tag"><<span class="hljs-title">param</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"scale_angular"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"1.5"</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"double"</span>/></span> <span class="hljs-tag"><<span class="hljs-title">remap</span> <span class="hljs-attribute">from</span>=<span class="hljs-value">"turtlebot_teleop_keyboard/cmd_vel"</span> <span class="hljs-attribute">to</span>=<span class="hljs-value">"cmd_vel_mux/input/teleop"</span>/></span> <span class="hljs-tag"></<span class="hljs-title">node</span>></span> <span class="hljs-tag"></<span class="hljs-title">launch</span>> </span></code>
可以发现速度命令的topic映射到了主题cmd_vel_mux/input/teleop
, 查看主题类型
<code class="hljs fsharp has-numbering">rostopic <span class="hljs-class"><span class="hljs-keyword">type</span> <span class="hljs-title">cmd_vel_mux</span>/<span class="hljs-title">input</span>/<span class="hljs-title">teleop</span></span> geometry_msgs/Twist </code>
通过rostopic pub 命令
<code class="hljs rust has-numbering">rostopic <span class="hljs-keyword">pub</span> /cmd_vel_mux/input/teleop geometry_msgs/Twist <span class="hljs-string">"linear: x: 0.1 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.1" </span></code>
可以发送角速度0.1rad/s, 线速度0.1m/s, 可进一步查看 REP 103:Standard Units of Measure and Coordinate ConventionsREP 103:Standard Units of Measure and Coordinate Conventions .
3. 显示
rviz的显示可以很大程度的帮助ROS开发过程中的调试工作. 除了rviz外,还有一些其他的工具.
显示图像topic image_view
<code class="hljs mel has-numbering">rosrun image_view image_view <span class="hljs-keyword">image</span>:=/<span class="hljs-keyword">camera</span>/rgb/image_raw </code>
node与topic 连接图 rqt_graph
<code class="hljs has-numbering">rosrun rqt_graph rqt_graph </code>
参数可视化配置rqt_reconfigure
<code class="hljs has-numbering">rosrun rqt_reconfigure rqt_reconfigure </code>
rqt可以方便让你用所有rqt_初始的工具
<code class="hljs has-numbering">rqt </code>