In this chapter, you will begin to understand the control of robot arms with ROS. We begin with a simple three-link, two-joint articulated robotic arm in simulation. The simulated robot arm, rrbot
, has two revolute joints that will help you to understand, without the complexities of more joints. We will use the URDF elements described in Chapter 2, Creating Your First Two-Wheeled Robot (in Simulation) and incorporate the advantages of Xacro to make our code more modular and efficient. We will also include a mesh design for our gripper, and add control elements for the arm and gripper to our URDF. Next, we will show various ways to control the robot arm in Gazebo.
In this chapter, you will learn:
We begin by expanding your 3D modeling skills in order to create a robot arm URDF using Xacro. First, the advantages of Xacro will be described.
Xacro is the XML macro language for ROS. Xacro provides a set of macro operations to replace some repetitive statements with shorter, concise macros that will expand into full XML statements when processed. Xacro can be used with any XML document, but is most useful with long, complex URDF files. Xacro allows you to create shorter and more readable XML files for the robot URDF. Xacro provides advantages in many different areas:
<property>
tag can be used to specify these constant values in a central location. These are typically parameters that can be changed later. Properties are usually identified at the beginning of the file, but they can be found anywhere in the XML file at any level. It does not matter whether the property declaration is before or after its use.Here is an example of how to implement a property:
<xacro:property name="my_name" value ="Robby" />
"${my_name}"
, which stands for the value of my_name
and can be used to substitute text or values into an attribute+
, -
, /
, and *
. Unary minus and parenthesis can also be used. The expression must be enclosed in the ${}
construct. Numeric values are floating point numbers.<xacro>
tag can expand into a statement or sequence of statements in the URDF/SDF file. Macros are extremely useful when statements are repeated or reused with modifications defined by parameters.rospack
commands, just as roslaunch
does for substitution arguments (args
) (http://wiki.ros.org/roslaunch/XML). Rospack commands enclosed within $()
will be resolved during Xacro processing. For example, $(find ros_robotics)
will find the relative pathname for the ros_robotics
package. The $(arg var1)
argument will be resolved to a value passed by an Xacro statement or the command line. Arguments passed via the command line must use the myvar:=true
flag.<xacro:include filename="path to filename/filename" />
These features will be used in the URDF file for rrbot
throughout this chapter. The order in which Xacro processes all these features is as follows:
In order to create the URDF file from Xacro files, the Xacro file must contain an XML namespace declaration using the xmlns
attribute with the Xacro prefix and corresponding URI. Here is the XML namespace (xmlns
) attribute for our rrbot
robot arm:
<robot name="rrbot" xmlns:xacro="http://www.ros.org/wiki/xacro">
This declaration is vital for the file to parse properly. This statement appears as the second line in the main Xacro file, following the XML version reference.
To generate a URDF file, the xacro
program (from the xacro
package) expands all the macros and outputs a resulting URDF file. For example:
$ rosrun xacro xacro rrbot.xacro > rrbot.urdf
This command will pull together all of the xacro
include files, expand the xacro
macros in rrbot.xacro
, and output the result to rrbot.urdf
. This step is not necessary for running in rviz or Gazebo, but it can be a handy tool when used to examine the full URDF. The URDF XML file is generated with a heading comment warning that the file is autogenerated and editing of the file is not recommended.
The most common way to generate the URDF is in a launch file. The following line of code can be added to a launch file to create the most current robot_description
from the Xacro file:
<param name="robot_description" command="$(find xacro)/xacro.py '$(find rrbot_description)/urdf/rrbot.xacro'" />
For complex robots, generating the URDF file at launch time will require a bit more time to process. The advantages are that the URDF is up to date and does not require a lot of memory to be stored.