Reader small image

You're reading from  Mastering ROS for Robotics Programming

Product typeBook
Published inDec 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781783551798
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Lentin Joseph
Lentin Joseph
author image
Lentin Joseph

Lentin Joseph is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 7 years of experience in the robotics domain primarily in ROS, OpenCV, and PCL. He has authored four books in ROS, namely, Learning Robotics using Python, Mastering ROS for Robotics Programming, ROS Robotics Projects, and Robot Operating System for Absolute Beginners. He is currently pursuing his master's in Robotics from India and is also doing research at Robotics Institute, CMU, USA.
Read more about Lentin Joseph

Right arrow

Chapter 2. Working with 3D Robot Modeling in ROS

The first phase of robot manufacturing is its design and modeling. We can design and model the robot using CAD tools such as AutoCAD, Solid Works, Blender, and so on. One of the main purposes of modeling robot is simulation.

The robotic simulation tool can check the critical flaws in the robot design and can confirm the working of the robot before it goes to the manufacturing phase.

The virtual robot model must have all the characteristics of real hardware, the shape of robot may or may not look like the actual robot but it must be an abstract, which has all the physical characteristics of the actual robot.

In this chapter, we are going to discuss the designing of two robots. One is a seven DOF ( Degrees of Freedom) manipulator and the other is a differential drive robot. In the upcoming chapters, we can see its simulation and how to build the real hardware and finally, it's interfacing to ROS.

If we are planning to create the 3D model of the...

ROS packages for robot modeling


ROS provides some good packages that can be used to build 3D robot models. In this section, we will discuss some of the important ROS packages that are commonly used to build robot models:

  • robot_model: ROS has a meta package called robot_model, which contains important packages that help build the 3D robot models. We can see all the important packages inside this meta-package:

    • urdf: One of the important packages inside the robot_model meta package is urdf. The URDF package contains a C++ parser for the Unified Robot Description Format (URDF), which is an XML file to represent a robot model.

  • We can define a robot model, sensors, and a working environment using URDF and can parse it using URDF parsers. We can only describe a robot in URDF that has a tree-like structure in its links, that is, the robot will have rigid links and will be connected using joints. Flexible links can't be represented using URDF. The URDF is composed using special XML tags and we can...

Understanding robot modeling using URDF


We have discussed the urdf package. In this section, we will look further at the URDF XML tags, which help to model the robot. We have to create a file and write the relationship between each link and joint in the robot and save the file with the .urdf extension.

The URDF can represent the kinematic and dynamic description of the robot, visual representation of the robot, and the collision model of the robot.

The following tags are the commonly used URDF tags to compose a URDF robot model:

  • link: The link tag represents a single link of a robot. Using this tag, we can model a robot link and its properties. The modeling includes size, shape, color, and can even import a 3D mesh to represent the robot link. We can also provide dynamic properties of the link such as inertial matrix and collision properties.

    The syntax is as follows:

    <link name="<name of the link>">
    <inertial>...........</inertial>
      <visual> ............</visual...

Creating the ROS package for the robot description


Before creating the URDF file for the robot, let's create a ROS package in the catkin workspace so that the robot model keeps using the following command:

$ catkin_create_pkg mastering_ros_robot_description_pkg roscpp tf geometry_msgs urdf rviz xacro 

The package mainly depends on the urdf and xacro packages, and we can create the urdf file of the robot inside this package and create launch files to display the created urdf in RViz. The full package is available on 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/qboticslabs/mastering_ros_robot_description_pkg.git

Before creating the urdf file for this robot, let's create three folders called urdf, meshes, and launch inside the package folder. The urdf folder can be used to keep the urdf/xacro files that we are going to create. The meshes folder keeps...

Creating our first URDF model


After learning about URDF and its important tags, we can start some basic modeling using URDF. The first robot mechanism that we are going to design is a pan and tilt mechanism as shown in the following figure.

There are three links and two joints in this mechanism. The base link is static, in which all other links are mounted. The first joint can pan on its axis and the second link is mounted on the first link and it can tilt on its axis. The two joints in this system are of a revolute type.

Figure 4 : Visualization of a pan and tilt mechanism in RViz

Let's see the URDF code of this mechanism. Navigate to chapter_2_code/mastering_ros_robot_description_pkg/urdf and open pan_tilt.urdf. The code indentation in URDF is not mandatory for URDF but it keeping indentation can improve code readability:

<?xml version="1.0"?>
<robot name="pan_tilt">

  <link name="base_link">
    <visual>
      <geometry>
      <cylinder length="0.01" radius...

Explaining the URDF file


When we check the code, we can add a <robot> tag at the top of the description:

<?xml version="1.0"?>
<robot name="pan_tilt">

The <robot> tag defines the name of the robot that we are going to create. Here, we named the robot pan_tilt.

If we check the sections after the <robot> tag definition, we can see link and joint definitions of the pan and tilt mechanism:

  <link name="base_link">
    <visual>
      <geometry>
      <cylinder length="0.01" radius="0.2"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 0"/>
      <material name="yellow">
        <color rgba="1 1 0 1"/>
      </material>
    </visual>
  </link>

The preceding code snippet is the base_link definition of the pan and tilt mechanism. The <visual> tag can describe the visual appearance of the link, which is shown on the robot simulation. We can define the link geometry (cylinder, box, sphere, or mesh...

Visualizing the robot 3D model in RViz


After designing URDF, we can view it on RViz. We can create a view_demo.launch launch file and put the following code into the launch folder. Navigate to chapter_2_code/mastering_ros_robot_description_pkg/launch for the same code:

<launch>
  <arg name="model" />
  <param name="robot_description" textfile="$(find mastering_ros_robot_description_pkg)/urdf/pan_tilt.urdf" />
  <param name="use_gui" value="true"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mastering_ros_robot_description_pkg)/urdf.rviz" required="true" />

</launch>

We can launch the model using the following command:

$ roslaunch mastering_ros_robot_description_pkg view_demo.launch

If everything works fine, we will get a pan and tilt mechanism...

Adding physical and collision properties to a URDF model


Before simulating a robot in a robot simulator, such as Gazebo, V-REP, and so on, we need to define the robot link's physical properties such as geometry, color, mass, and inertia, and the collision properties of the link.

We will only get good simulation results if we define all these properties inside the robot model. URDF provides tags to include all these parameters and code snippets of base_link contained in theses properties as given here:

<link>
......    
<collision>
      <geometry>
      <cylinder length="0.03" radius="0.2"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 0"/>
    </collision>

    <inertial>
    <mass value="1"/>
    <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
    </inertial>
...........
</link>

Here, we define the collision geometry as cylinder and the mass as 1 Kg, and we also set the inertial matrix of...

Understanding robot modeling using xacro


The flexibility of URDF reduces when we work with complex robot models. Some of the main features that URDF is missing are the simplicity, reusability, modularity, and programmability.

If someone wants to reuse a URDF block ten times in his robot description, he can copy and paste the block ten times. If there is an option to use this code block and make multiple copies with different settings, it will be very useful while creating the robot description.

The URDF is single file and we can't include other URDF files inside it. This reduces the modular nature of the code. All code should be in a single file, which reduces the code simplicity too.

Also, if there is some programmability, such as adding variable, constants, mathematical expressions, conditional statement, and so on, in the description language, it will be more user friendly.

The robot modeling using xacro meets all these conditions and some of the main features of xacro are as follows:

  • Simplify...

Conversion of xacro to URDF


After designing the xacro file, we can use the following command to convert it into a UDRF file:

$ rosrun xacro xacro.py pan_tilt.xacro > pan_tilt_generated.urdf

We can use the following line in the ROS launch file for converting xacro to UDRF and use it as a robot_description parameter:

  <param name="robot_description" command="$(find xacro)/xacro.py $(find mastering_ros_robot_description_pkg)/urdf/pan_tilt.xacro" />

We can view the xacro of pan and tilt by making a launch file, and it can be launched using the following command:

$ roslaunch mastering_ros_robot_description_pkg view_pan_tilt_xacro.launch

Creating the robot description for a seven DOF robot manipulator


Now, we can create some complex robots using URDF and xacro. The first robot we are going to deal with is a seven DOF robotic arm, which is a serial link manipulator having multiple serial links. The seven DOF arm is kinematically redundant, which means it has more joints and DOF than required to achieve its goal position and orientation. The advantage of redundant manipulators are, we can have more joint configuration for a particular goal position and orientation. It will improve the flexibility and versatility of the robot movement and can implement effective collision free motion in a robotic workspace.

Let's start creating the seven DOF arm; the final output model of the robot arm is shown here (the various joints and links in the robot are also marked on the image):

Figure 8 : Joints and Links of seven dof arm robot

The preceding robot is described using xacro. We can take the actual description file from the cloned repository...

Explaining the xacro model of seven DOF arm


We will define 10 links and 9 joints on this robot and 2 links and 2 joints in the robot gripper.

Let's start by discussing the xacro definition:

<?xml version="1.0"?>
<robot name="seven_dof_arm" xmlns:xacro="http://www.ros.org/wiki/xacro">

Because we are writing a xacro file, we should mention the xacro namespace to parse the file.

Using constants

We use constants inside this xacro to make robot descriptions shorter and readable. Here, we define the degree to the radian conversion factor, PI value, length, height, and width of each of the links:

  <property name="deg_to_rad" value="0.01745329251994329577"/>
  <property name="M_PI" value="3.14159"/>

  <property name="elbow_pitch_len" value="0.22" />
  <property name="elbow_pitch_width" value="0.04" />
  <property name="elbow_pitch_height" value="0.04" />

Using macros

We define macros in this code to avoid repeatability and to make the code shorter. Here are the...

Creating a robot model for the differential drive mobile robot


A differential wheeled robot will have two wheels connected on opposite sides of the robot chassis which is supported by one or two caster wheels. The wheels will control the speed of the robot by adjusting individual velocity. If the two motors are running at the same speed it will move forward or backward. If a wheel is running slower than the other, the robot will turn to the side of the lower speed. If we want to turn the robot to the left side, reduce the velocity of the left wheel compared to the right and vice versa.

There are two supporting wheels called caster wheels that will support the robot and freely rotate according to the movement of the main wheels.

The UDRF model of this robot is present in the cloned ROS package. The final robot model is shown as follows:

Figure 12 : 3D model of differential drive mobile robot

The preceding robot has five joints and five links. The two main joints are two wheel joints and the other...

Questions


  1. What are the packages used for robot modeling in ROS?

  2. What are the important URDF tags used for robot modeling?

  3. What are the reasons for using xacro over URDF?

  4. What is the use of the joint state publisher and robot state publisher packages?

  5. What is the use of the transmission tag in URDF?

Summary


In this chapter, we mainly discussed the importance of robot modeling and how we can model a robot in ROS. We discussed more on the robot_model meta package and the packages inside robot_model such as urdf, xacro, joint_state_publisher, and so on. We discussed URDF, xacro, and the main URDF tags that we are going to use. We also created a sample model in URDF and xacro and discussed the difference between the two. After that, we created a complex robotic manipulator with seven DOF and saw the usage of the joint state publisher and robot state publisher packages. At the end of the chapter, we saw the designing procedure of a differential drive mobile robot using xacro. In the next chapter, we will look at the simulation of these robot using Gazebo.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering ROS for Robotics Programming
Published in: Dec 2015Publisher: PacktISBN-13: 9781783551798
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Lentin Joseph

Lentin Joseph is an author and robotics entrepreneur from India. He runs a robotics software company called Qbotics Labs in India. He has 7 years of experience in the robotics domain primarily in ROS, OpenCV, and PCL. He has authored four books in ROS, namely, Learning Robotics using Python, Mastering ROS for Robotics Programming, ROS Robotics Projects, and Robot Operating System for Absolute Beginners. He is currently pursuing his master's in Robotics from India and is also doing research at Robotics Institute, CMU, USA.
Read more about Lentin Joseph