需要运行的几个launch文件
1、启动turtlebot的launch文件
$ roslaunch turtlebot_bringup minimal.launch
2、自主行驶的launch文件
$ roslaunch turtlebot_navigation amcl_demo.launch
3、在rviz观察tb在地图上的移动的launch文件
$ roslaunch turtlebot_rviz_launchers view_navigation.launch --screen
<launch>
<!-- 3D sensor -->
<arg name="3d_sensor"
default="$(env TURTLEBOT_3D_SENSOR)"/> <!-- r200, kinect, asus_xtion_pro
-->
<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" />
<!-- We must specify an absolute
topic name because if not it will be prefixed by "$(arg
camera)".
Probably is a bug in the nodelet
manager: https://github.com/ros/nodelet_core/issues/7 -->
<arg name="scan_topic"
value="/scan" />
</include>
<!-- Map server -->
<arg name="map_file"
default="$(env TURTLEBOT_MAP_FILE)"/>
<node name="map_server"
pkg="map_server" type="map_server" args="$(arg
map_file)" />
<!-- AMCL -->
<arg
name="custom_amcl_launch_file" default="$(find
turtlebot_navigation)/launch/includes/amcl/$(arg
3d_sensor)_amcl.launch.xml"/>
<arg name="initial_pose_x"
default="0.0"/> <!-- Use 17.0 for willow's map in simulation
-->
<arg name="initial_pose_y"
default="0.0"/> <!-- Use 17.0 for willow's map in simulation
-->
<arg name="initial_pose_a"
default="0.0"/>
<include file="$(arg
custom_amcl_launch_file)">
<arg
name="initial_pose_x" value="$(arg initial_pose_x)"/>
<arg
name="initial_pose_y" value="$(arg
initial_pose_y)"/>
<arg
name="initial_pose_a" value="$(arg
initial_pose_a)"/>
</include>
<!-- Move base -->
<arg
name="custom_param_file" default="$(find
turtlebot_navigation)/param/$(arg 3d_sensor)_costmap_params.yaml"/>
<include file="$(find
turtlebot_navigation)/launch/includes/move_base.launch.xml">
<arg
name="custom_param_file" value="$(arg
custom_param_file)"/>
</include>
</launch>
<launch>
<!-- 3D sensor -->
<arg name="3d_sensor"
default="$(env TURTLEBOT_3D_SENSOR)"/> <!-- r200, kinect, asus_xtion_pro
-->
<include file="$(find
ydlidar)/launch/lidar_view.launch">
<param name="port" type="string"
value="/dev/ydlidar"/>
<param
name="baudrate"
type="int"
value="115200"/>
<param
name="frame_id"
type="string" value="laser_frame"/>
<param
name="angle_fixed"
type="bool"
value="true"/>
<param
name="low_exposure"
type="bool"
value="false"/>
<param
name="heartbeat"
type="bool"
value="false"/>
<param
name="resolution_fixed"
type="bool"
value="true"/>
<param
name="angle_min"
type="double" value="-180" />
<param
name="angle_max"
type="double" value="180" />
<param
name="range_min"
type="double" value="0.08" />
<param
name="range_max"
type="double" value="16.0" />
<param
name="ignore_array" type="string" value=""
/>
<param
name="samp_rate"
type="int"
value="9"/>
<param name="frequency" type="double"
value="7"/>
<!-- We must specify an absolute
topic name because if not it will be prefixed by "$(arg
camera)".
Probably is a bug in the nodelet
manager: https://github.com/ros/nodelet_core/issues/7 -->
</include>
<!-- Run the map server -->
<arg name="map_file"
default="$(find turtlebot_navigation)/maps/map5.yaml"/>
<node name="map_server"
pkg="map_server" type="map_server" args="$(arg
map_file)" />
<!-- AMCL -->
<arg
name="custom_amcl_launch_file" default="$(find
turtlebot_navigation)/launch/includes/amcl/$(arg
3d_sensor)_amcl.launch.xml"/>
<arg name="initial_pose_x"
default="0.0"/> <!-- Use 17.0 for willow's map in simulation
-->
<arg name="initial_pose_y"
default="0.0"/> <!-- Use 17.0 for willow's map in simulation
-->
<arg name="initial_pose_a"
default="0.0"/>
<include file="$(arg
custom_amcl_launch_file)">
<arg
name="initial_pose_x" value="$(arg
initial_pose_x)"/>
<arg
name="initial_pose_y" value="$(arg
initial_pose_y)"/>
<arg name="initial_pose_a"
value="$(arg initial_pose_a)"/>
</include>
<!-- Move base -->
<arg
name="custom_param_file" default="$(find
turtlebot_navigation)/param/$(arg
3d_sensor)_costmap_params.yaml"/>
<include file="$(find
turtlebot_navigation)/launch/includes/move_base.launch.xml">
<arg
name="custom_param_file" value="$(arg
custom_param_file)"/>
<include file="$(find
turtlebot_navigation)/laser/move_base_turtlebot_laser.launch" />
</include>
</launch>
如何修改?
我们知道激光雷达是我们自己装在turtlebot上的,turtlebot2有自己的相机,写好的包也是与原本相匹配的,但是因为很多人学习激光雷达与其结合,所以也有laser这个文件,我们所修改的内容就是从此而来,在turtlebot_navigation/laser 中可以看到laser_amcl_demo.launch中
<!-- Run the map server -->
<arg name="map_file"
default="$(find
turtlebot_navigation)/maps/willow-2010-02-18-0.10.yaml"/>
<node name="map_server"
pkg="map_server" type="map_server" args="$(arg
map_file)" />
<!--- Run Move Base -->
<include file="$(find
turtlebot_navigation)/laser/move_base_turtlebot_laser.launch" />
我把他们加入到amcl_demo.launch里面
只需要修改所使用的地图就可以了,因为原来里面的地图服务,运行时加上map_file:=/*** 使用总是出错,虽然改过之后使用不同地图都要修改launch文件,但奈何没有错误。
以及加了移动基础Move Base,其实内容都是一样的。
turtlebot_navigation)/maps/willow-2010-02-18-0.10.yaml"/>
加粗字体为地图名称,前面为路径
<include file="$(find
ydlidar)/launch/lidar_view.launch">
<param name="port" type="string"
value="/dev/ydlidar"/>
<param
name="baudrate"
type="int"
value="115200"/>
<param
name="frame_id"
type="string" value="laser_frame"/>
<param
name="angle_fixed"
type="bool"
value="true"/>
<param
name="low_exposure"
type="bool"
value="false"/>
<param
name="heartbeat"
type="bool"
value="false"/>
<param
name="resolution_fixed"
type="bool"
value="true"/>
<param
name="angle_min"
type="double" value="-180" />
<param
name="angle_max"
type="double" value="180" />
<param
name="range_min"
type="double" value="0.08" />
<param
name="range_max"
type="double" value="16.0" />
<param
name="ignore_array" type="string" value=""
/>
<param
name="samp_rate"
type="int"
value="9"/>
<param name="frequency" type="double"
value="7"/>
这些都是激光雷达参数,原来使用的是相机,只需要把参数改成激光雷达的,以及寻找激光雷达的文件就可以了。我不知道加不加TF转换,我没加可以运行。这些东西存在于ydlidar_master/launch/lidar.launch中,只需要找到需要的部分复制就行了。
修改之后,依次运行上面三个launch文件就行了。
初始化turtlebot姿态:
rviz里面点击2D Pose Estimate 选择地图上一点选择方向,此时的位置和方向是turtlebot2的位置和方向。
选择移动到的地点:
rviz里面点击2D Nav Goal 选择地图上一点并选择方向,turtlebot2会规划好路径并开始移动,直至到达目标地点。