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 3. Visualization and Debug Tools

ROS has a good number of tools that allow the user and the developer to visualize and debug the code in order to detect and solve issues with both hardware and software. This comprises a message logging system similar to log4cxx, diagnostic messages and also visualization and inspection tools that show which nodes are running and how are they connected.

In this chapter, we will also show you how to debug an ROS node with the GDB debugger. The message logging API will be explained, and advice will be given on how to choose the logging level. Then, we will explain the set of ROS tools that are meant to inspect which processes are running and what information is communicated among them. For instance, the following figure shows a tool that visualizes the graph of the system, where the nodes are the processes running and the edges represent the data workflow through communication topics. This tool is rqt_graph, and in this case, it show the nodes and topics...

Debugging ROS nodes


ROS nodes can be debugged as regular programs. They run as a process in the operative system and have a PID. Therefore, you can debug them as with any program using standard tools, such as gdb. Similarly, you can check for memory leaks with valgrind or profile the performance of your algorithm with callgrind. However, remember that in order to run a node, you must run the following command:

$ rosrun chapter3_tutorials example1

Unfortunately, you cannot run the command in the following way:

$ gdb rosrun chapter3_tutorials example1

In the next sections, we will explain how to call these tools for an ROS node to overcome this issue. Later, we will see how to add a logging message to our code in order to make it simple to diagnose problems that, in practice, helps to diagnose basic problems even without debugging the binaries. Similar, later on, we will discuss ROS introspection tools that allow detecting broken connections between nodes easily. Therefore, although here we...

Logging messages


It is a good practice to include messages that indicate what the program is doing. But we must do it without compromising on the efficiency of our software and the clarity of its output. In ROS, we have an API that covers both features, built on top of log4cxx (a port of the well-known log4j logger library). In brief, we have several levels of messages, which might have a name (named messages) and depend on a condition or even throttle. All of them have a null footprint on performance if they are masked by the current verbosity level (even at compile time). They also have full integration with other ROS tools to visualize and filter the messages from all the nodes running.

Outputting a logging message

ROS comes with a great number of functions/macros to output logging messages. It supports different levels, conditions, STL streams, throttling, and other features that we will see in this section. To start with something simple, an information message is printed with this code...

Inspecting what is going on


When our system is running, we might have several nodes and many more topics publishing messages among nodes. Also, we might have nodes providing actions or services as well. For large systems, it is important to have tools that let us see what is running at a given time. ROS provides basic but powerful tools with this aim, from the CLI to GUI applications.

Listing nodes, topics, services, and parameters

In our honest opinion, we will start with the most basic level of introspection. We are going to see how to obtain the list of nodes running and topics and services available at a given time:

Obtain the list of all

Command

Nodes running

rosnode list

Topics of all nodes running

rostopic list

Services of all nodes running

rosservice list

Parameters on the server

rosparam list

We recommend that you go back to Chapter 2, ROS Architecture and Concepts, to see how these commands also allow us to obtain the message type sent by a particular topic as well...

Setting dynamic parameters


If a node implements a dynamic reconfigure parameter server, we can use rqt_reconfigure to modify them on the fly. Run the following example, which implements a dynamic reconfigure server with several parameters (see the cfg file in the cfg folder of the package).

$ roslaunch chapter3_tutorials example6.launch

With the dynamic reconfigure server running, open the GUI with the following command:

$ rosrun rqt_reconfigure rqt_reconfigure

Select the example6 server in the left-hand side table list, and you will see its parameters, which you can modify directly. The parameter changes take effect immediately, running the code inside a callback method in the source code, which checks for the validity of the values. In this example, the parameters are printed every time they are changed, that is, when the callback method is executed. The following screenshot encapsulates this discussion:

Dynamic parameters were originally meant for drivers, so it was easy to modify them...

When something weird happens


ROS has several tools to detect potential problems in all the elements of a given package. Just move with roscd to the package you want to analyze. Then, run roswtf. For chapter3_tutorials, we have the following output. Note that if you have something running, the ROS graph would be analyzed too. We run the roslaunch chapter3_tutorials example6.launch command that yields the an output similar to the following screenshot:

In general, we should expect no error or warning, but even some of them are innocuous. In the preceding screenshot, we see that roswtf does not detect any error; it only issues a warning about pip, which sometimes might generate problems with the Python code installed in the system. Note that the purpose of roswtf is to signal potential problems, and then we are responsible to check whether they are real or meaningless ones, as in the previous case.

Another useful tool is catkin_lint, which helps to diagnose errors with catkin, usually in the CMakeLists...

Visualizing node diagnostics


ROS nodes can provide diagnostic information using the diagnostics topic. For that, there is an API that helps to publish diagnostic information in a standard way. The information follows the diagnostic_msgs/DiagnositcStatus message type, which allows us to specify a level (OK, WARN, ERROR), name, message, and hardware ID as well as a list of diagnostic_msgs/KeyValue, which are pairs of key and value strings.

The interesting part comes with the tools to collect and visualize this diagnostic information. At the basic level, rqt_runtime_monitor allows us to visualize the information directly published through the diagnostics topic. Run the example7 node, which publishes information through the diagnostics topic and this visualization tool to see the diagnostic information:

$ roslaunch chapter3_tutorials example7.launch
$ rosrun rqt_runtime_monitor rqt_runtime_monitor

The preceding commands display the following output:

When the system is large, we can aggregate diagnostic...

Plotting scalar data


Scalar data can be easily plotted with generic tools already available in ROS. Even nonscalar data can be plotted, but with each scalar field plotted separately. That is why we talk about scalar data, because most nonscalar structures are better represented with ad hoc visualizers, some of which we will see later; for instance, images, poses, orientation/attitude, and so on.

Creating a time series plot with rqt_plot

Scalar data can be plotted as a time series over the time provided by the timestamps of the messages. Then, in the y axis, we will plot our scalar data. The tool to do so is rqt_plot. It has a powerful argument syntax, which allows specifying several fields of a structured message in a concise manner as well; we can also add or remove topics or fields manually from the GUI.

To show rqt_plot in action, we are going to use the example4 node since it publishes a scalar and a vector (nonscalar) in two different topics, which are temp and accel, respectively. The...

Image visualization


In ROS, we have a node that allows the display of images coming from a camera on-the-fly. This is an example of a topic with complex data, which is better visualized or analyzed with special tools. You only need a camera to do this, such as your laptop webcam. The example8 node implements a basic camera capture program using OpenCV and ROS bindings to convert cv::Mat images into ROS Image messages that can be published in a topic. This node publishes the camera frames in the /camera topic.

We are only going to run the node with a launch file created to do so. The code inside the node is still new for the reader, but in the next chapters, we will cover how to work with cameras and images in ROS, so we will be able to come back to this node and understand it:

$ roslaunch chapter3_tutorials example8.launch

Once the node is running, we can list the topics (rostopic list) and see that the /camera topic is there. A straightforward way to verify that we are actually capturing...

3D visualization


There are certain devices (such as stereo cameras, 3D lasers, the Kinect sensor, and so on) that provide 3D data—usually in the form of point clouds (organized/ordered or not). For this reason, it is extremely useful to have tools that visualize this type of data. In ROS, we have rviz or rqt_rviz, which integrates an OpenGL interface with a 3D world that represents sensor data in a world representation, using the frame of the sensor that reads the measurements in order to draw such readings in the correct position with respect to each other.

Visualizing data in a 3D world using rqt_rviz

With roscore running, start rqt_rviz with (note that rviz is still valid in ROS hydro):

$ rosrun rqt_rviz rqt_rviz

We will see the graphical interface of the following screenshot, which has a simple layout:

On the left-hand side, we have the Displays panel, in which we have a tree list of the different elements in the world, which appears in the middle. In this case, we have certain elements...

Saving and playing back data


Usually, when we work with robotic systems, the resources are shared, not always available, or the experiments cannot be done regularly because of the cost or time required for preparing and performing them or because they are difficult to reproduce. For this reason, it is a good practice to record the data of the experiment session for later analysis and to work, develop, and test our algorithms. However, the process of saving good data so that we can reproduce the experiment offline is not trivial. Fortunately, in ROS, we have powerful tools that have already solved this problem.

ROS can save all the messages published on any topic. It has the ability to create a bag file that contains the messages as they are with all their fields and timestamps. That allows the reproduction of the experiment offline with its real conditions on the robot as the latency of messages transmission. What's more, ROS tools do all this efficiently, with a high bandwidth, and in an...

Using the rqt_gui and rqt plugins


Since ROS Fuerte, the rx applications or tools are deprecated, and we should instead use the rqt nodes. They are basically the same, and only a few of them incorporate small updates, bug fixes, and new features. The following table shows the equivalences for the tools shown in this chapter (the ROS hydro rqt tool and the one it replaces from previous ROS distributions):

ROS hydro rqt tool

Replaces (ROS fuerte or before)

rqt_console and rqt_logger_level

rxconsole

rqt_graph

rxgraph

rqt_reconfigure rqt_reconfigure

dynamic_reconfigure reconfigure_gui

rqt_plot

rxplot

rqt_image_view

image_view

rqt_bag

rxbag

In ROS hydro, there are even more standalone plugins, such as a shell (rqt_shell), a topic publisher (rqt_publisher), a message type viewer (rqt_msg), and much more (the most important ones have been covered in this chapter). Even rqt_viz is a plugin, which replaces rviz, and can also be integrated into the new rqt_gui interface...

Summary


After reading and running the code of this chapter, you learned to use many tools that help you to develop robotic systems faster, debug errors, and visualize your results, so that you can evaluate their quality or validate them. Some of the specific concepts and tools you will exploit the most in your life as a robot developer have been summarized here.

Now you know how to include logging messages in your code with different levels of verbosity, which will help you to debug errors in your nodes. For this purpose, you can also use the powerful tools included in ROS, such as the rqt_console interface. Additionally, you can also inspect or list the nodes running, topics published, and services provided in the whole system. This includes the inspection of the node graph using rqt_graph.

Regarding the visualization tools, you should be able to plot scalar data using rqt_plot for a more intuitive analysis of certain variables published by your nodes. Similarly, you can view more complex...

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}