Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to subscirbe 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!

How to subscirbe 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){&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!

How to subscirbe 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) **argv)

{ ros::init(argc, argv, "test");

ros::NodeHandle nh;

ros::Subscriber positions_sub = nh.subscribe("/POSITIONS", 3, &imageCallback);

ros::spin(); 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!

click to hide/show revision 4
None

How to subscirbe 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
#include  <ros ros.h="">

include <sensor_msgs navsatfix.h="">

include <geometry_msgs pointstamped.h="">

<ros/ros.h> #include <sensor_msgs/NavSatFix.h> #include <geometry_msgs/PointStamped.h> static geometry_msgs::PointStamped point;

point;

void imageCallback(const sensor_msgs::NavSatFix::ConstPtr &msg) {

{ point.point.x=msg->latitude; point.point.y=msg->longitude; point.point.z=msg->altitude; }

point.point.x=msg->latitude;

point.point.y=msg->longitude;

point.point.z=msg->altitude;

}

int main(int argc, char **argv)

**argv) { ros::init(argc, argv, "test");

"test"); ros::NodeHandle nh;

nh; ros::Subscriber positions_sub = nh.subscribe("/POSITIONS", 3, &imageCallback);

ros::spin();

}

&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!

How to subscirbe 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!