在ROS中開始自主機器人仿真 - 2 讓turtlebot跑起來


借助ROS的工具箱讓turtlebot在gazebo中運行起來.

part 1.1: 讓turtlebot跑起來

1. 在gazebo中顯示機器人

roslaunch turtlebot_gazebo turtlebot_world.launch

turtlebot_world]![turtlebot_world

默認加載了一個playground 的world文件.

2. 用鍵盤進行控制機器人

roslaunch turtlebot_teleop keyboard_teleop.launch --screen
Moving around:
   u    i    o
   j    k    l
   m    ,    .

q/z : increase/decrease max speeds by 10%
w/x : increase/decrease only linear speed by 10%
e/c : increase/decrease only angular speed by 10%
space key, k : force stop
anything else : stop smoothly

可以通過以上方式控制機器人的運動了.

3. 在rviz中顯示

roslaunch turtlebot_rviz_launchers view_robot.launch --screen

rviz_world

在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啟動文件

roscd turtlebot_gazebo

進入

/opt/ros/indigo/share/turtlebot_gazebo
├── cmake
│   ├── turtlebot_gazeboConfig.cmake
│   └── turtlebot_gazeboConfig-version.cmake
├── launch
│   ├── amcl_demo.launch
│   ├── gmapping_demo.launch
│   ├── includes
│   │   ├── create.launch.xml
│   │   ├── kobuki.launch.xml
│   │   └── roomba.launch.xml
│   └── turtlebot_world.launch
├── maps
│   ├── playground.pgm
│   └── playground.yaml
├── package.xml
└── worlds
    ├── corridor.world
    ├── empty.world
    └── playground.world

可以找到我們加載的playground.world的文件.

* turtlebot_world.launch*文件中, 通過加載gazebo_ros包中的empty.launch啟動Gazebo, 通過名為world_name 的參數可以修改仿真的Gazebo環境. 

<arg name="world_name" value="$(arg world_file)"/>
替換為
<arg name="world_name" value="$(find turtlebot_gazebo)/worlds/corridor.world"/>
可將Gazebo仿真環境替換為corridor. 通過在Gazebo中編輯環境也可以很輕松的可以生成自己的world. 

哈哈, 現在可以不同的Gazebo物理環境中實現仿真了, 滿足感溢出.

接下來我們看看Kinect2 (RGBD) 如何轉換成laserscan, 我們會在下面發現name = "depthimage_to_laserscan", 通過remap

<remap from="image" to="/camera/depth/image_raw"/>
<remap from="scan" to="/scan"/>

我們找到了在rviz中顯示的topic了.

2. 機器人控制

除了上述提到的控制方法外,也可以采用

roslaunch kobuki_keyop keyop.launch

查看keyboard_teleop.launch文件,

<?xml version="1.0"?>
<launch>
  <node pkg="turtlebot_teleop" type="turtlebot_teleop_key" name="turtlebot_teleop_keyboard"  output="screen">
    <param name="scale_linear" value="0.5" type="double"/>
    <param name="scale_angular" value="1.5" type="double"/>
    <remap from="turtlebot_teleop_keyboard/cmd_vel" to="cmd_vel_mux/input/teleop"/>
  </node>
</launch>

可以發現速度命令的topic映射到了主題cmd_vel_mux/input/teleop, 查看主題類型

rostopic type cmd_vel_mux/input/teleop
geometry_msgs/Twist

通過rostopic pub 命令

rostopic pub /cmd_vel_mux/input/teleop geometry_msgs/Twist "linear:
  x: 0.1
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.1"

可以發送角速度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
rosrun image_view image_view  image:=/camera/rgb/image_raw
node與topic 連接圖 rqt_graph
rosrun rqt_graph rqt_graph

參數可視化配置rqt_reconfigure
rosrun rqt_reconfigure rqt_reconfigure
rqt可以方便讓你用所有rqt_初始的工具
rqt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM