Robotics StackExchange | Archived questions

How to read data from "/rosout" topic using c++ node.

I want to write a c++ node which subscribe the topic /rosout read data from it and print the extracted data on terminal using ROS_INFO().

Asked by kjitender469 on 2019-10-11 04:38:57 UTC

Comments

You just need a subscriber to the topic to read the data it contains. You can follow example here

Asked by Choco93 on 2019-10-11 04:59:20 UTC

Answers

Hello,

ROS_INFO() will display the message in the terminal, but ROS_INFO() will also send a message to /rosout. If you create a node that subscribe to /rosout and use ROS_INFO(), you will write an infinite loop because :

1 . Node receive message from /rosout

2 . Node print with ROS_INFO()

3 . ROS_INFO() Send a message to /rosout

4 . Go back to 1

For a simple example of how to do a subscriber, you can subscribe to /rosout and simply use std::cout for displaying the message (or your favorite logging system that doesn't use /rosout).

If you want to extract Warning, Error or Fatal level message, you can use a message filter, or just discarding message with logger level less than warning in the beginning of the callback function.

Asked by lmathieu on 2019-10-11 05:54:46 UTC

Comments

Ok. I have written a node using C++ but i am unable to extract "msg" field data from it. The type of rosout is rosmsgs_graph/Log. I want to extract the data from "msg" field and convert it into string.

Asked by kjitender469 on 2019-10-11 07:24:11 UTC