Gazebo plugins in ROS
1. 要了解
Gazebo插件为URDF模型提供了更大的功能,并且可以将ROS消息和服务调用捆绑在一起以用于传感器输出和电动机输入。
2. 插件类型
凉亭支持几种插件类型,它们都可以连接到ROS,但是只能通过URDF文件引用几种类型:
- ModelPlugins,提供对Physical :: Model API的访问
- SensorPlugins,用于提供对传感器的访问:: Sensor API
- VisualPlugins,提供对render :: Visual API的访问
3. 添加一个ModelPlugin
把ModelPlugin插入< robot >元素内的URDF中,它包含有< gazebo >标签,以指示传递给Gazebo的信息。
<robot>
... robot description ...
<gazebo>
<plugin name="differential_drive_controller" filename="libdiffdrive_plugin.so">
... plugin parameters ...
</plugin>
</gazebo>
... robot description ...
</robot>
在凉亭内加载机器人模型后,将为diffdrive_plugin代码提供对模型本身的引用,以允许其进行操作。
4. 添加一个SensorPlugin
指定传感器插件的时候,Gazebo中的传感器应该连接到link上,所以描述该传感器的< gazebo >必须被赋予对该link的引用。
<robot>
... robot description ...
<link name="sensor_link">
... link description ...
</link>
<gazebo reference="sensor_link">
<sensor type="camera" name="camera1">
... sensor parameters ...
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
... plugin parameters ..
</plugin>
</sensor>
</gazebo>
</robot>
如果在凉亭内加载机器人模型,camera_controller代码将被赋予对传感器的引用,从而可以访问其API。
5. gazebo_plugins中的所有可用插件
每个部分的名称都是从插件类名称派生的。例如,“ Block Laser”来自GazeboRosBlockLaser类,可以在文件gazebo_plugins / src / gazebo_ros_block_laser.cpp中找到。
5.1 Camera
描述:提供了ROS接口,用于通过发布sensor_msgs中所述的CameraInfo和Image ROS消息来模拟wge100_camera之类的摄像机。
示例:在RRBot摆臂末端安装了RGB相机,link3上边的红色框表示相机。
<joint name="camera_joint" type="fixed">
<axis xyz="0 1 0" />
<origin xyz="${camera_link} 0 ${height3 - axel_offset*2}" rpy="0 0 0"/>
<parent link="link3"/>
<child link="camera_link"/>
</joint>
<!-- Camera -->
<link name="camera_link">
<collision>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="${camera_link} ${camera_link} ${camera_link}"/>
</geometry>
</collision>
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="${camera_link} ${camera_link} ${camera_link}"/>
</geometry>
<material name="red"/>
</visual>
<inertial>
<mass value="1e-5" />
<origin xyz="0 0 0" rpy="0 0 0"/>
<inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
</inertial>
</link>
Gazebo插件提供了摄像头功能,把图像发布到ROS消息中,在rrbot.gazebo中:
<!-- camera -->
<gazebo reference="camera_link">
<sensor type="camera" name="camera1">
<update_rate>30.0</update_rate>
<camera name="head">
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
<noise>
<type>gaussian</type>
<!-- Noise is sampled independently per pixel on each frame.
That pixel's noise value is added to each of its color
channels, which at that point lie in the range [0,1]. -->
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<alwaysOn>true</alwaysOn>
<updateRate>0.0</updateRate>
<cameraName>rrbot/camera1</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
<frameName>camera_link_optical</frameName>
<!-- setting hackBaseline to anything but 0.0 will cause a misalignment
between the gazebo sensor image and the frame it is supposed to
be attached to -->
<hackBaseline>0.0</hackBaseline>
<distortionK1>0.0</distortionK1>
<distortionK2>0.0</distortionK2>
<distortionK3>0.0</distortionK3>
<distortionT1>0.0</distortionT1>
<distortionT2>0.0</distortionT2>
<CxPrime>0</CxPrime>
<Cx>0.0</Cx>
<Cy>0.0</Cy>
<focalLength>0.0</focalLength>
</plugin>
</sensor>
</gazebo>
Gazebo内每秒拍摄一次新相机图像的次数:
<update_rate>30.0</update_rate>
假定像素为正方形,填写这些值以匹配物理相机的规格,近片段和远片段是特定于仿真的参数,为摄像机在仿真中可以看到对象的距离提供了上限和下限。:
<horizontal_fov>1.3962634</horizontal_fov>
<image>
<width>800</width>
<height>800</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.02</near>
<far>300</far>
</clip>
实际的gazebo_ros / gazebo_ros_camera.cpp文件在此处链接为共享对象:
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
这里为图像主题和相机信息主题定义了相机将发布到的rostopic:
<cameraName>rrbot/camera1</cameraName>
<imageTopicName>image_raw</imageTopicName>
<cameraInfoTopicName>camera_info</cameraInfoTopicName>
它们分别为:
/rrbot/camera1/image_raw
/rrbot/camera1/camera_info
图像在tf树中发布的坐标框架:
<frameName>camera_link_optical</frameName>
测试一下
roslaunch rrbot_gazebo rrbot_world.launch
roslaunch rrbot_description rrbot_rviz.launch
在Gazebo中添加一座房子,Camera传回图像:
5.2 GPU Laser(激光测距传感器)
通过广播LaserScan消息来模拟激光测距传感器,在RRBot中:
<joint name="hokuyo_joint" type="fixed">
<axis xyz="0 1 0" />
<origin xyz="0 0 ${height3 - axel_offset/2}" rpy="0 0 0"/>
<parent link="link3"/>
<child link="hokuyo_link"/>
</joint>
<!-- Hokuyo Laser -->
<link name="hokuyo_link">
<collision>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<box size="0.1 0.1 0.1"/>
</geometry>
</collision>
<visual>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<mesh filename="package://rrbot_description/meshes/hokuyo.dae"/>
</geometry>
</visual>
<inertial>
<mass value="1e-5" />
<origin xyz="0 0 0" rpy="0 0 0"/>
<inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
</inertial>
</link>
从代码看出:这次使用的是网格物体,而不是仅使用可视模型的矩形:
<mesh filename="package://rrbot_description/meshes/hokuyo.dae"/>
同理,将其信息添加到rrbot.gazebo中:
<!-- hokuyo -->
<gazebo reference="hokuyo_link">
<sensor type="gpu_ray" name="head_hokuyo_sensor">
<pose>0 0 0 0 0 0</pose>
<visualize>false</visualize>
<update_rate>40</update_rate>
<ray>
<scan>
<horizontal>
<samples>720</samples>
<resolution>1</resolution>
<min_angle>-1.570796</min_angle>
<max_angle>1.570796</max_angle>
</horizontal>
</scan>
<range>
<min>0.10</min>
<max>30.0</max>
<resolution>0.01</resolution>
</range>
<noise>
<type>gaussian</type>
<!-- Noise parameters based on published spec for Hokuyo laser
achieving "+-30mm" accuracy at range < 10m. A mean of 0.0m and
stddev of 0.01m will put 99.7% of samples within 0.03m of the true
reading. -->
<mean>0.0</mean>
<stddev>0.01</stddev>
</noise>
</ray>
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">
<topicName>/rrbot/laser/scan</topicName>
<frameName>hokuyo_link</frameName>
</plugin>
</sensor>
</gazebo>
这里如果为true,则在gpu激光的扫描区域内可以看到半透明的激光射线:
<visualize>false</visualize>
将这些设置为将激光扫描发布到的ROS主题名称,以及TF使用的转换框架:
<topicName>/rrbot/laser/scan</topicName>
<frameName>hokuyo_link</frameName>
测试一下
roslaunch rrbot_gazebo rrbot.launch
roslaunch rrbot_description rrbot_rviz.launch
5.3 Laser
非GPU版本的GPU Laser,但本质上使用相同的代码,将:
<sensor type="gpu_ray" name="head_hokuyo_sensor">
替换为:
<sensor type="ray" name="head_hokuyo_sensor">
将:
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">
替换为:
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
5.4 其他
- Multicamera
- Depth Camera
- Openni Kinect
- Block Laser
- IMU (GazeboRosImu)
- IMU sensor (GazeboRosImuSensor)
- Joint Pose Trajectory
- P3D (3D Position Interface for Ground Truth)
- Projector
- Prosilica Camera
- Bumper
- Differential Drive
- Skid Steering Drive
- Video Plugin
- Planar Move Plugin
- Template