Mastering ROS for Robotics Programming(Second Edition)
上QQ阅读APP看书,第一时间看更新

Creating the robotic arm simulation model for Gazebo

We can create the simulation model for a robotic arm by updating the existing robot description by adding simulation parameters.

We can create the package needed to simulate the robotic arm using the following command:

$ catkin_create_pkg seven_dof_arm_gazebo gazebo_msgs gazebo_plugins gazebo_ros gazebo_ros_control mastering_ros_robot_description_pkg  

Alternatively, the full package is available in the following Git repository; you can clone the repository for a reference to implement this package, or you can get the package from the book's source code:

$ git clone  https://github.com/jocacace/seven_dof_arm_gazebo.git  

You can see the complete simulation model of the robot in the seven_dof_arm.xacro file, placed in the mastering_ros_robot_description_pkg/urdf/ folder.

The file is filled with URDF tags, which are necessary for the simulation. We will define the sections of collision, inertial, transmission, joints, links, and Gazebo.

To launch the existing simulation model, we can use the seven_dof_arm_gazebo package, which has a launch file called seven_dof_arm_world.launch. The file definition is as follows:

<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> 
 
  <!-- Load the URDF into the ROS Parameter Server --> 
<param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mastering_ros_robot_description_pkg)/urdf/seven_dof_arm.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 seven_dof_arm -param robot_description"/> </launch>

Launch the following command and check what you get:

    $ roslaunch seven_dof_arm_gazebo seven_dof_arm_world.launch  

You can see the robotic arm in Gazebo, as shown in the following figure; if you get this output, without any errors, you are done:

Figure 1: Simulation of seven-DOF arm in Gazebo

Let's discuss the robot simulation model files in detail.