在Ubuntu 16.04+ ROS Kinetic环境学习《Learning ROS for Robotics Programming Second Edition》 chapter 8 The Navigation Stack –Robot Setups时候没有办法直接运行作者给出的示例,做了部分修改记录在下文。
===========================================Part one==============================================
1 案例运行命令
roslaunch chapter8_tutorials gazebo_mapping_robot.launch model:="`rospack find robot1_description`/urdf/robot1_base_04.xacro"
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
失败消息这里省略,和第九章类似。
2 修改文件
2.1 chapter8_tutorials/launch/gazebo_mapping_robot.launch
注释掉红色行
<node name="slam_gmapping" pkg="gmapping" type="slam_gmapping">
<!--<remap from="scan" to="/robot/laser/scan"/> -->
<param name="base_link" value="base_footprint"/>
</node>
2.2 chapter8_tutorials/urdf/robot1_base_04.xacro
修改如下红色
<!-- Drive controller -->
<gazebo>
<plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">
<updateRate>100.0</updateRate>
<robotNamespace>/</robotNamespace>
<leftFrontJoint>base_to_wheel1</leftFrontJoint>
<rightFrontJoint>base_to_wheel3</rightFrontJoint>
<leftRearJoint>base_to_wheel2</leftRearJoint>
<rightRearJoint>base_to_wheel4</rightRearJoint>
<wheelSeparation>4</wheelSeparation>
<wheelDiameter>0.1</wheelDiameter>
<robotBaseFrame>base_footprint</robotBaseFrame> //原来为base_link
<torque>1</torque>
<topicName>cmd_vel</topicName>
<broadcastTF>true</broadcastTF> //原来为0
</plugin>
</gazebo>
2.3 修改文件chapter7_tutorials/robot1_description/urdf/robot.gazebo
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
<topicName>/scan</topicName> //原来为/robot/laser/scan
<frameName>hokuyo_link</frameName>
</plugin>
3 正常运行输出结果
3.1 rviz和gazebo
如下为rviz图,
如下为gazebo图,
运行成功后执行如下命令保存地图:
rosrun map_server map_saver -f map
===========================================Part2============================
1 运行命令
查看并使用之前保存的地图
roslaunch chapter8_tutorials gazebo_map_robot1.launch model:="`rospack
find chapter8_tutorials`/urdf/robot1_base_04.xacro"
2 修改文件
添加文件chaper8/launch/gazebo_map_robot1.launch
<?xml version="1.0"?>
<launch>
<param name="/use_sim_time" value="true" />
<!-- start up wg world -->
<include file="$(find gazebo_ros)/launch/willowgarage_world.launch" />
<arg name="model" />
<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)" />
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
<!-- start robot state publisher -->
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen" >
<param name="publish_frequency" type="double" value="50.0" />
</node>
<node name="spawn_robot" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -z 0.1 -model robot_model" respawn="false" output="screen" >
</node>
<node name="map_server" pkg="map_server" type="map_server" args="$(find chapter8_tutorials)/maps/map.yaml" output="screen">
</node>
<node pkg="tf" type="static_transform_publisher" name="odom_map_broadcaster" args="0 0 0 0 0 0 /map /odom 100" /> //很重要没有无法运行成功,原本书上没有
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find chapter8_tutorials)/launch/mapping.rviz" >
</node>
</launch>
3 运行效果
来源:CSDN
作者:倔强不倒翁
链接:https://blog.csdn.net/x_r_su/article/details/53504784