Mavlink latitude and longitude

689 views
Skip to first unread message

Enzo Buono

unread,
Jul 27, 2015, 5:36:42 AM7/27/15
to MAVLink
Hi to all,
I have a doubt. I am trying to send waypoint command using mission_item message. I am testing the drone without props now, and It seem that the command is working. I would to set latitude and longitude ,in mission_item message, using my position and adding an offset. But I read lat an lon with GPS_RAW_INT message and lat and long are integer number with 9 digit. The mission item message accept float value for lat and lon. I need to put the comma? For example:
lat(int)=401234567 -> 40.1234567. I am programming with c++, if I do a cast int to float I lost 3 digit after the comma, Is the precision worst with float value? I would use SET_POSITION_TARGET_LOCAL_NED instead but I have an APM 2.6 and it doesn't support this :/

Bill Bonney

unread,
Jul 27, 2015, 12:53:58 PM7/27/15
to mavlink, mavlink

double lat = static_cast<double>(gps_raw_int.lat / 1E7);

OR

float lat = static_cast<float>(gps_raw_int.lat / 1E7);


That will convert the number fro int32 to double, or you can make it float (but you lose precision* unless the original was a float of course)

Bill.

> --
> Sie erhalten diese Nachricht, weil Sie Mitglied der Google Groups-Gruppe "MAVLink" sind.
> Wenn Sie sich von dieser Gruppe abmelden und keine E-Mails mehr von dieser Gruppe erhalten möchten, senden Sie eine E-Mail an mavlink+u...@googlegroups.com.
> Weitere Optionen: https://groups.google.com/d/optout

Enzo Buono

unread,
Jul 28, 2015, 5:19:34 AM7/28/15
to MAVLink, billb...@communistech.com
Hi Bill,
thank you for the answer, I tried your method but I lost 3 digit after the comma. But mission_item message accept float values. This is the only way to do this? 

Bill Bonney

unread,
Jul 28, 2015, 9:51:56 AM7/28/15
to Enzo Buono, MAVLink
You could try 1.0E7 as the way to represent 10000000.0 ie double lat = static_cast<double>(gps_raw_int.lat / 1.0E7);

Adding the .0 should make sure the number is interpreted as a doube/float and the the division will then be not an integer division.

What compiler are you using, platform etc.

Bill
Reply all
Reply to author
Forward
0 new messages