ROS 學習系列 -- 執行turtlebot navigation的方法

我們講一下如何使用現有的turtlebot launch文件來啓動navigation,並在PC上使用rviz指揮。

1. 網絡環境佈置

turtlebot單片機我們使用的是firefly,rviz運行在PC上,它們使用wifi通訊。master ros運行在firefly上,PC需要指向firefly。在PC修改IP到firefly主機的映射,修改/etc/hosts 文件,如

sudo nano /etc/hosts

打開hosts後,我們從前面幾行開始插入firefly單片機的ip地址和hostname,形式如下:

127.0.0.1       localhost
127.0.1.1       pc_hostname
192.168.1.16    firefly

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
完畢後保存並確認可以在PC上ping通firefly名字本身。


在firefly單片機上source下面的腳本內容,設定turtlebot爲master ROS節點:

export TURTLEBOT_BASE=roomba
export TURTLEBOT_STACKS=circles
export TURTLEBOT_3D_SENSOR=asus_xtion_pro
export TURTLEBOT_SIMULATION=false
export TURTLEBOT_SERIAL_PORT=/dev/ttyUSB0
export ROS_IP=192.168.1.16
export TURTLEBOT_MAP_FILE=/home/firefly/room323.yaml

在PC上source下面的腳本內容,指向turtlebot爲master ROS節點:

export ROS_MASTER_URI=http://firefly:11311
export ROS_HOSTNAME=<span style="font-family:SimSun;">pc_hostname</span>

2. 安裝必要軟件包 

在firefly單片機上執行下面的腳本安裝:

sudo apt-get install ros-indigo-turtlebot ros-indigo-rocon-app-platform ros-indigo-rocon-multimaster ros-indigo-rocon-msgs ros-indigo-rocon-qt-gui ros-indigo-rocon-tools ros-indigo-std-capabilities ros-indigo-rqt-capabilities ros-indigo-rocon-remocon ros-indigo-rocon-apps ros-indigo-turtlebot-rapps

在PC上執行下面的腳本安裝:

sudo apt-get install ros-indigo-turtlebot-rviz-launchers
當然RVIZ 是必須已經安裝完了


3. 啓動turtlebot和rviz 
在firefly單片機上打開一個終端執行下面腳本:

roslaunch turtlebot_bringup minimal.launch

在firefly單片機上打開第二個終端執行下面腳本:

roslaunch  turtlebot_app nav_map.launch

注意這裏一定要設置環境變量 TURTLEBOT_MAP_FILE 註明地圖yaml文件的位置。這個時候,turtlebot已經可以使用了,準備接受命令移動。


執行下面腳本在PC上執行腳本:

roslaunch turtlebot_rviz_launchers view_navigation.launch --screen
這時候就可以看到rviz上顯示如下畫面,點擊按鈕'2D Pose Estimate' '2D Nav Goal'就可以導航了:



4. 簡化後的turtlebot啓動腳本

在firefly單片機上只執行一個簡化後的launch腳本也可以,腳本內容如下:

<!--
  Right now, the android app is hard coded to look for /cmd_vel as the input
  topic.
 -->
<launch>  
  
<!-- Turtlebot -->
  <arg name="base"              default="$(env TURTLEBOT_BASE)"         doc="mobile base type [create, roomba]"/>
  <arg name="battery"           default="$(env TURTLEBOT_BATTERY)"      doc="kernel provided locatio for battery info, use /proc/acpi/battery/BAT0 in 2.6 or earlier kernels." />
  <arg name="stacks"            default="$(env TURTLEBOT_STACKS)"       doc="stack type displayed in visualisation/simulation [circles, hexagons]"/>
  <arg name="3d_sensor"         default="$(env TURTLEBOT_3D_SENSOR)"    doc="3d sensor types [kinect, asux_xtion_pro]"/>
  <arg name="simulation"        default="$(env TURTLEBOT_SIMULATION)"   doc="set flags to indicate this turtle is run in simulation mode."/>
  <arg name="serialport"        default="$(env TURTLEBOT_SERIAL_PORT)"  doc="used by create to configure the port it is connected on [/dev/ttyUSB0, /dev/ttyS0]"/>
  <arg name="robot_name"        default="$(env TURTLEBOT_NAME)"         doc="used as a unique identifier and occasionally to preconfigure root namespaces, gateway/zeroconf ids etc."/>
  <arg name="robot_type"        default="$(env TURTLEBOT_TYPE)"         doc="just in case you are considering a 'variant' and want to make use of this."/>

  <param name="/use_sim_time" value="$(arg simulation)"/>

  <include file="$(find turtlebot_bringup)/launch/includes/robot.launch.xml">
    <arg name="base" value="$(arg base)" />
    <arg name="stacks" value="$(arg stacks)" />
    <arg name="3d_sensor" value="$(arg 3d_sensor)" />
  </include>
  <include file="$(find turtlebot_bringup)/launch/includes/mobile_base.launch.xml">
    <arg name="base" value="$(arg base)" />
    <arg name="serialport" value="$(arg serialport)" />
  </include>  
  
  <arg name="scan_topic"              default="scan"/>
  <arg name="cmd_vel_topic"           default="/teleop/cmd_vel"/>
  <arg name="compressed_image_topic"  default="/teleop/compressed_image"/>
  
  <include file="$(find turtlebot_bringup)/launch/3dsensor.launch">
    <arg name="rgb_processing" value="false" />
    <arg name="depth_registration" value="false" />
    <arg name="depth_processing" value="false" />
  </include>

  <!-- Make a slower camera feed available. -->
  <!-- *********************** Teleoperation ********************** -->
  <param name="camera/rgb/image_color/compressed/jpeg_quality" value="22"/>
  <!-- 
  <node pkg="topic_tools" type="throttle" name="camera_throttle" args="messages camera/rgb/image_rect_color/compressed 5"/>
  -->
  
  <node pkg="nodelet" type="nodelet" name="teleop_velocity_smoother"
        args="load yocs_velocity_smoother/VelocitySmootherNodelet /mobile_base_nodelet_manager">
    <rosparam file="$(find turtlebot_bringup)/param/defaults/smoother.yaml" command="load"/>
    <remap from="teleop_velocity_smoother/raw_cmd_vel" to="$(arg cmd_vel_topic)"/>
    <remap from="teleop_velocity_smoother/smooth_cmd_vel" to="/cmd_vel_mux/input/teleop"/>

    <!-- Robot velocity feedbacks; use the one configured as base default -->
    <remap from="teleop_velocity_smoother/odometry"       to="/odom"/>
    <remap from="teleop_velocity_smoother/robot_cmd_vel"  to="/mobile_base/commands/velocity"/>
  </node>

  <!-- *********************** Optimisation *********************** -->
  <node pkg="tf" type="tf_change_notifier" name="tf_throttle_for_android_gui">
    <param name="polling_frequency"             value="5"/>
    <param name="translational_update_distance" value="-1"/>
    <param name="angular_update_distance"       value="-1"/>
    <rosparam param="frame_pairs">
      - {source_frame: base_footprint, target_frame: map}
      - {source_frame: camera_depth_frame, target_frame: map}
    </rosparam>
  </node>


  <!-- *************************** Navi *************************** -->
  <include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml">
    <arg name="odom_topic" value ="/odom" />
  </include>
  <include file="$(find turtlebot_navigation)/launch/includes/amcl.launch.xml">
    <arg name="use_map_topic" value ="true"/>
  </include>
  
  <!--
  <node pkg="topic_tools" type="throttle" name="relay_compressed_throttle_image" args="messages camera/rgb/image_rect_color/compressed_throttle 5 $(arg compressed_image_topic)" required="true">
    <param name="lazy" value="false"/>
  </node>
  -->
  
  <node pkg="topic_tools" type="throttle" name="relay_scan" args="messages scan 5 $(arg scan_topic)" required="true">
    <param name="lazy" value="false"/>
  </node>

  <!-- Maps -->
  <arg name="map_file" default=" $(env TURTLEBOT_MAP_FILE)" />
  <node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)" />


<!--  <node pkg="map_store" type="map_manager" name="map_manager" output="screen"/>-->

  <!-- World Canvas -->
  <arg name="debug" default="false"/>
  <node pkg="world_canvas_server" type="world_canvas_server" name="world_canvas_server" args="$(arg debug)" output="screen">
    <param name="start_map_manager" value="true"/>
    <param name="auto_save_map" value="false"/>
  </node> 
</launch>


發佈了36 篇原創文章 · 獲贊 88 · 訪問量 30萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章