How to Add a Depth Camera to an SDF File for Gazebo


In the cover image, you can see a depth camera that was added to a simulated robot in Gazebo. An depth camera is useful for performing tasks like object recognition, facial recognition, obstacle avoidance, and more.

Adding a depth camera is important if you’re planning to build a robust robot for the real-world that will use the ROS 2 Navigation stack.

To add a simulated depth camera to your SDF file, you will need to add code that looks like this:

  <!-- *********************** DEPTH CAMERA ******************************  -->
  <!-- The depth camera (e.g. Intel Realsense camera). -->
  <link name="camera_depth_frame">
    <pose>0.12 0 0.65 -1.5708 0 -1.5708</pose>
  <link name="camera_link">
    <pose>0.12 0 0.65 0 0 0</pose>
    <visual name="camera_visual">
      <pose>-0.005 0 0 0 0 0</pose>
          <size>0.015 0.08 0.022</size>
        <ambient>0 0 0 1.0</ambient>
        <diffuse>0 0 0 1.0</diffuse>
        <specular>0.0 0.0 0.0 1.0</specular>
        <emissive>0.0 0.0 0.0 1.0</emissive>
    <sensor name="depth_camera" type="camera">
      <camera name="camera">
          <!-- 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]. -->
      <plugin name="depth_camera_controller" filename="">

When you launch RViz along with Gazebo, you will need to add the Image sensor option so that you can visualize the depth camera output. Be sure to select “Best Effort” for the reliability policy.