ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

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 sensor_msgs::NavSatFix, and your #include should point to sensor_msgs/NavSatFix.h. You'll also need to have a <depend package="sensor_msgs"/> line in your package's manifest.xml.

#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>

void callback(const sensor_msgs::NavSatFixConstPtr &fix) {
  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;
}

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 sensor_msgs::NavSatFix, and your #include should point to sensor_msgs/NavSatFix.h. You'll also need to have a <depend package="sensor_msgs"/> line in your package's manifest.xml.

#include <ros/ros.h>
#include <sensor_msgs/NavSatFix.h>
#include <sensor_msgs/NavSatStatus.h>

void callback(const sensor_msgs::NavSatFixConstPtr &fix) {
  if (fix->status.status == sensor_msgs::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;
}

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 sensor_msgs/NavSatFix.hgps_common/NavSatFix.h. You'll also need to have a <depend package="sensor_msgs"/>package="gps_common"/> line in your package's manifest.xml.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 sensor_msgs::NavSatFixConstPtr NavSatFixConstPtr &fix) {
  if (fix->status.status == sensor_msgs::NavSatStatus::STATUS_NO_FIX) 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;
}