Skip to content

AP_Mount, AP_DDS: fix lat/lon precision loss in Topotek and DDS goal - #34929

Open
tatsuy wants to merge 2 commits into
ArduPilot:masterfrom
tatsuy:pr-fix-latlng-float32
Open

tatsuy wants to merge 2 commits into
ArduPilot:masterfrom
tatsuy:pr-fix-latlng-float32

Conversation

@tatsuy

@tatsuy tatsuy commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix loss of precision in the latitude/longitude sent to Topotek gimbals and published on the DDS /ap/goal_lla topic.
Same issue as the Xacti fix in #34925.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Not tested on hardware. Build-tested only:

  • Topotek: built for CubeOrange and confirmed in the disassembly that latitude/longitude are now computed in double precision (vdiv.f64).
  • DDS: built SITL with --enable-DDS and confirmed in the disassembly that latitude/longitude are now computed in double precision (cvtsi2sd + divsd).

Description

Both places store the result in a double, but calculate it as loc.lat * 1e-7. With -fsingle-precision-constant, 1e-7 is a float, so the value is computed in single precision. This rounds the longitude to steps of about 1.5e-5° (~1.4 m).

  • AP_Mount_Topotek: the position is sent as ddmm.mmmm (resolution ~1.9e-6°), so the float rounding is coarser than the output format.
  • AP_DDS_Client: geographic_msgs/GeoPoint defines latitude/longitude as float64.

This PR casts to double before dividing, so the full precision of the int32 location is kept.

This contribution was AI-assisted.

tatsuy and others added 2 commits October 28, 2026 22:32
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tatsuy

tatsuy commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

AP_NMEA_Output.cpp uses a similar loc.lat * 1.0e-7f pattern, but I left it out of this PR because the problem is different:

  • The minutes part (min_dec) is already calculated in double, so normal output does not lose precision.
  • Only the integer-degree part is calculated in float. When the position is just below an integer degree (within ~1.6e-6° for latitude, ~6.4e-6° for longitude, i.e. less than 1 m), it rounds up and the minutes become negative, producing a malformed sentence, e.g. 35.9999990 → 36-0.00006.
  • Fixing it needs the degree/minute split to be reworked, not just a cast, so it seemed better handled separately.

I'm happy to add the fix to this PR or open a separate one, whichever the reviewers prefer.

@tatsuy tatsuy changed the title Pr fix latlng float32 AP_Mount, AP_DDS: fix lat/lon precision loss in Topotek and DDS goal Oct 28, 2026
@github-actions

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from 4ff58a8 rebased onto 6743a33

Board Periph tracker blimp bootloader copter heli iofw plane rover sub
DrotekP3Pro _ _ _ * _ _ _ _ _ _
Durandal _ * * _ -4 -4 _ -4 -4 -4
Hitec-Airspeed * _ _ _ _ _ _ _ _ _
KakuteF7 _ * * _ * * _ * * *
MambaH743v4 _ * * _ +4 +4 _ +4 +4 +4
MatekF405-CAN _ _ _ * _ _ _ _ _ _
MatekF405 _ * * _ * * _ * * *
MatekH743-bdshot _ * * _ -4 -4 _ -4 -4 -4
Pixhawk1-1M _ * * _ * * _ * * *
disco _ * * _ -40 -40 _ -40 -40 -40
f103-GPS * _ _ _ _ _ _ _ _ _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant