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

You're reading from  Mastering ROS for Robotics Programming

Product type Book
Published in Dec 2015
Publisher Packt
ISBN-13 9781783551798
Pages 480 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Lentin Joseph Lentin Joseph
Profile icon Lentin Joseph

Table of Contents (19) Chapters

Mastering ROS for Robotics Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Introduction to ROS and Its Package Management Working with 3D Robot Modeling in ROS Simulating Robots Using ROS and Gazebo Using the ROS MoveIt! and Navigation Stack Working with Pluginlib, Nodelets, and Gazebo Plugins Writing ROS Controllers and Visualization Plugins Interfacing I/O Boards, Sensors, and Actuators to ROS Programming Vision Sensors using ROS, Open-CV, and PCL Building and Interfacing Differential Drive Mobile Robot Hardware in ROS Exploring the Advanced Capabilities of ROS-MoveIt! ROS for Industrial Robots Troubleshooting and Best Practices in ROS Index

Chapter 6. Writing ROS Controllers and Visualization Plugins

In the last chapter, we have discussed about pluginlib, nodelets, and Gazebo plugins. The base library for making plugins in ROS is pluginlib, and the same library can be used in nodelets and Gazebo plugins. In this chapter, we will continue with pluginlib-based concepts such as ROS controllers and 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 3, Simulating Robots Using ROS and Gazebo.

In this chapter, we will see how to write a basic ROS controller for a PR2 robot (https://www.willowgarage.com/pages/pr2/overview) and robots similar to PR2. After creating the controller, use the controller in PR2 simulation. The RViz plugins can add more functionality to RViz and in this chapter we can see how to create a basic RViz plugin. The detailed topics that we are going to discuss in this chapter are as follows:

  • Understanding...

Understanding pr2_mechanism packages


The pr2_mechanism stack contain packages for writing ROS real-time controllers. The first package that we are going to discuss is the pr2_controller_interface package.

pr2_controller_interface package

A basic ROS real-time controller must inherit a base class called pr2_controller_interface::Controller from this package. This base class contains four important functions: init() , start(), update(), and stop(). The basic structure of the Controller class is given as follows:

namespace pr2_controller_interface
{
  class Controller
  {
  public:
    virtual bool init(pr2_mechanism_model::RobotState *robot,
                     ros::NodeHandle &n);
    virtual void starting();
    virtual void update();
    virtual void stopping();
  };
}

The workflow of the controller class is shown as follows.

Figure 1: Workflow of the controller

Initialization of the controller

The first function executing when a controller is loaded is init(). The init() function will not...

Writing a basic real-time joint controller in ROS


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

We are going to develop a controller that can access a joint of the robot and move the robot in a sinusoidal fashion.

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

  • Create a ROS package with necessary dependencies

  • Write controller code in C++

  • Register or export the C++ class as plugin

  • Define the plugin definition in an XML file

  • Update the package.xml for exporting the plugin

  • Write CMakeLists.txt

  • Compile the code

  • Writing configuration for our controller

  • Start the PR2 simulation in Gazebo

  • Load the controller using the controller manager

Step 1 – Creating controller package

The first step is to create the controller package with all its...

Understanding ros_control packages


In the preceding section, we discussed the pr2_mechanism packages which build the controllers for PR2. These packages are exclusively designed for PR2, but they will work in robots that are similar to PR2.

To make these packages more generic to all the robots, the pr2_mechanism packages rewritten and formed a new set of packages called ros_control (http://wiki.ros.org/ros_control).

The ros_control implement standard set of generic controllers such as effort_controllers, joint_state_controllers, position_controllers, and velocity controllers for any kind of robots.

We have already used these ROS controllers from ros_control in Chapter 3, Simulating Robots Using ROS and Gazebo. The ros_control is still in development. The building procedure of the controllers is almost similar to PR2 controllers.

You can go through the available wiki page of ros_control for building new controls at https://github.com/ros-controls/ros_control/wiki.

You will get a sample controller...

Understanding ROS visualization tool (RViz) 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 ROS desktop full installation. Let's launch RViz and see the basic components present in RViz:

  • Start roscore

    $roscore
    
  • Start RViz

    $ rosrun rviz rviz
    

The important sections of the RViz GUI are marked and the uses of each section are given as follows:

Figure 6: RViz and its toolbars

Displays panel

The panel on the left side of the RViz is called Displays panel. The Displays panel contains a list of display plugins of RViz and its properties. The main use of display plugins is to visualize different types of ROS messages, mainly sensor data in the RViz 3D viewport. There are lots of display plugins already present in RViz for viewing images from camera, for viewing 3D point cloud, LaserScan, robot model, Tf, and so on. Plugins can be added by pressing the Add button on the...

Writing a RViz plugin for teleoperation


In this chapter, we design a teleoperation commander in which we can manually enter the teleoperation topic, linear velocity, and angular velocity, as shown in the following:

Figure 7: RViz teleop plugin

The following is a detailed procedure to build this plugin.

Methodology of building RViz plugin

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

The following steps describe how this teleoperation RViz plugin is going to work:

  • The dockable panel will have a Qt GUI interface and the user can input the topic, linear velocity, and angular velocity of teleoperation from the GUI.

  • Collect the user input from GUI using Qt signals/slots and publish the values...

Questions


  1. What are the list of packages needed for writing a real-time controller in ROS?

  2. What are the different processes happening inside a ROS controller?

  3. What are the main functions of the PR2 mechanism model?

  4. What are the different types of RViz plugins?

Summary


In this chapter, we discussed creating plugins for the ROS visualization tool (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; we need the twist messages and to enter the 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 interfacing of I/O boards and running ROS in embedded systems.

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