Chapter 5. Creating Your First Robot Arm (in Simulation)

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:

  • The advantages of using Xacro in a URDF
  • How to design a three-link, two-joint robotic arm using Xacro and mesh files
  • How to control the arm in Gazebo using ROS commands and rqt

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.

Features of Xacro

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 and property blocks: If repeated information is used in a URDF/SDF file, the <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:

    • Define as <xacro:property name="my_name" value ="Robby" />
    • Use as "${my_name}", which stands for the value of my_name and can be used to substitute text or values into an attribute
  • Simple math: Math expressions can be constructed using the four basic operations: +, -, / , and *. Unary minus and parenthesis can also be used. The expression must be enclosed in the ${} construct. Numeric values are floating point numbers.
  • Macros: This is the main feature of Xacro. When creating a macro, a simple <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.
  • Use of rospack commands: Xacro supports the use of 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.
  • Combining multiple Xacro files: Other Xacro files can be included in the main URDF file to allow you to modularize the URDF file into component files. The tag is as follows:
    <xacro:include filename="path to filename/filename" />
  • Other features of Xacro can be found at http://wiki.ros.org/xacro. Additional features are part of the ROS Jade software release.

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:

  1. Includes
  2. Properties and property blocks
  3. Macro definitions
  4. Instantiation of macros
  5. Expression evaluation

Expanding Xacro

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.

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

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