Chapter 2. Creating Your First Two-Wheeled ROS Robot (in Simulation)
Your first robot will be created in simulation so that even if you do not have a robot to learn ROS on, you will be able to follow along and do the exercises in this book. We will build a simple two-wheeled robot named dd_robot
(dd is short for a differential drive). We will build a
Unified Robot Description Format (URDF) file for the robot that will describe the main components of our robot and enable it to be visualized and controlled by ROS tools, such as rviz and Gazebo. Rviz is a visualization tool in which we will view our dd_robot
URDF file as we build it in increments. When the visual model is complete, we will modify the URDF file for use in the Gazebo simulator. In Gazebo, we can view the effects of physics on our model as we move our model around the 3D environment.
In this chapter, we will cover the following topics:
Rviz, abbreviation for ROS visualization, is a powerful 3D visualization tool for ROS. It allows the user to view the simulated robot model, log sensor information from the robot's sensors, and replay the logged sensor information. By visualizing what the robot is seeing, thinking, and doing, the user can debug a robot application from sensor inputs to planned (or unplanned) actions.
Rviz displays 3D sensor data from stereo cameras, lasers, Kinects, and other 3D devices in the form of point clouds or depth images. 2D sensor data from webcams, RGB cameras, and 2D laser rangefinders can be viewed in rviz as image data.
If an actual robot is communicating with a workstation that is running rviz, rviz will display the robot's current configuration on the virtual robot model. ROS topics will be displayed as live representations based on the sensor data published by any cameras, infrared sensors, and laser scanners that are part of the robot's system. This can be useful to develop and debug...
Creating and building a ROS package
Before we begin to design and build our robot model in simulation, we should create our first ROS package. In Chapter 1, Getting Started with ROS, we created a ROS catkin workspace under /home/<username>/catkin_ws
. The structure of a catkin workspace looks like this:
Tip
Make sure that you have source ~/catkin_ws/devel/setup.bash
in your .bashrc
file, or this command is entered at the terminal window prompt.
We begin by moving to your catkin workspace source directory:
Now, let's create our first ROS package, ros_robotics
:
This command will create a /ros_robotics
directory under the ~/catkin_ws/src
directory. The /ros_robotics
directory...
Building a differential drive robot URDF
URDF is an XML format specifically defined to represent robot models down to their component level. These URDF files can become long and cumbersome on complex robot systems. Xacro (XML Macros) is an XML macro language created to make these robot description files easier to read and maintain. Xacro helps you reduce the duplication of information within the file.
For our first robot model, we will build a URDF file for a two-wheeled differential drive robot. The model will be created incrementally, and we will view the results at each step in rviz. When our simple two-wheeled robot is complete, we will add Gazebo formatting and view the model in Gazebo. In Chapter 5, Creating Your First Robot Arm (in Simulation), we will expand our knowledge of URDF files and build a simple robot arm model using the Xacro notation.
Note
Downloading the ros_robotics code
You can download the example code files and other support material for this book from www.PacktPub.com...
Gazebo is a free and open source robot simulation environment developed by Willow Garage. As a multifunctional tool for ROS robot developers, Gazebo supports the following:
Designing of robot models
Rapid prototyping and testing of algorithms
Regression testing using realistic scenarios
Simulation of indoor and outdoor environments
Simulation of sensor data for laser range finders, 2D/3D cameras, kinect-style sensors, contact sensors, force-torque, and more
Advanced 3D objects and environments utilizing Object-Oriented Graphics Rendering Engine (OGRE)
Several high-performance physics engines (Open Dynamics Engine (ODE), Bullet, Simbody, and Dynamic Animation and Robotics Toolkit (DART)) to model the real-world dynamics
In this section, we will load our two-wheeled robot URDF into Gazebo to visualize it in a 3D environment. Gazebo allows you to take control of some aspects of our model without an external control program. In the later chapters, we will be using simulated versions of robots...
Your first robot design has been a simple two-wheeled differential drive model defined in URDF. There are many other properties that can be defined in the URDF file, and you are free to extend the dd_robot
model. This introductory exercise was provided so that the elements of simulation can be understood by the reader. In Chapter 3, Driving Around with TurtleBot, we will use a simulated and a real TurtleBot to explore a variety of ROS control methods for mobile robot navigation. The rqt toolset will be introduced and used to monitor and control the TurtleBot's movements.
In Chapter 5, Creating Your First Robot Arm (in Simulation), we will extend our understanding of URDF by learning more about Xacro. We will build a Xacro file to define a robot model for a robot arm.