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 5: Simulating Robots Using ROS, CoppeliaSim, and Webots

Having learned how to simulate robots with Gazebo, in this chapter we will discuss how to use the other two powerful robot-simulation software: CoppeliaSim (http://www.coppeliarobotics.com) and Webots (https://cyberbotics.com/).

These are multiplatform robotic simulators. CoppeliaSim is developed by Coppelia Robotics. It offers many simulation models of popular industrial and mobile robots ready to be used, and different functionalities that can be easily integrated and combined through a dedicated application programming interface (API). In addition, it can operate with Robot Operating System (ROS) using a proper communication interface that allows us to control the simulation scene and the robots via topics and services. As with Gazebo, CoppeliaSim can be used as a standalone software, while an external plugin must be installed to work with ROS. As for Webots, it is a free and open source software used to simulate...

Technical requirements

To follow this chapter, you need a standard laptop running Ubuntu 20.04 with ROS Noetic installed. The reference code for this chapter can be downloaded from the following Git repository: https://github.com/PacktPublishing/Mastering-ROS-for-Robotics-Programming-Third-edition.git. The code is contained in the Chapter5/csim_demo_pkg and Chapter5/webost_demo_pkg folders.

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

Setting up CoppeliaSim with ROS

Before starting to work with CoppeliaSim, we need to install it on our system and configure our environment to start the communication bridge between ROS and the simulation scene. CoppeliaSim is cross-platform software, available for different operating systems such as Windows, macOS, and Linux. It is developed by Coppelia Robotics GmbH and is distributed with both free educational and commercial licenses. Download the latest version of the CoppeliaSim simulator from the Coppelia Robotics download page at http://www.coppeliarobotics.com/downloads.html, choosing the edu version for Linux. In this chapter, we will refer to the CoppeliaSim 4.2.0 version.

After completing the download, extract the archive. Move to your download folder and use the following command:

tar vxf CoppeliaSim_Edu_V4_2_0_Ubuntu20_04.tar.xz

This version is supported by Ubuntu versions 20.04. It is convenient to rename this folder with something more intuitive, such as this...

Simulating a robotic arm using CoppeliaSim and ROS

In the previous chapter, we used Gazebo to import and simulate the seven-degrees of freedom (DOF) arm designed in Chapter 3, Working with ROS for 3D Modeling. Here, we will do the same thing using CoppeliaSim. The first step to simulate our seven-DOF arm is to import it in the simulation scene. CoppeliaSim allows you to import new robots using URDF files; for this reason, we must convert the xacro model of the arm in a URDF file, saving the generated URDF file in the urdf folder of the csim_demo_pkg package, as follows:

rosrun xacro seven_dof_arm.xacro >  /path/to/csim_demo_pkg/urdf/seven_dof_arm.urdf

We can now import the robot model, using the URDF import plugin. Select from the main drop-down menu the Plugins | URDF import entry and press the Import button, choosing the default import options from the dialog window. Finally, select the desired file to import, and the seven-DOF arm will appear in the scene, as...

Setting up Webots with ROS

As already done with CoppeliaSim, we need to install Webots on our system before setting it up with ROS. Webots is a multiplatform simulation software supported by Windows, Linux, and macOS. This software was initially developed by the Swiss Federal Institute of Technology, Lausanne (EPFL). Now, it is developed by Cyberbotics, and it is released under the free and open source Apache 2 license. Webots provides a complete development environment to model, program, and simulate robots. It has been designed for professional use and it is widely used in industry, education, and research.

You can choose different ways to install the simulator. You can download the .deb package from the Webots web page (http://www.cyberbotics.com/#download) or use the Debian/Ubuntu Advanced Packaging Tool (APT) package manager. Assuming that you are running Ubuntu, let's start by authenticating the Cyberbotics repository, as follows:

wget -qO- https://cyberbotics.com...

Writing your first controller

In this section, we will write our first controller for the mobile robot. We have seen how the controllers handle the motion of the robot and its reaction to the sensors. Let's change the controller of the E-puck robot to move some fixed directions. We can choose different programming languages for our controller; however, we will use C++. The goal of the new controller is to command the velocity of the wheels of the robot to show the typical structure of a Webots controller.

The first thing to do is to change the controller associated with our mobile robot. Note that each robot can use only one controller at once. Conversely, we can associate the same controller with different robots. To write our new controller, we must follow these steps:

  1. Create a new controller file.
  2. Write a new controller.
  3. Compile the new controller.
  4. Change the default controller of the robot with the new one in the robot properties panel.

As already...

Writing a teleop node using webots_ros

In this section, we will implement a ROS node to directly control the wheels' velocity of the e-puck robot starting from a geometry_msgs::Twist message. To do this, we need to exploit webots_ros as a dependency. Let's create a webots_demo_pkg package, specifying webots_ros as a dependency, as follows:

catkin_create_pkg webots_demo_pkg roscpp webots_ros geometry_msgs

The complete source code can be found in the book source code, and it is explained next. Let's start by defining some useful header files implementing the messages needed to use the Webots services, as follows:

#include "ros/ros.h"
#include <webots_ros/Int32Stamped.h>
#include <webots_ros/set_float.h>
#include <webots_ros/set_int.h>
#include <webots_ros/robot_get_device_list.h>
#include <std_msgs/String.h>
#include <geometry_msgs/Twist.h>

Then, declare some variable to save the data received by the ROS callbacks...

Summary

In this chapter, we mainly replicated what we have already done in the previous chapter with Gazebo, using other robot simulators: CoppeliaSim and Webots. These are multiplatform simulation software programs that integrate different technologies and are very versatile. Thanks to their intuitive UIs, they might be easier to use for new users.

We mainly simulated two robots, one imported using the URDF file of the seven-DOF arm designed in previous chapters, with the other being a popular differential wheeled robot provided by the Webots simulation models. We learned how to interface and control the robot joints of our model with ROS and how to move a differential-drive mobile robot using topics.

In the next chapter, we will see how to interface the robotic arm with the ROS MoveIt package and the mobile robot with the Navigation stack.

Questions

We should now be able to answer the following questions:

  • How do CoppeliaSim and ROS communicate?
  • In what way is it possible to control a CoppeliaSim simulation with ROS?
  • How can we import new robot models in CoppeliaSim and integrate them with ROS?
  • Can Webots be used as standalone software?
  • How can ROS and Webots communicate?
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