Ask Your Question
0

Ros subscriber

asked 2016-08-02 23:19:56 -0600

SaurabhR gravatar image

updated 2016-08-02 23:20:26 -0600

Hi, Can somebody explain me the following line of code line by line ? The code has been taken from ros tutorials.

  std_msgs::String msg;
  std::stringstream ss;
 ss << "hello world " << count;
  msg.data = ss.str();
   ROS_INFO("%s", msg.data.c_str());

Here is the link to the code http://wiki.ros.org/ROS/Tutorials/Wri...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-08-03 01:38:33 -0600

Horse-man gravatar image

updated 2016-08-03 01:41:15 -0600

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-02 23:19:56 -0600

Seen: 80 times

Last updated: Aug 03 '16