Showing messages once, throttling, and other combinations

It is also possible to control how many times a given message is shown. We can print it only once with ROS_<LEVEL>[_STREAM]_ONCE[_NAMED]:

for(int i = 0; i< 10; ++i ) { 
  ROS_INFO_STREAM_ONCE("My once INFO stream message; i = " <<i); 
} 

This code from the example2 node will show the message only once.

However, it is usually better to show the message with a certain frequency. For that, we have throttle messages. They have the same format as the once message, but here ONCE is replaced with THROTTLE. They also include a first argument, which is period in seconds, that is, it is printed only every period seconds:

for(int i = 0; i< 10; ++i ) { 
  ROS_INFO_STREAM_THROTTLE(2, 
    "My throttle INFO stream message; i = " <<i); 
  ros::Duration( 1 ).sleep(); 
} 

Finally, note that named, conditional, and once/throttle messages can be used together with all the available levels.

Nodelets also have some support in terms of logging messages. Since they have their own namespace, they have a specific name to differentiate the message of one nodelet from another. Simply put, all the macros shown until now are valid, but instead of ROS_*, we have NODELET_*. These macros will only compile inside nodelets. In addition, they operate by setting up a named logger with the name of the nodelet running so that you can differentiate between the outputs of two nodelets of the same type running in the same nodelet manager. They also have an advantage in that you can turn one specific nodelet into the debug level instead of all the nodelets of a specific type.

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

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