
Simulating a differential wheeled robot in Gazebo
We have seen the simulation of the robotic arm. In this section, we can set up the simulation for the differential wheeled robot that we designed in the previous chapter.
You will get the diff_wheeled_robot.xacro mobile robot description from the mastering_ros_robot_description_pkg/urdf folder.
Let's create a launch file to spawn the simulation model in Gazebo. As we did for the robotic arm, we can create a ROS package to launch a Gazebo simulation using the same dependencies of the seven_dof_arm_gazebo package, clone the entire package from the following Git repository, or get the package from the book's source code:
$ git clone https://github.com/jocacace/diff_wheeled_robot_gazebo.git
Navigate to the diff_wheeled_robot_gazebo/launch directory and take the diff_wheeled_gazebo.launch file. Here is the definition of this launch:
<launch> <!-- these are the arguments you can pass this launch file, for example paused:=true --> <arg name="paused" default="false"/> <arg name="use_sim_time" default="true"/> <arg name="gui" default="true"/> <arg name="headless" default="false"/> <arg name="debug" default="false"/> <!-- We resume the logic in empty_world.launch --> <include file="$(find gazebo_ros)/launch/empty_world.launch"> <arg name="debug" value="$(arg debug)" /> <arg name="gui" value="$(arg gui)" /> <arg name="paused" value="$(arg paused)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="headless" value="$(arg headless)"/> </include> <!-- urdf xml robot description loaded on the Parameter Server--> <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mastering_ros_robot_description_pkg)/urdf/diff_wheeled_robot.xacro'" /> <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot --> <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model diff_wheeled_robot -param robot_description"/> </launch>
To launch this file, we can use the following command:
$ roslaunch diff_wheeled_robot_gazebo diff_wheeled_gazebo.launch
You will see the following robot model in Gazebo. If you get this model, you have successfully finished the first phase of the simulation:

After successful simulation, let's add the laser scanner to the robot.