Sunday, October 7, 2018

Gazebo camera plugin

resource

Plugins can be added to any of the main elements of a URDF - a <robot>, <link>, or <joint> depending on what the scope and purpose of the plugin is. when add <plugin> to urdf we wrap it with <gazebo> element

<gazebo reference="<link_name>"> <plugin name="camera_controller" filename="libgazebo_ros_camera.so"> ... plugin parameters ... </plugin> </gazebo>

Gazebo Camera

<gazebo reference="camera_link"> <sensor type="camera" name="camera"> <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> <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>bot/camera</cameraName> <imageTopicName>image_raw</imageTopicName> <cameraInfoTopicName>camera_info</cameraInfoTopicName> <frameName>camera_link</frameName> <hackBaseline>0.07</hackBaseline> <distortionK1>0.0</distortionK1> <distortionK2>0.0</distortionK2> <distortionK3>0.0</distortionK3> <distortionT1>0.0</distortionT1> <distortionT2>0.0</distortionT2> </plugin> </sensor> </gazebo> </robot>

Name and Topic

<sensor type="camera" name="camera">
  • sensor name must be unique and used by cameraName
<cameraName>bot/camera</cameraName> <imageTopicName>image_raw</imageTopicName> <cameraInfoTopicName>camera_info</cameraInfoTopicName>

rostopic list

rostopic list /bot/camera/camera_info /bot/camera/image_raw /bot/camera/image_raw/compressed /bot/camera/image_raw/compressed/parameter_descriptions /bot/camera/image_raw/compressed/parameter_updates /bot/camera/image_raw/compressedDepth /bot/camera/image_raw/compressedDepth/parameter_descriptions /bot/camera/image_raw/compressedDepth/parameter_updates /bot/camera/image_raw/theora /bot/camera/image_raw/theora/parameter_descriptions /bot/camera/image_raw/theora/parameter_updates /bot/camera/parameter_descriptions /bot/camera/parameter_updates ...

tf

The coordinate frame the image is published under in the tf tree.

<frameName>camera_link</frameName>

Test

  • Terminal 1(launch gazebo)
roslaunch gazebo_ros empty_world.launch
  • Terminal 2(spawn)
#from urdf path rosrun gazebo_ros spawn_model -file camera.urdf -urdf -model bot
  • Terminal 3(rqt)
rqt # Plugins -> Visualization-> image viewer # From combo /bot/camera/image_raw
  • From gazebo add model in the front of camera

  • Check view in rqt

Full urdf code

<?xml version="1.0"?> <robot name="bot"> <!-- Camera --> <link name="camera_link"> <collision> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.05 0.05 0.05"/> </geometry> </collision> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.05 0.05 0.05"/> </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 reference="camera_link"> <sensor type="camera" name="camera"> <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> <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>bot/camera</cameraName> <imageTopicName>image_raw</imageTopicName> <cameraInfoTopicName>camera_info</cameraInfoTopicName> <frameName>camera_link</frameName> <hackBaseline>0.07</hackBaseline> <distortionK1>0.0</distortionK1> <distortionK2>0.0</distortionK2> <distortionK3>0.0</distortionK3> <distortionT1>0.0</distortionT1> <distortionT2>0.0</distortionT2> </plugin> </sensor> </gazebo> </robot>

No comments: