本专栏旨在通过对ROS的系统学习,掌握ROS底层基本分布式原理,并具有机器人建模和应用ROS进行实际项目的开发和调试的工程能力。
详情:《ROS从入门到精通》
在ROS从入门到精通3-3:Solidworks三维建模并导入Rviz、Gazebo图文教程中我们用Solidworks导出了自主设计的机器人模型,如下所示
但是这些零件不具有实际的功能,比如没有电机能控制轮轴旋转、摄像头无法获取图像、激光雷达不能进行扫描,因此本节将对urdf引入gazebo插件,使机器人的各个零件能发挥各自作用,并与gazebo环境进行联合仿真
ros_control
是ROS为用户提供的应用与机器人之间的中间件,包含一系列控制器接口、传动装置接口、硬件接口、控制器工具箱等。不同的机器人平台只要按照这套规范实现,那么就可以保证与ROS应用兼容。通过ros_control
可以实现插拔式架构,大大提高了程序设计的效率、灵活性与异构平台的多态性。
Gazebo中已经实现了ros_control
的相关接口,因此直接调用Gazebo相关接口即可控制机器人运动。
运动控制集成分为两步:
<xacro:macro name="joint_trans" params="joint_name">
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmissiontype>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterfacehardwareInterface>
joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterfacehardwareInterface>
<mechanicalReduction>1mechanicalReduction>
actuator>
transmission>
xacro:macro>
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<rosDebugLevel>narosDebugLevel>
<robotNamespace>/robotNamespace>
<publishTf>1publishTf>
<publishWheelTF>falsepublishWheelTF>
<publishWheelJointState>falsepublishWheelJointState>
<alwaysOn>truealwaysOn>
<updateRate>100.0updateRate>
<legacyMode>truelegacyMode>
<leftJoint>left_wheel_jointleftJoint>
<rightJoint>right_wheel_jointrightJoint>
<wheelSeparation>0.28wheelSeparation>
<wheelDiameter>0.08wheelDiameter>
<broadcastTF>1broadcastTF>
<wheelTorque>10wheelTorque>
<wheelAcceleration>1wheelAcceleration>
<commandTopic>cmd_velcommandTopic>
<odometryFrame>odomodometryFrame>
<odometryTopic>odomodometryTopic>
<odometrySource>worldodometrySource>
<publishOdomTF>truepublishOdomTF>
<robotBaseFrame>base_footprintrobotBaseFrame>
plugin>
gazebo>
添加完成后即可通过cmd_vel
话题控制机器人运动
采用Gazebo中的gazebo_rplidar
插件实现
<xacro:macro name="scan_gazebo" params="scan_name">
<gazebo reference="${scan_name}">
<sensor type="ray" name="rplidar">
<pose>0 0 0 0 0 0pose>
<visualize>truevisualize>
<update_rate>5.5update_rate>
<ray>
<scan>
<horizontal>
<samples>360samples>
<resolution>1resolution>
<min_angle>-3min_angle>
<max_angle>3max_angle>
horizontal>
scan>
<range>
<min>0.10min>
<max>30.0max>
<resolution>0.01resolution>
range>
<noise>
<type>gaussiantype>
<mean>0.0mean>
<stddev>0.01stddev>
noise>
ray>
<plugin name="gazebo_rplidar" filename="libgazebo_ros_laser.so">
<topicName>/scantopicName>
<frameName>laserframeName>
plugin>
sensor>
gazebo>
xacro:macro>
Gazebo中激光雷达可视化
采用Gazebo中的kinect_camera_controller
插件实现
<xacro:macro name="kinect_gazebo" params="kinect_name">
<gazebo reference="${kinect_name}">
<sensor type="depth" name="camera">
<always_on>truealways_on>
<update_rate>20.0update_rate>
<camera>
<horizontal_fov>${60.0*3.14/180.0}horizontal_fov>
<image>
<format>R8G8B8format>
<width>640width>
<height>480height>
image>
<clip>
<near>0.05near>
<far>8.0far>
clip>
camera>
<plugin name="kinect_camera_controller" filename="libgazebo_ros_openni_kinect.so">
<cameraName>cameracameraName>
<alwaysOn>truealwaysOn>
<updateRate>10updateRate>
<imageTopicName>rgb/image_rawimageTopicName>
<depthImageTopicName>depth/image_rawdepthImageTopicName>
<pointCloudTopicName>depth/pointspointCloudTopicName>
<cameraInfoTopicName>rgb/camera_infocameraInfoTopicName>
<depthImageCameraInfoTopicName>depth/camera_infodepthImageCameraInfoTopicName>
<frameName>${kinect_name}frameName>
<baseline>0.1baseline>
<distortion_k1>0.0distortion_k1>
<distortion_k2>0.0distortion_k2>
<distortion_k3>0.0distortion_k3>
<distortion_t1>0.0distortion_t1>
<distortion_t2>0.0distortion_t2>
<pointCloudCutoff>0.4pointCloudCutoff>
plugin>
sensor>
gazebo>
xacro:macro>
[ WARN] [1660283011.791926958, 50.632000000]: Timed out waiting for transform from base_footprint to map to become available before running costmap, tf error: canTransform: target_frame map does not exist.. canTransform returned after 50.632 timeout was 0.1.
解决方案:在没有amcl、map_server等模块的帮助下,tf树中map
和base_footprint
坐标是断开的,因此可以手动发布一个tf信息来修复
<node pkg="tf" type="static_transform_publisher" name="map_broadcaster" args="0.20 0 0 0 0 0 map odom 50" />
No laser scan received (and thus no pose updates have been published) for 66.175000 seconds. Verify that data is being published on the /scan topic.
解决方案:导致这个问题的原因有很多,对于自定义的机器人urdf文件,需要检查所有Gazebo插件中涉及frameName
的参数是否和link_name
一致,例如我的激光雷达连杆是
<link name="scan_link">
那么gazebo_rplidar
插件插件中就对应
<plugin name="gazebo_rplidar" filename="libgazebo_ros_laser.so">
<topicName>scantopicName>
<frameName>scan_linkframeName>
plugin>
多机器人实验时发现只发布了一个/odom
解决方案:将differential_drive_controller
插件中的
标签去掉,否则为机器人增加tf_prefix
前缀或命名空间无效
更多精彩专栏: