Explaining the simulation code

The sensor_sim_gazebo package has the following list of files for simulating all self-driving car sensors. Here is the directory structure of this package:

List of files in sensor_sim_gazebo

To simulate a laser, launch the laser.launch file; similarly, to start simulating the IMU, GPS, and camera, launch the corresponding launch files. Inside URDF, you can see the Gazebo plugin definition for each sensor.

The sensor.xacro file is the orange box definition that you saw in the preceding simulation. It is just a box for visualizing a sensor model. We are using this model to represent all of the sensors inside this package. You can use your own model instead of this, too.

The laser.xacro file has the Gazebo plugin definition of the laser, as shown in our repository here: https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_10_ws/sensor_sim_gazebo/urdf/laser.xacro.

Here, you can see various parameters of the laser scanner plugin. We can fine-tune these parameters for our custom applications. The plugin we've used here is libgazebo_ros_laser.so, and all of the parameters are passed to this plugin.

In the laser.launch file, we are creating an empty world and spawning the laser.xacro file. Here is the code snippet to spawn the model in Gazebo and start a joint-state publisher to start publishing TF data:

  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find sensor_sim_gazebo)/urdf/laser.xacro'" /> 
 
  <node pkg="gazebo_ros" type="spawn_model" name="spawn_model" args="-urdf -param /robot_description -model example"/> 
 
  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher"> 
    <param name="publish_frequency" type="double" value="30.0" /> 
  </node> 

Now that we have seen how the laser plugin works, let's see how to interface real hardware in ROS in the next section.

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

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