How can I store subscribed message and use that from other function?
Hi.
I've written a simple subscriber to subscribe and use message, but it isn't work. it just prints zero, not stored values.
The subscriber is test program to use stored message from published by v-rep.
How should I change in this code?
Thank you for your interest and help.
#include <ros/ros.h>
#include <geometry_msgs/Pose.h>
geometry_msgs::Pose p;
void poseCB(const geometry_msgs::Pose::ConstPtr &msg) {
p = *msg;
}
void print() {
ROS_INFO("Crrent state : (%f, %f, %f)", p.position.x, p.position.y, p.position.z);
}
int main(int argc, char **argv) {
ros::init(argc, argv, "sub_test");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe<geometry_msgs::Pose>("/vrep_ros_interface/bear_pose", 1, &poseCB);
print();
ros::spin();
return 0;
}