Chapter 7. 3D Modeling and Simulation
Programming directly on a real robot gives us a good feedback and is more impressive than simulations, but not everybody has access to real robots. For this reason, we have programs that simulate the physical world.
In this chapter, we are going to learn how to:
Create a 3D model of our robot
Provide movements, physical limits, inertia, and other physical aspects to our robot
Add simulated sensors to our 3D model
Use the model on the simulator
A 3D model of our robot in ROS
The way ROS uses the 3D model of a robot or its parts, to simulate them or to simply help the developers in their daily work, is by means of the URDF files.
Unified Robot Description Format (URDF) is an XML format that describes a robot, its parts, its joints, dimensions, and so on. Every time you see a 3D robot on ROS, for example, the
PR2 (Willow Garage) or the
Robonaut (NASA), a URDF file is associated with it. In the next few sections, we will learn how to create this file, and the format for defining different values.
Creating our first URDF file
The robot that we are going to build in the following sections, is a mobile robot with four wheels and an arm with a gripper.
To start with, we create the base of the robot with four wheels. Create a new file in the chapter7_tutorials/robot1_description/urdf
folder with the name robot1.urdf
, and enter the following code; this URDF code is based on XML, and the indentation is not mandatory but advisable. So, use an editor that supports it or an adequate plugin or configuration (for example, an appropriate .vimrc
file in Vim):
Xacro – a better way to write our robot models
Notice the size of the robot1_physics.urdf
file. It has 314 lines of code to define our robot. Imagine adding cameras, legs, and other geometries—the file will start increasing, and the maintenance of the code will become more complicated.
Xacro helps in reducing the overall size of the URDF file and makes it easier to read and maintain. It also allows us to create modules and reutilize them to create repeated structures such as several arms or legs.
To start using xacro
, we need to specify a namespace so that the file is parsed properly. For example, these are the first two lines of a valid xacro
file:
In the preceding lines, we define the name of the model, which in this case is robot1_xacro
. Remember that the file extension will be .xacro
instead of .urdf
.
We can use xacro
to declare constant values; hence, we can avoid putting...
In order to make simulations with our robots on ROS, we are going to use Gazebo.
Gazebo (http://gazebosim.org/) is a multirobot simulator for complex indoor and outdoor environments. It is capable of simulating a population of robots, sensors, and objects in a three-dimensional world. It generates both realistic sensor feedback and physically plausible interactions between objects.
Gazebo is now independent from ROS and is installed as a standalone package in Ubuntu. In this section, we will see how to interface Gazebo and ROS. You will learn how to use the model created before, how to include a laser sensor and a camera, and how to move it as a real robot.
Using our URDF 3D model in Gazebo
We are going to use the model that we designed in the last section, but without the arm to make it simple.
Make sure that you have Gazebo installed by typing the following command in a terminal:
Before starting to work with Gazebo, we will install ROS packages to interface Gazebo...
For people learning robotics, the ability to have access to real robots is fun and useful, but not everyone has access to a real robot. Simulators are a great tool when we have limited access to a real robot. They were created for testing the behavior of algorithms before trying them on a real robot. This is why simulators exist.
In this chapter, you have learned how to create a 3D model of your own robot. This includes a detailed explanation that guides you in the tasks of adding textures and creating joints, and also describes how to move the robot with a node.
Then, we introduced Gazebo, a simulator where you can load the 3D model of your robot, and simulate it moving and sensing a virtual world. This simulator is widely used by the ROS community and it already supports many real robots in simulation.
Indeed, in a nutshell, we have seen how to reuse parts of other robots to design ours. In particular, we have included a gripper and added sensors, such as a laser range finder and...