Unable to use data received in callback function
Hi. I am receiving data in a call back function using class. But i can't use data in main function. Any solutions?
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "driving_msgs/StateArray.h"
#include "geometry_msgs/Twist.h"
#include <iostream>
using namespace std;
class server
{
public:
int totalobjects;
void chatterCallback(const driving_msgs::StateArray& msg);
};
void server::chatterCallback(const driving_msgs::StateArray& msg)
{
totalobjects = msg.objects.size();
}
int main(int argc, char **argv)
{
server objserver;
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/ground_truth", 1000, &server::chatterCallback, &objserver);
ros::spin();
cout << objserver.totalobjects;
cout<<"\n";
return 0;
}
http://wiki.ros.org/roscpp/Overview/C...