Outputting logging messages

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 in C++:

    $ ROS_INFO("My INFO message.");
  

In order to have access to these logging functions/macros, the following header is required:

#include <ros/ros.h> 

This includes the following header (where the logging API is defined):

#include <ros/console.h> 

As a result of running a program with the preceding message, we will get the following output:

    [ INFO] [1356440230.837067170]: My INFO message.  

All messages are printed with their level and the current timestamp (your output might differ for this reason) before the actual message, with both between square brackets. The timestamp is the epoch time, that is, the number of seconds and nanoseconds since January 1, 1970. Then, we have our message-always with a new line.

This function allows parameters in the same way as the C printf function does. For example, we can print the value of a floating point number in the variable val with this code:

floatval = 1.23; 
ROS_INFO("My INFO message with argument: %f", val); 

C++ STL streams are also supported with *_STREAM functions. Therefore, the previous instruction is equivalent to the following using streams:

ROS_INFO_STREAM("My INFO message with argument: " <<val); 

Note that we did not specify any stream since the API takes care of that by redirecting to cout/cerr, a file, or both.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.181