ROS gpsd client Subscriber node (fix)
I want to write subscriber node for ROS GPSD client which is publishing GPS coordinates on topic "/fix". I don't know exactly what would be the right code and what changes I have to make in CMakeList.txt and package.xml. Below is the code
#include <ros/ros.h>
#include <sensor_msgs/NavSatStatus.h>
#include <sensor_msgs/NavSatFix.h>
using namespace gps_common;
void callback(const sensor_msgs::NavSatFixConstPtr& fix) {
if (fix->status.status == sensor_msgs::NavSatStatus::STATUS_NO_FIX) {
ROS_INFO("No fix.");
return;
}
if (fix->header.stamp == ros::Time(0)) {
return;
}
printf("\n Latitude = %f and Logitude = %f ",fix->latitude, fix->logitude);
}
int main (int argc, char **argv) {
ros::init(argc, argv, "gps_collect");
ros::NodeHandle node;
ros::Subscriber fix_sub = node.subscribe("fix", 10, callback);
ros::spin();
return 0;
}
Have you gone through the tutorials? These cover the basics (subscribing, publishing, etc.) pretty well. Are you getting any errors that you can post? I can't imagine that this code compiles with
return
statements in avoid
function.Also, in one of your
include
s you're mixing"
with<
.And just to make sure you've seen it: gpsd_client. There's nothing wrong with wanting to learn how to do something yourself btw.