rbx1包裏機器人仿真程序的實踐

1.打開一個終端
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_bringup fake_turtlebot.launch
2.新打開一個終端
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_nav fake_move_base_blank_map.launch 
要是避障的話,運行
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_nav fake_move_base_map_with_obstacles.launch
3.新打開一個終端
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
rosrun rviz rviz -d `rospack find rbx1_nav`/nav_fuerte.rviz
ADD這三個play就能夠了,還要再ADDcostmap
4.新打開一個終端
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 0, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
 
 
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "base_link" }, pose: { position: { x: 1.0, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
 
 
不能帶<這個符號,否則不成功
ctrl+shift +t 測試
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "base_link" }, pose: { position: { x: 1.0, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 2, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
的確x軸向前移動了2米
 
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 0, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 2, y:1, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
不行,出錯
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 0, y:1, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
一次只能朝向一個方向行走
點擊一下2d_Nav Goal,點擊鼠標左鍵,能夠選定一個目標位置,接着機器人就能夠移動到目標位置
5.讓機器人回到原點
rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped \
'{ header: { frame_id: "map" }, pose: { position: { x: 0, y: 0, z: 0 }, orientation: { x: 0, y: 0, z: 0, w: 1 } } }'
點擊rviz上的reset
6,打開一個新終端,
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src

rosrun rbx1_nav move_base_square.py  node

 
能夠看到機器人沿一個正方形在走(這個代碼解釋已經完成)
7.第二步是運行了一個空白地圖,如今把它換成帶有障礙物的地圖,找到這個終端,ctrl+c退出這個地圖,而後運行
 roslaunch rbx1_nav fake_move_base_map_with_obstacles.launch
 
8.再運行rosrun rbx1_nav move_base_square.py  
能夠看到機器人在正方形區域避障行走
3、amcl定位
先運行仿真機器人
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_bringup fake_turtlebot.launch
新打開一個終端,運行amcl節點,使用的已經準備好的測試地圖,這個地圖不是咱們本身建的地圖,咱們本身要建地圖的話,須要使用深度數據,而後用gmapping生成地圖,amcl是二維環境下的機率定位系統,之因此說是機率定位系統,是由於它用的是自適應的蒙特卡洛的定位方法,就是以前的粒子濾波,用這個粒子濾波去跟蹤機器人當前的狀態。
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
 

roslaunch rbx1_nav fake_amcl.launch map:=test_map.yamlgit

先來看一下這個launch文件是怎麼寫的。
<launch>
  <!-- Set the name of the map yaml file: can be overridden on the command line. -->
  <arg name="map" default="test_map.yaml" />
  <!-- Run the map server with the desired map -->
  <node name="map_server" pkg="map_server" type="map_server" args="$(find rbx1_nav)/maps/$(arg map)"/>
  <!-- The move_base node -->
  <include file="$(find rbx1_nav)/launch/fake_move_base.launch" />
 
  <!-- Run fake localization compatible with AMCL output -->
  <node pkg="fake_localization" type="fake_localization"  name="fake_localization" output="screen" />
  <!-- For fake localization we need static transforms between /odom and /map and /map and /world -->
  <node pkg="tf" type="static_transform_publisher" name="odom_map_broadcaster" 
args="0 0 0 0 0 0 /odom /map 100" />
</launch>
能夠看到它調用了map_server包用來加載地圖,fake_localization,tf包裏的static_transform_publisher的工具,還調用了fake_move_base_launch文件打開move_base節點並加載配置文件,而後運行amcl節點。主要做用是加載了一個地圖(以下所示)
 
而後運行rviz
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src

rosrun rviz rviz -d `rospack find rbx1_nav`/nav_fuerte.rvizgithub

我是在rviz里加載了這幾個display,其中global plan下的costmap,RobotModel,global plan下的Path,Axes是必須的。

而後就能夠在rviz中看到實際效果了。左鍵選定目標位置,機器人就能夠自主規劃繞開障礙物到達目的地了。
程序:
1.
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_bringup fake_turtlebot.launch
 
2.
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_nav fake_amcl.launch map:=test_map.yaml
3.
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
rosrun rviz rviz -d `rospack find rbx1_nav`/nav_fuerte.rviz
4、自主導航
但咱們老是但願機器人可以自主進行導航,這樣才更智能化。下面它作的是讓目標點在地圖中隨機生成,而後讓機器人自動導航到達其目標。
首先來看一下它的launch文件fake_nav_test.launch
<launch>
 
  <param name="use_sim_time" value="false" />
 
  <!-- Start the ArbotiX controller -->
  <include file="$(find rbx1_bringup)/launch/fake_turtlebot.launch" />
 
  <!-- Run the map server with the desired map -->
  <node name="map_server" pkg="map_server" type="map_server" args="$(find rbx1_nav)/maps/test_map.yaml"/>
 
  <!-- The move_base node -->
  <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
    <rosparam file="$(find rbx1_nav)/config/fake/costmap_common_params.yaml" command="load" ns="global_costmap" />
    <rosparam file="$(find rbx1_nav)/config/fake/costmap_common_params.yaml" command="load" ns="local_costmap" />
    <rosparam file="$(find rbx1_nav)/config/fake/local_costmap_params.yaml" command="load" />
    <rosparam file="$(find rbx1_nav)/config/fake/global_costmap_params.yaml" command="load" />
    <rosparam file="$(find rbx1_nav)/config/fake/base_local_planner_params.yaml" command="load" />
    <rosparam file="$(find rbx1_nav)/config/nav_test_params.yaml" command="load" />
  </node>
 
  <!-- Run fake localization compatible with AMCL output -->
  <node pkg="fake_localization" type="fake_localization" name="fake_localization" output="screen" />
 
  <!-- For fake localization we need static transform between /odom and /map -->
  <node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 /map /odom 100" />
 
  <!-- Start the navigation test -->
  <node pkg="rbx1_nav" type="nav_test.py" name="nav_test" output="screen">
    <param name="rest_time" value="1" />
    <param name="fake_test" value="true" />
  </node>
 
</launch>
這個launch文件的功能比較多
(1)加載機器人驅動( <include file="$(find rbx1_bringup)/launch/fake_turtlebot.launch" />這樣咱們就不用在終端中再去加載機器人驅動了)
(2)加載地圖
 <node name="map_server" pkg="map_server" type="map_server" args="$(find rbx1_nav)/maps/test_map.yaml"/>
這裏的地圖就是map_server,有時候可不須要
(3)調用move_base節點
 <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen">
而且加載了它的幾個配置文件,分別是:
costmap_common_params.yaml,local_costmap_params.yaml,global_costmap_params.yaml,base_local_planner_params.yaml,nav_test_params.yaml
(4)調用以前的amcl節點
<node pkg="fake_localization" type="fake_localization" name="fake_localization" output="screen" />
(5)固然還有tf
<node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 /map /odom 100" />
(6)加載nav_test.py程序,進行隨機導航(這裏的隨機是指目標點位置隨機)
其實這個launch文件好像是把以前運行的幾個launch文件進行整合了。
運行
roscore
運行 
rqt_console(這個程序若是運行不了的話,運行sudo apt-get install ros-indigo-rqt ros-indigo-rqt-common-plugins ros-indigo-turtlesim,參考: http://blog.exbot.net/archives/1413
打開一個新終端,運行
 
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_nav fake_nav_test.launch 
打開一個新終端,運行
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
rosrun rviz rviz -d `rospack find rbx1_nav`/nav_test_fuerte.rviz
運行結果以下
以前運行的rqt_console是用來作調試的,能夠看到機器人發送的狀態信息。
    好比
 
能夠看到目標點信息(going to ),狀態信息(state),距離信息(Distance),成功率,速度等
程序:
1.
roscore
2.
rqt_console
3.
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
roslaunch rbx1_nav fake_nav_test.launch 

4.bash

 
cd ~/catkin_ws/
catkin_make
source ./devel/setup.bash
cd src
rosrun rviz rviz -d `rospack find rbx1_nav`/nav_test_fuerte.rviz
 
相關文章
相關標籤/搜索