How to get an accuracy of e-7 from ublox gps

asked 2020-08-24 10:57:37 -0500

romaxtech gravatar image

I'm on ROS melodic and ubuntu 18.04.

I use a ublox gps module and I try to get the longitude and latitude with a precision of e-7.

I manage to display the coordinates on the topic with rostopic echo /ublox_gps/fix from https://github.com/ros-agriculture/ub... and I'm getting good latitude and longitude with accuracy e-7.

But when I create a subscriber (see below) to get these values , the accuracy of the latitude changes to e-4 but the longitude remains at e-7.

Do you know why? I don't know where to look to change the accuracy.

The code suscriber (c++):

#include <iostream>
#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;
      }

  double longitude = fix->longitude;
  double latitude = fix->latitude;

  std::cout << "Current Latitude: "  << latitude  << std::endl;
  std::cout << "Current Longitude: " << longitude << std::endl;

}
int main(int argc, char **argv) {
  ros::init(argc, argv, "suscriber_ublox");
  ros::NodeHandle nh;

  ros::Subscriber gps_sub = nh.subscribe("/ublox_gps/fix", 10, callback);

  ros::spin();
  return 0;
}
edit retag flag offensive close merge delete

Comments

But when I create a subscriber (see below) to get these values , the accuracy of the latitude changes to e-4 but the longitude remains at e-7.

How did you verify "the accuracy"?

std::cout << latitude << std::endl is not what I would consider a sufficient test to state anything about the accuracy.

For one thing, the nr of digits printed would depend on the configuration of the stream being output to. See setprecision(..), but that doesn't really mean anything for the floating point nr itself.

gvdhoorn gravatar image gvdhoorn  ( 2020-08-24 11:20:21 -0500 )edit

Longitude and latitude was well set to e -7 but once printed, we had latitude with 4 digits and longitude with 7 digits. Why one good and not the other?

Anyway, with setposition( ) for the latitude value, we solved the problem Thank you very much!

romaxtech gravatar image romaxtech  ( 2020-08-25 02:54:53 -0500 )edit

Anyway, with setposition( ) for the latitude value, we solved the problem

Please do realise setprecision(..) does not change anything in the underlying double.

It only changes how many digits are printed when passing the double to an output stream (ie: cout).

gvdhoorn gravatar image gvdhoorn  ( 2020-08-25 02:57:57 -0500 )edit