学艺不精,使用turtlebot进行仿真时发现无论如何如何在gazebo都不能运行,我尝试使用mbot和turtlebot3进行gazebo仿真都很顺利,但这使用卡在我心上,在又学了一段时间ros后,我又回头来解决这个问题。
turtlebot不能在gazebo运行的关键原因就在于他的底盘是kobuki,因此我们会安装kobuki的相关资源,这些完成之后应该能操作现实的机器人,但要turtlebot与gazebo交互还差了一个模块:kobuki_gazebo
查找控制插件
首先,我们要清楚ros和gazebo是独立的,ros和gazebo交互需要通过gazebo提供的plugin,在turtlebot和mbot中都有以下的plugin
<!-- controller -->
<gazebo>
<plugin name="differential_drive_controller"
filename="libgazebo_ros_diff_drive.so">
<rosDebugLevel>WARN</rosDebugLevel>
<publishWheelTF>true</publishWheelTF>
<robotNamespace>/</robotNamespace>
<publishTf>1</publishTf>
<publishOdomTF>1</publishOdomTF>
<odometrySource>world</odometrySource> <!-- 'encoder' instead of 'world' is also possible -->
<publishWheelJointState>true</publishWheelJointState>
<alwaysOn>true</alwaysOn>
<updateRate>100.0</updateRate>
<legacyMode>true</legacyMode>
<leftJoint>left_wheel_joint</leftJoint>
<rightJoint>right_wheel_joint</rightJoint>
<wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
<wheelDiameter>${2*wheel_radius}</wheelDiameter>
<broadcastTF>1</broadcastTF>
<wheelTorque>30</wheelTorque>
<wheelAcceleration>1.8</wheelAcceleration>
<commandTopic>cmd_vel</commandTopic>
<odometryFrame>odom</odometryFrame>
<odometryTopic>odom</odometryTopic>
<robotBaseFrame>base_footprint</robotBaseFrame>
</plugin>
看到注释,我们也清楚这就是controller的功能,他所需要的库为libgazebo_ros_diff_drive.so,这是我们安装ros-full时就存在的,这插件也是控制ros的命令能够让gazebo反馈出来。
接下来我们分析turtlebot
在turtlebot_description/robots/kobuki_hexagons_kinect.urdf.xacro中
<xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_common_library.urdf.xacro" />
<xacro:include filename="$(find kobuki_description)/urdf/kobuki.urdf.xacro" />
<xacro:include filename="$(find turtlebot_description)/urdf/stacks/hexagons.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/kinect.urdf.xacro"/>
引入了4个xacro文件,其中引入了kobuki.urdf.xacro
在kobuki_description/urdf/kobuki.urdf.xacro中引入了
<xacro:include filename="$(find kobuki_description)/urdf/common_properties.urdf.xacro"/>
<xacro:include filename="$(find kobuki_description)/urdf/kobuki_gazebo.urdf.xacro"/>
其中kobuki_gazebo就是与gazebo交互的配置文件
我们找到他的controller
<gazebo>
<plugin name="kobuki_controller" filename="libgazebo_ros_kobuki.so">
<publish_tf>1</publish_tf>
<left_wheel_joint_name>wheel_left_joint</left_wheel_joint_name>
<right_wheel_joint_name>wheel_right_joint</right_wheel_joint_name>
<wheel_separation>.230</wheel_separation>
<wheel_diameter>0.070</wheel_diameter>
<torque>1.0</torque>
<velocity_command_timeout>0.6</velocity_command_timeout>
<cliff_sensor_left_name>cliff_sensor_left</cliff_sensor_left_name>
<cliff_sensor_center_name>cliff_sensor_front</cliff_sensor_center_name>
<cliff_sensor_right_name>cliff_sensor_right</cliff_sensor_right_name>
<cliff_detection_threshold>0.04</cliff_detection_threshold>
<bumper_name>bumpers</bumper_name>
<imu_name>imu</imu_name>
</plugin>
</gazebo>
发现与turtlebot3不同,他的controller使用的插件为libgazebo_ros_robuki.so
安装kobuki_gazebo插件
找到kobuki_gazebo的plugin位置,我一开始以为是插件配置失败,又尝试了很多无用功。我突然想到定位这些库的位置,然后发现
locate libgazebo_ros_kobuki.so
竟然为空!!!现在结果已经很明确了,因为缺少必要的库,所以无法正常控制turtlebot_gazebo
在搜索之后,我发现kobuki_gazebo的github为
https://github.com/yujinrobot/kobuki_desktop
下载完并编译成功,我在自己的catkin_ws下找到了 libgazebo_ros_kobuki.so
至此
roslaunch turtlebot_gazebo turtlebot_world.launch
rostopic pub -1 /mobile_base/commands/velocity geometry_msgs/Twist -- '[0.5,0,0]' '[0,0,0]'
已经可以让turtlebot在gazebo中运动起来