Adding the laser scanner to Gazebo

We add the laser scanner on the top of Gazebo to perform high-end operations, such as autonomous navigation or map creation using this robot. Here, we should add the following extra code section to diff_wheeled_robot.xacro to add the laser scanner to the robot:

  <link name="hokuyo_link"> 
    <visual> 
      <origin xyz="0 0 0" rpy="0 0 0" /> 
      <geometry> 
        <box size="${hokuyo_size} ${hokuyo_size} ${hokuyo_size}"/> 
      </geometry> 
      <material name="Blue" /> 
    </visual> 
  </link> 
  <joint name="hokuyo_joint" type="fixed"> 
    <origin xyz="${base_radius - hokuyo_size/2} 0 ${base_height+hokuyo_size/4}" rpy="0 0 0" /> 
    <parent link="base_link"/> 
    <child link="hokuyo_link" /> 
  </joint> 
  <gazebo reference="hokuyo_link"> 
    <material>Gazebo/Blue</material> 
    <turnGravityOff>false</turnGravityOff> 
    <sensor type="ray" name="head_hokuyo_sensor"> 
      <pose>${hokuyo_size/2} 0 0 0 0 0</pose> 
      <visualize>false</visualize> 
      <update_rate>40</update_rate> 
      <ray> 
        <scan> 
          <horizontal> 
            <samples>720</samples> 
            <resolution>1</resolution> 
            <min_angle>-1.570796</min_angle> 
            <max_angle>1.570796</max_angle> 
          </horizontal> 
        </scan> 
        <range> 
          <min>0.10</min> 
          <max>10.0</max> 
          <resolution>0.001</resolution> 
        </range> 
      </ray> 
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so"> 
        <topicName>/scan</topicName> 
        <frameName>hokuyo_link</frameName> 
      </plugin> 
    </sensor> 
  </gazebo> 

In this section, we use the Gazebo ROS plugin file called libgazebo_ros_laser.so to simulate the laser scanner. The complete code can be found in the diff_wheeled_robot_with_laser.xacro description file in the mastering_ros_robot_description_pkg/urdf/ directory.

We can view the laser scanner data by adding some objects in the simulation environment. Here, we add some cylinders around the robot and can see the corresponding laser view in the next section of the figure:

Figure 12: Differential drive robot in random object in Gazebo

The laser scanner plugin publishes laser data ( sensor_msgs/LaserScan  ) into the /scan  topic.