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 13: Writing ROS Controllers and Visualization Plugins

In the previous chapter, we discussed pluginlib, nodelets, and Gazebo plugins. The base library for making plugins in ROS is pluginlib, and the same library can be used in nodelets. In this chapter, we will continue with pluginlib-based concepts, such as ROS controllers and ROS visualization (RViz) plugins. We have already worked with ROS controllers and have reused some standard controllers, such as joint state, position, and trajectory controllers, in Chapter 4, Simulating Robots Using ROS and Gazebo.

In this chapter, we will see how to write a basic ROS controller for a generic robot. We will implement the desired controller for our seven-Degree of Freedom (DOF) arm robot, developed in previous chapters, executing it in the Gazebo simulator. RViz plugins can add more functionality to RViz, and in this chapter, we will look at how to create a basic RViz plugin. The detailed topics that we are going to discuss in this...

Technical requirements

To follow this chapter, you should have the following setup on your computer:

  • Ubuntu 20.04 LTS
  • ROS Noetic desktop full installation

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/tree/main/Chapter13

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

Understanding ros_control packages

Let's see how to develop a ROS controller. The first step is to understand the dependency packages required to start building custom controllers.

The main set of packages used to develop a controller generic to all robots is contained in the ros_control stack. This is a rewritten version of pr2_mechanism, containing useful libraries to write low-level controllers for PR2 robots (http://wiki.ros.org/Robots/PR2) used in the past version of ROS. In ROS Kinetic, pr2_mechanism has been substituted with the ros_control stack (http://wiki.ros.org/ros_control). The following is a description of some useful packages that help us to write robot controllers:

  • ros_control: This package takes as input the joint state data directly from the robot's actuators and the desired set point, generating the output to send to its motors. The output is usually represented by the join position, velocity, or effort.
  • controller_manager: The controller...

Writing a basic joint controller in ROS

The basic prerequisites for writing a ROS controller are already installed. We have discussed the underlying concepts of controllers. Now, we can start creating a package for our controller.

We are going to develop a controller that can access a joint of the robot and move the robot in a sinusoidal fashion. In particular, the first joint of the seven-DOF arm will follow a sinusoidal motion.

The procedure for building a controller is similar to other plugin development that we have seen earlier. The procedure to create a ROS controller is as follows:

  1. Create a ROS package with the necessary dependencies.
  2. Write controller code in C++.
  3. Register or export the C++ class as a plugin.
  4. Define the plugin definition in an XML file.
  5. Edit the CMakeLists.txt and package.xml files for exporting the plugin.
  6. Write the configuration for our controller.
  7. Load the controller using the controller manager.

Let&apos...

Understanding the RViz tool and its plugins

The RViz tool is an official 3D visualization tool of ROS. Almost all kinds of data from sensors can be viewed through this tool. RViz will be installed along with the full ROS desktop installation. Let's launch RViz and see the basic components present in RViz. Make sure you are executing these commands in separate terminals (or tabs).

Start roscore:

roscore

Start rviz:

rviz

The important sections of the RViz GUI are marked, and the uses of each section are shown in the following screenshot:

Figure 13.4 – Sections of RViz

We have seen how to work with RViz in ROS, and have seen different sections in RViz. In the following sections, we will provide a detailed explanation of each section of RViz.

The Displays panel

The panel on the left side of RViz is called the Displays panel. The Displays panel contains a list of the display plugins of RViz and its properties. The main use of...

Writing an RViz plugin for teleoperation

In this section, we will see how to create an RViz plugin from scratch. The objective of this plugin is to teleoperate the robot from RViz. Normally, we use separate teleoperation nodes for controlling the robot, but using this plugin, we can mention the teleop topic and the linear and angular velocity, as shown in the following screenshot:

Figure 13.5 – RViz Teleop plugin

In the following section, we discuss the detailed procedure of building this plugin.

The methodology of building a RViz plugin

Before starting to build the teleoperation plugin, we should understand how to write a RViz plugin in general. The standard method to build a ROS plugin is applicable for this plugin too. The difference is that the RViz plugin is GUI-based. RViz is written using a GUI framework called Qt, so we need to create a GUI in Qt and, using Qt APIs, we have to get the GUI values and send them to the ROS system.

The following...

Summary

In this chapter, we discussed creating plugins for RViz and writing basic ROS controllers. We have already worked with default controllers in ROS, and in this chapter, we developed a custom controller for moving joints. After building and testing the controller, we looked at RViz plugins. We created a new RViz panel for teleoperation. We can manually enter the topic name and linear and angular velocity in the panel. This panel is useful for controlling robots without starting another teleoperation node.

In the next chapter, we will discuss using ROS with MATLAB. MATLAB is a powerful numeric computing environment developed by MathWorks. The next chapter discusses how to interface this tool with ROS to create robot applications.

Here are some questions based on what we covered in this chapter.

Questions

  • What is the list of packages needed for writing a low-level controller in ROS?
  • What are the different processes happening inside a ROS controller?
  • What are the main packages of the ros_control stack?
  • What are the different types of RViz plugins?
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