ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

How to access the instant ros callback value

So i am subscribing the position of a marker, but i would like to access its position at the instant i am using the function so that i can put the x y z coordinate into a vector. how should i do that ?

#include "ros/ros.h"
#include <math.h>
#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include "geometry_msgs/PoseStamped.h"
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/PoseWithCovariance.h"
#include <visp/vpDisplayGDI.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDot2.h>
#include <visp/vpImageIo.h>
#include <visp/vpPixelMeterConversion.h>
#include <visp/vpPose.h>
 
using namespace cv;
using namespace std;
 
void imageCallback(const geometry_msgs::PoseStamped::ConstPtr& ps4){
     
cout<<"pose is"<<ps4->pose.position<<endl;
//ps_cov->publish(ps);
 
}
 
 
 
int main(int argc,char** argv){
    geometry_msgs::PoseStamped my_vidoe;
    ros::init(argc, argv, "visp_auto_tracker_1");
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe<geometry_msgs::PoseStamped>("/visp_auto_tracker/object_position", 1000, imageCallback);
     
    ros::spin();
    return 0;
}

Hi Aankin_wang,

According to ROS community support guidelines http://wiki.ros.org/Support this question should be better asked in http://answers.ros.org

Please do not post questions on the discourse.ros.org they should go to ROS Answers.
ROS Discourse is for news and general interest discussions. ROS Answers provides a forum which can 
be filtered by tags to make sure the relevant people are included and not overload everyone.

Best regards,
Martin