ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
std_msgs::String msg;  // create a standard message object of type String (used to send messages between ROS services / nodes / programs)

std::stringstream ss;  // create a stringstream object which will store our text and take care of other operations on strings 

ss << "hello world " << count;  // fill the stringsream object with text "Hello world X". X represent the iteration number which was previously stored in "count" variable 

msg.data = ss.str();  // fill the data field of our ROS message with the text we previously stored in the stringstream object (you can see the stringstream object as a buffer where we store text) 

ROS_INFO("%s", msg.data.c_str()); // print the content of the ROS message in the console and save it in the log file

It will simply create a ROS message, fill it with a text and print it. Here's the line by line explanation:

std_msgs::String msg;  // create a standard message object of type String (used to send messages between ROS services / nodes / programs)

std::stringstream ss;  // create a stringstream object which will store our text and take care of other operations on strings 

ss << "hello world " << count;  // fill the stringsream object with text "Hello world X". X represent the iteration number which was previously stored in "count" variable 

msg.data = ss.str();  // fill the data field of our ROS message with the text we previously stored in the stringstream object (you can see the stringstream object as a buffer where we store text) 

ROS_INFO("%s", msg.data.c_str()); // print the content of the ROS message in the console and save it in the log file