Simulating an ultrasonic sensor in Gazebo

Ultrasonic sensors also play a key role in self-driving cars. We've already seen that range sensors are widely used in parking assistant systems. In this section, we are going to see how to simulate a range sensor in Gazebo. The range sensor Gazebo plugin is already available in the hector Gazebo ROS plugin, so we can just use it in our code.

As we did in earlier demos, we will first see how to run the simulation and watch the output.

The following command will launch the range sensor simulation in Gazebo:

$ roslaunch sensor_sim_gazebo sonar.launch 

In this simulation, we are taking the actual 3D model of the sonar, and it's very small. You may need to zoom into Gazebo to view the model. We can test the sensor by putting an obstacle in front of it. We can start RViz and can view the distance using the range display type. The topic name is /distance and the Fixed Frame is world.

Here is the range sensor value when the obstacle is far away:

Range sensor value when the obstacle is far

You can see that the marked point is the ultrasonic sound sensor, and on the right, you can view the RViz range data as a cone-shaped structure. If we move the obstacle near the sensor, we can see what happens to the range sensor data:

Range sensor value when the obstacle is near

When the obstacle is too near the sensor, the cone size is reduced, which means the distance to the obstacle is very short.

Open the Gazebo sonar plugin definition from https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_10_ws/sensor_sim_gazebo/urdf/sonar.xacro. This file includes a reference to another file called sonar_model.xacro, which has the complete sonar plugin definition.

We are using the libhector_gazebo_ros_sonar plugin to run this simulation, which is given in the following code snippet from sonar_mode.xacro:

<plugin name="gazebo_ros_sonar_controller" filename="libhector_gazebo_ros_sonar.so"> 

Let's now look at a few popular low-cost LIDAR sensors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.116.159