Link .gazebo file to .urdf

Hi @staff

I am trying to make my urdf code cleaner, in this way I have seen some ROS users that use xacro and also put the plugins structure outside the URDF model. Well in this case my robot is not so big, so I will not create a xacro…however I would like to create a .gazebo file to put my plugins (because I am using several cameras and a diff-drive plugin). However I am using an example of a guy which used xacro to model his robot…So my link .gazebo file and .urdf file is not being linked, and the plugins are not appearing in my simulation…I did not found any tutorial that explains me how to connect the .gazebo file with urdf. Can someone help me? My .gazebo file is below:

<?xml version="1.0"?>
<!-- camera -->
  <gazebo reference="camera_link">
  <sensor name="camera" type="depth">
    <update_rate>20</update_rate>
    <camera>


      <horizontal_fov>1.047198</horizontal_fov>
      <image>
	<width>3000</width>
	<height>2800</height>
	<format>R8G8B8</format>
      </image>
      <clip>
	<near>0.05</near>
	<far>8</far>
      </clip>
    </camera>
    <plugin name="camera_link_controller" filename="libgazebo_ros_openni_kinect.so">
      <baseline>0.2</baseline>
      <alwaysOn>true</alwaysOn>
      <updateRate>1.0</updateRate>
      <cameraName>camera</cameraName>
      <imageTopicName>/camera/rgb/image_raw</imageTopicName>
      <cameraInfoTopicName>/camera/rgb/camera_info</cameraInfoTopicName>
      <depthImageTopicName>/camera/depth/image_raw</depthImageTopicName>
      <depthImageCameraInfoTopicName>/camera/depth/camera_info</depthImageCameraInfoTopicName>
      <pointCloudTopicName>/camera/depth/points</pointCloudTopicName>
      <frameName>camera_rgb_optical_frame</frameName>
      <pointCloudCutoff>0.5</pointCloudCutoff>
      <pointCloudCutoffMax>3.0</pointCloudCutoffMax>
      <distortionK1>0.00000001</distortionK1>
      <distortionK2>0.00000001</distortionK2>
      <distortionK3>0.00000001</distortionK3>
      <distortionT1>0.00000001</distortionT1>
      <distortionT2>0.00000001</distortionT2>
      <CxPrime>0</CxPrime>
      <Cx>0</Cx>
      <Cy>0</Cy>
      <focalLength>0</focalLength>
      <hackBaseline>0</hackBaseline>
    </plugin>
  </sensor>
</gazebo>


    <!-- camera 2-->
  <gazebo reference="camera2_link">
  <sensor name="camera2" type="depth">
    <update_rate>20</update_rate>
    <camera>



      <horizontal_fov>1.447198</horizontal_fov>
      <image>
	<width>640</width>
	<height>480</height>
	<format>R8G8B8</format>
      </image>
      <clip>
	<near>0.05</near>
	<far>3</far>
      </clip>
    </camera>
    <plugin name="camera2_link_controller" filename="libgazebo_ros_openni_kinect.so">
      <baseline>0.2</baseline>
      <alwaysOn>true</alwaysOn>
      <updateRate>1.0</updateRate>
      <cameraName>camera2</cameraName>
      <imageTopicName>/camera2/rgb/image_raw</imageTopicName>
      <cameraInfoTopicName>/camera2/rgb/camera_info</cameraInfoTopicName>
      <depthImageTopicName>/camera2/depth/image_raw</depthImageTopicName>
      <depthImageCameraInfoTopicName>/camera2/depth/camera_info</depthImageCameraInfoTopicName>
      <pointCloudTopicName>/camera2/depth/points</pointCloudTopicName>
      <frameName>camera2_rgb_optical_frame</frameName>
      <pointCloudCutoff>0.5</pointCloudCutoff>
      <pointCloudCutoffMax>3.0</pointCloudCutoffMax>
      <distortionK1>0.00000001</distortionK1>
      <distortionK2>0.00000001</distortionK2>
      <distortionK3>0.00000001</distortionK3>
      <distortionT1>0.00000001</distortionT1>
      <distortionT2>0.00000001</distortionT2>
      <CxPrime>0</CxPrime>
      <Cx>0</Cx>
      <Cy>0</Cy>
      <focalLength>0</focalLength>
      <hackBaseline>0</hackBaseline>
    </plugin>
  </sensor>
</gazebo>

  <!-- camera 3 -->
  <gazebo reference="camera3_link">
  <sensor name="camera3" type="depth">
    <update_rate>20</update_rate>
    <camera>


      <horizontal_fov>1.047198</horizontal_fov>
      <image>
	<width>640</width>
	<height>480</height>
	<format>R8G8B8</format>
      </image>
      <clip>
	<near>0.05</near>
	<far>3</far>
      </clip>
    </camera>
    <plugin name="camera3_link_controller" filename="libgazebo_ros_openni_kinect.so">
      <baseline>0.2</baseline>
      <alwaysOn>true</alwaysOn>
      <updateRate>1.0</updateRate>
      <cameraName>camera3</cameraName>
      <imageTopicName>/camera3/rgb/image_raw</imageTopicName>
      <cameraInfoTopicName>/camera3/rgb/camera_info</cameraInfoTopicName>
      <depthImageTopicName>/camera3/depth/image_raw</depthImageTopicName>
      <depthImageCameraInfoTopicName>/camera3/depth/camera_info</depthImageCameraInfoTopicName>
      <pointCloudTopicName>/camera3/depth/points</pointCloudTopicName>
      <frameName>camera3_rgb_optical_frame</frameName>
      <pointCloudCutoff>0.5</pointCloudCutoff>
      <pointCloudCutoffMax>3.0</pointCloudCutoffMax>
      <distortionK1>0.00000001</distortionK1>
      <distortionK2>0.00000001</distortionK2>
      <distortionK3>0.00000001</distortionK3>
      <distortionT1>0.00000001</distortionT1>
      <distortionT2>0.00000001</distortionT2>
      <CxPrime>0</CxPrime>
      <Cx>0</Cx>
      <Cy>0</Cy>
      <focalLength>0</focalLength>
      <hackBaseline>0</hackBaseline>
    </plugin>
  </sensor>
</gazebo>

So what should I add, remove or change?

Or this feature of using a .gazebo file for plugins can just be used with .xacro files?

Thanks in advance!

Just use XACROS, its very usefull and it really doesnt matter if your robot is small. It allowa much more flexibility and among other things, linking you r.gazebo file.

In the course of URDF there is a Unit talking about XACROS. Its very simpe and you will get the hang of it fast.

1 Like