Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning ROS for Robotics Programming Second Edition

You're reading from  Learning ROS for Robotics Programming Second Edition

Product type Book
Published in Aug 2015
Publisher Packt
ISBN-13 9781783987580
Pages 458 pages
Edition 1st Edition
Languages
Concepts

Table of Contents (27) Chapters

Learning ROS for Robotics Programming Second Edition
Credits
About the Author
Acknowledgments
About the Author
Acknowledgments
About the Author
Acknowledgments
About the Author
Acknowledgments
About the Reviewer
About the Reviewer
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Getting Started with ROS Hydro ROS Architecture and Concepts Visualization and Debug Tools Using Sensors and Actuators with ROS Computer Vision Point Clouds 3D Modeling and Simulation The Navigation Stack – Robot Setups The Navigation Stack – Beyond Setups Manipulation with MoveIt! Index

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):

<?xml version="1.0"?>
  <robot name="Robot1">
    <link name="base_link">
      <visual>
        <geometry>
          <box size="0.2 .3 .1"/>
        </geometry>
        <origin rpy="0 0 0" xyz="0 0 0.05"/>
        <material name="white">
          <color rgba="1 1 1 1"/>
        </material>
      </visual>
    </link>

    <link name="wheel_1">
      <visual...

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:

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

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.

Using constants

We can use xacro to declare constant values; hence, we can avoid putting...

Simulation in ROS


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:

$ gazebo

Before starting to work with Gazebo, we will install ROS packages to interface Gazebo...

Summary


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

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning ROS for Robotics Programming Second Edition
Published in: Aug 2015 Publisher: Packt ISBN-13: 9781783987580
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.
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}