How to know /GPSFix message availability?
Below program will perfectly subscribe /GPSFIX value from rosbag and print Latitude Longitude values. I want this program to print the value 0 always even in the absence of /GPSFIX publisher. Because always i want to print 0 at first then followed by Lat/Long if publisher is available otherwise 0 alone always .
EDIT: Using this code how to check whether /GPS message is available through c++ program?
First i want to check availability of /GPSFix messagge after that i want to print LatLong like this format. That is value zero followed by lat/long message.
Program:
#include "ros/ros.h"
#include <gps_common/GPSFix.h>
using namespace std;
void GPSCallback(const gps_common::GPSFix::ConstPtr& msg)
{
printf("%f\n", msg->longitude);
printf("%f\n", msg->latitude);
fflush(stdout);
sleep(2);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/GPSFix", 10, GPSCallback);
ros::spin();
return 0;
}
Current Output:
Longitude: 80.0910
Latitude: 13.1289
Longitude: 80.0911
Latitude: 13.1289
Longitude: 80.0912
Latitude: 13.1290
Longitude: 80.0913
Latitude: 13.1289
Longitude: 80.0912
Latitude: 13.1288
My expected output format if /GPSFix is available:
0
Longitude: 80.0910
Latitude: 13.1289
0
Longitude: 80.0911
Latitude: 13.1289
0
Longitude: 80.0912
Latitude: 13.1290
0
Longitude: 80.0913
Latitude: 13.1289
0
Longitude: 80.0912
Latitude: 13.1288
Incase /GPSFix is not available output should be like
0
0
0
0
0