Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 6

How to subscribe the topic only once

Previous: Answer by gvdhoorn for 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!
$
0
0
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 #include #include 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!

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images