How to subscribe the topic only once
I have a problem about how to sucscribe the topic only once,In some time, I only hope to get the first data from the topic, rather than change the publisher. So how should I do? This is my code:
#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <geometry_msgs/PointStamped.h>
static geometry_msgs::PointStamped point;
void imageCallback(const sensor_msgs::NavSatFix::ConstPtr &msg)
{
point.point.x=msg->latitude;
point.point.y=msg->longitude;
point.point.z=msg->altitude;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "test");
ros::NodeHandle nh;
ros::Subscriber positions_sub = nh.subscribe("/POSITIONS", 3, &imageCallback);
ros::spin();
}
In this code, I can get many points, but I only hope to get the first point. What should I change in tthe code ? THANKS!