How to Add Ultrasonic Sensors to an SDF File for Gazebo


In the cover image you can see an ultrasonic sensor that was added to a simulated robot in Gazebo. An ultrasonic sensor is useful because, unlike LIDAR, an ultrasonic sensor can detect glass. Detection of glass is important if you’re planning to build a robot for the real-world that will use the ROS 2 Navigation stack.

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

  <!-- *********************** ULTRASONIC SENSOR ************************  -->
  <link name="ultrasonic_1_link">
    <pose>0.09 -0.139 0.595 0 0 0</pose>
    <sensor name="ultrasonic_1" type="ray">
      <plugin name="ultrasonic_sensor_1" filename="">

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