Reader small image

You're reading from  Mastering ROS for Robotics Programming, Third edition - Third Edition

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801071024
Edition3rd Edition
Concepts
Right arrow
Authors (2):
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

Jonathan Cacace
Jonathan Cacace
author image
Jonathan Cacace

Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received his Master's degree in computer science, and a Ph.D. degree in Information and Automation Engineering, from the University of Naples Federico II. Currently, he is an Assistant Professor at the University of Naples Federico II. He is also a member of PRISMA Lab where he is involved in different research projects focused on industrial and service robotics in which he has developed several ROS-based applications integrating robot perception and control.
Read more about Jonathan Cacace

View More author details
Right arrow

Chapter 3: Working with ROS for 3D Modeling

The first phase of robot manufacturing involves designing and modeling. We can design and model a robot using CAD tools such as Autodesk Fusion 360, SolidWorks, Blender, and many others. One of the main purposes of robot modeling is simulation.

The robotic simulation tool can check for critical flaws in a robot's design and can confirm that the robot will work before it goes to the manufacturing phase.

In this chapter, we are going to discuss the design process of two robots. One is a seven-Degrees-of-Freedom (DOF) manipulator, and the other is a differential drive robot. In the upcoming chapters, we will look at simulation, learn how to build real hardware, and discuss interfacing with ROS.

If you are planning to create a 3D model of a robot and simulate it using ROS, you will need to learn about some ROS packages that can help in robot designing. Creating a model for our robot in ROS is important for various reasons. For example...

Technical requirements

To follow the examples in this chapter, you will need a standard laptop running Ubuntu 20.04 with ROS Noetic installed. The reference code for this chapter can be downloaded from the Git repository at https://github.com/PacktPublishing/Mastering-ROS-for-Robotics-Programming-Third-edition.git. The code is contained inside the Chapter3/mastering_ros_robot_description_pkg/ folder.

You can view this chapter's code in action here: https://bit.ly/2W5jief.

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 and model a robot:

  • urdf: The most important ROS package to model a robot is the urdf package. This package contains a C++ parser for the URDF, which is an XML file representing a robot model. Other different components make up urdf, such as the following:

    a. urdf_parser_plugin: This package implements methods to fill the URDF data structures.

    b. urdfdom_headers: This component provides core data structure headers to use the urdf parser.

    c. collada_parser: This package populates data structures by parsing a Collada file.

    d. urdfdom: This component populates data structures by parsing URDF files.

We can define robot models, sensors, and a working environment using URDF. We can also parse them using URDF parsers. We can only describe a robot in URDF that has a tree-like...

Understanding robot modeling using URDF

In the previous section, we listed some important packages that use the urdf file format. In this section, we will take a further look at the URDF XML tags, which help to model the robot. We need to create a file and write the relationship between each link and joint in the robot and save the file using the .urdf extension.

URDF can represent the kinematic and dynamic description of the robot, the 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 the single link of a robot. Using this tag, we can model a robot link and its properties. The modeling includes the size, the shape, and the color; it can even import a 3D mesh to represent the robot link. We can also provide the dynamic properties of the link, such as the inertial matrix and the collision properties.

    The syntax is as follows:

    ...

Creating the ROS package for the robot description

Before creating the URDF file for the robot, let's create an 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. If these packages have not been installed on to your system, you can install them using the package manager:

sudo apt-get install ros-noetic-urdf
sudo apt-get install ros-noetic-xacro  

We can create the urdf file of the robot inside this package and create launch files to display the created urdf file in RViz. The full package is available in the following Git repository; you can clone the repository for 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_3rd_edition.git
cd mastering_ros_robot_description_pkg...

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 diagram.

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

Figure 3.4 – A visualization of the pan-and-tilt mechanism in RViz

Let's take a look at the URDF code of this mechanism. Navigate to the mastering_ros_robot_description_pkg/urdf directory and open pan_tilt.urdf.

We will start by defining the base link of the root model:

<?xml version="1.0"?> 
<robot name="pan_tilt"> 
  <link name="base_link"> 
 ...

Explaining the URDF file

When we check the code, we can add a <robot> tag at the top of the description. In this way, we inform our system that we are visualizing a markup language file. This also allows the text editor to highlight the keywords of the file:

<?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 view the 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="...

Visualizing the 3D robot model in RViz

After designing the 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 the mastering_ros_robot_description_pkg/launch directory for the code:

<?xml version="1.0" ?>
<launch>
  <arg name="model" />
  <param name="robot_description" textfile="$(find mastering_ros_robot_description_pkg)/urdf/pan_tilt.urdf" />
 <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" />
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mastering_ros_robot_description_pkg)/urdf.rviz" required="true"...

Adding physical and collision properties to a URDF model

Before simulating a robot in a robot simulator, such as Gazebo or CoppeliaSim, we need to define the robot link's physical properties, such as geometry, color, mass, and inertia, as well as the collision properties of the link.

Good robot simulations can be obtained only if the robot dynamic parameters (for instance, its mass, inertia, and more) are correctly specified in the urdf file. In the following code, we include these parameters as part of the base_link:

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

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 include simplicity, reusability, modularity, and programmability.

If someone wants to reuse a URDF block 10 times in their robot description, they can copy and paste the block 10 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 a 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's simplicity.

Also, if there is some programmability, such as adding variables, constants, mathematical expressions, and conditional statements in the description language, it will be more user-friendly.

Robot modeling using xacro meets all of these conditions. Some of the main features of xacro...

Converting xacro to URDF

As already stated, xacro files can be converted into urdf files every time. After designing the xacro file, we can use the following command to convert it into a URDF file:

rosrun xacro pan_tilt.xacro > pan_tilt_generated.urdf

We can use the following line in the ROS launch file to convert xacro into URDF and use it as a robot_description parameter:

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

We can view the xacro of the pan-and-tilt robot 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

After running this command, we should see the same output of the visualization as the URDF file. Now we are ready to do something more complicated. The pan-and-tilt robot only has two joints and so only two degrees of freedom. In the...

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 with 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 is that we can have more joint configurations for a desired goal position and orientation. This will improve the flexibility and versatility of the robot's movement and can implement effective collision-free motion in a robotic workspace.

Let's start by 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 diagram):

Figure 3.8 – Joints and links of the seven-DOF arm robot

The preceding robot is described using...

Explaining the xacro model of the seven-DOF arm

After defining the elements that we must insert in the robot model file, we are now ready to include 10 links and 9 joints (7 for the arm and 2 for the gripper) on this robot, and 2 links and 2 joints on the robot gripper.

Let's start by looking at the xacro definition:

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

Because we are writing a xacro file, we should mention the xacro namespace to parse the file; then, we can start to define the geometric properties of the arm.

Using constants

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

  <property name="deg_to_rad" value="0.01745329251994329577"/> 
  <property...

Creating a robot model for the differential drive mobile robot

A differential wheeled robot will have two wheels connected to 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 regulating the velocity of the single wheels. If the two motors are running at the same speed, the wheels will move forward or backward. If one 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, we reduce the velocity of the left wheel and vice versa.

There are two supporting wheels, called caster wheels, that will support the robot and rotate freely based on the movement of the main wheels.

The URDF model of this robot is present in the cloned ROS package. The final robot model is shown here:

Figure 3.12 – The differential drive mobile robot

The preceding robot has five joints and links. The two main...

Summary

In this chapter, we mainly looked at the importance of robot modeling and how we can model a robot in ROS. We discussed the packages that are used in ROS to model a robotic structure, such as urdf, xacro, and joint_state_publisher and its GUI. We discussed URDF, xacro, and the main URDF tags that we can use. We also created a sample model in URDF and xacro and discussed the differences between the two. Following this, we created a complex robotic manipulator with seven DOF and looked at the usage of the joint_state_publisher and robot_state_publisher packages. At the end of the chapter, we reviewed the design procedure of a differential drive mobile robot using xacro. In the next chapter, we will take a look at the simulation of these robots using Gazebo.

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 function of the joint state publisher and robot state publisher packages?
  5. What is the function of the transmission tag in URDF?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering ROS for Robotics Programming, Third edition - Third Edition
Published in: Oct 2021Publisher: PacktISBN-13: 9781801071024
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

Authors (2)

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

author image
Jonathan Cacace

Jonathan Cacace was born in Naples, Italy, on December 13, 1987. He received his Master's degree in computer science, and a Ph.D. degree in Information and Automation Engineering, from the University of Naples Federico II. Currently, he is an Assistant Professor at the University of Naples Federico II. He is also a member of PRISMA Lab where he is involved in different research projects focused on industrial and service robotics in which he has developed several ROS-based applications integrating robot perception and control.
Read more about Jonathan Cacace