How to get the message from the Subscriber Function
Hi, I am relatively new to ROS and have a question regarding Publisher and Subscriber.
To make this easy I use the Code from the ROS Tutorial "Writing a Simple Publisher and Subscriber (C++)". I can get everything to run and I can see the published messages through the "listener" node.
My question now is, how can I get the messages from the "chatterCallback" function back into my main function because I want to use it with Data from the main. I looked into the documentation of "subscribe" but I cant get it to work.
Maybe I cant see the obvious solution because I didn't programmed for a while now.
Used Code: http://wiki.ros.org/ROS/Tutorials/Wri...
#include "ros/ros.h"
#include "std_msgs/String.h"
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
//here I want access to the message from chatterCallback
ros::spin();
return 0;
}
Thank you for the answers.
Welcome! What does
mean? What have you tried (post your code please)?
I edited the post.