Get the GPS accuracy via mavlink


I would like to know if it is possible to get to accuracy of my copter position in real Time via Mavlink? If it is possible, could you help me please.

Thanks a lot.

It is in the stats but averaged to +/-1 meter. It would be nice if it ran out a few decimal places.

Take a look at this

And its will be helpful

Thanks for the fast reply guyz.

I’ve already read those topics. They show how to read the GPS data, which i’ve done already. I have use the GPS_POSITION_INT (long, lat and alt) to take my vehicle position.
Now I would like to take the accuracy of my position (lon, lat and alt) in real time. I don’t know what mavlink message i should read.

in the logs of ardupilot there is a category with name GPA with these sub data (VDop, HAcc, VAcc, SAcc, VV)
HAcc = horizontal accuracy
VAcc = vertical accuracy

try to find these items in mavlink data if cant get these data i will read the source code to find out parameters name

Accuracy is contained in the GPS_RAW_INT mavlink message. Here’s an example from MAVProxy on my drone:
281059: GPS_RAW_INT {time_usec : 155889790000, fix_type : 3, lat : 375161843, lon : -1220451322, alt : -1200, eph : 120, epv : 194, vel : 12, cog : 26644, satellites_visible : 8, alt_ellipsoid : 0, h_acc : 0, v_acc : 0, vel_acc : 0, hdg_acc : 0}
I’m actually not sure why the accuracy values are reported as 0 here. The values are nonzero in the flight logs, so it might be as @mtnsurveyor said and that they’re being casted into integers in the mavlink message and appearing as 0 when they’re <1.0.

Hi @Rick
Could you please send data when your copter is under a roof ?

It was indoors already, actually.

It looks like these mavlink message fields aren’t being used. I recorded a log that showed my accuracy values to be 3-6 meters, but GPS_RAW_INT was still reporting 0.
Correction: they are being used. Something was wrong with my setup.

1 Like

How do I read the log?
Is it possible to read the log and take the accuracy with a python program?

The flight logs are recorded on the SD card inside the flight controller. You can access them by downloading them with ground control software like Mission Planner, or by putting the SD card in your computer.

In the log, the accuracy data is contained in the GPA category. In Mission Planner, it looks like this:

And yes, the logs can be parsed by scripts. The logs are in a binary format, but Mission Planner automatically converts and creates a plain-text .log version when you download them. Mission Planner also has a button to convert any log, or you can use any of these tools to do it yourself if you want.

1 Like

Okey thank you. I get.

But the problem with this method is that It is not in a real time. Or in my project I need the accuracy in real time. Not after the flight.
I need to to get the accuracy and do some calculation in real time with that.
Do you have another idea, please?

EDIT: These are unnecessary because the mavlink message does work.

There’s three ways I can think of to do this, in order of “good idea” to “bad idea”:

  1. Modify the code so that the GPS_RAW_INT message sends the accuracy values. I found the relevant code: I’m not sure why they don’t send those values.
  2. If you have a companion computer, you can plug the GPS into it instead of the flight controller. This will let your companion computer get the accuracy data and then pass the GPS data to the flight controller.
  3. With a companion computer, you can enable realtime flight logging using dataflash-over-mavlink. MAVProxy can do this. This will write the flight log to the companion computer in real time, so you can have a script extract the accuracy data.

Wow, the three of them sound hard to do. I’ll try the first one and I’ll let you know

Thank you for your help.
If you think about any other ideas, please let me know.

You can use RTK to get these #s to minimums but the truth is they do not check to these values.
If you watch your elevation you can see much more variance than reported.

I looked at the code a bit more. Everything seems correct; the function that writes the Mavlink message uses the same code as the one which writes data to the flight log, so it should work. I’m not sure what is wrong.

It does work. I was able to get accuracy data through mavlink with Mission Planner. Not sure why my Mavproxy setup was showing 0’s, but this shows that the data is there.

Guyz!! Good news!!!

I have tried with the GPS_RAW_INT to get the h_acc.
This is my code on my companion

And this my the result when I run the program. I work. It seems that the accuracy is around 5m.

But I would like to know what is the meaning of h_acc and v_acc?

Thank you for your help guyz

take a look at this post

Hello, kinda of a newbie here. Also trying to get the gps accuracy, how do you execute that code with mission planner?