The relevant topic names and message types have been shuffled a bit since that tutorial was last updated. You'll want to replace gps_common::GPSFix
with gps_common::NavSatFix
(or sensor_msgs::NavSatFix
if you're using Diamondback), and your #include
should point to gps_common/NavSatFix.h
. You'll also need to have a <depend package="gps_common"/>
line in your package's manifest.xml. If you're using Cturtle, set gpsd_client's ~report_as
parameter to "navsat".
#include <ros/ros.h>
// Change following lines to "gps_common" if you're using Cturtle
#include <sensor_msgs/NavSatFix.h>
#include <sensor_msgs/NavSatStatus.h>
using sensor_msgs;
void callback(const NavSatFixConstPtr &fix) {
if (fix->status.status == NavSatStatus::STATUS_NO_FIX) {
std::cout << "Unable to get a fix on the location." << std::endl;
return;
}
std::cout << "Current Latitude: " << fix->latitude << std::endl;
std::cout << "Current Longitude " << fix->longitude << std::endl;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "gps_subscriber");
ros::NodeHandle nh;
ros::Subscriber gps_sub = nh.subscribe("fix", 1, callback);
ros::spin();
return 0;
}