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

Slevin Kelevra's profile - activity

2019-03-05 14:56:38 -0500 marked best answer 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.

2018-04-18 06:07:32 -0500 received badge  Famous Question (source)
2018-04-18 06:07:32 -0500 received badge  Notable Question (source)
2018-01-26 08:51:39 -0500 received badge  Supporter (source)
2018-01-19 02:11:49 -0500 received badge  Popular Question (source)
2018-01-18 14:56:42 -0500 commented answer How to get the message from the Subscriber Function

...messages till I get them from the main function?

2018-01-18 14:56:19 -0500 commented answer How to get the message from the Subscriber Function

I knew that I could use a global variable but I learned that global variables should be avoided if possible. I try your

2018-01-18 13:03:35 -0500 commented question How to get the message from the Subscriber Function

I edited the post.

2018-01-18 13:03:04 -0500 edited question How to get the message from the Subscriber Function

How to get the message from the Subscriber Function Hi, I am relatively new to ROS and have a question regarding Publis

2018-01-18 10:59:44 -0500 asked a question How to get message from Subscriber into main

How to get message from Subscriber into main Hi, I am relatively new to ROS and have a question regarding Publisher and

2018-01-18 10:59:44 -0500 asked a question How to get the message from the Subscriber Function

How to get the message from the Subscriber Function Hi, I am relatively new to ROS and have a question regarding Publis