Skip to content

AP_Mount: fix lat/lon precision loss in Xacti - #34925

Merged
peterbarker merged 1 commit into
ArduPilot:masterfrom
tatsuy:pr-fix-xacti-float32
Oct 29, 2026
Merged

peterbarker merged 1 commit into
ArduPilot:masterfrom
tatsuy:pr-fix-xacti-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 Xacti cameras in the GnssStatus DroneCAN message.

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

Took several photos at the same spot while the GPS position was jittering slightly:

  • Before: the EXIF longitude was identical in every photo
  • After: the EXIF longitude differs between photos

Description

com.xacti.GnssStatus defines latitude and longitude as float64, but they were calculated as loc.lat * 1e-7.
This rounds the longitude to steps of about 1.5e-5° (~1.4 m).
This PR casts to double before dividing, so the full precision of the int32 location is kept.

xacti_gnss_status_msg.utc_seconds = sec;
xacti_gnss_status_msg.latitude = loc.lat * 1e-7;
xacti_gnss_status_msg.longitude = loc.lng * 1e-7;
xacti_gnss_status_msg.latitude = (double)loc.lat / 1.0e7;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks very much for this. I guess the fix is the cast to double?

It's fine but I guess we could stick with the, "* 1e-7" part instead of changing to a divide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1e-7 is treated as a float (due to -fsingle-precision-constant) and becomes 1.0000000117e-7.
I built and tested each value using Claude and compared the results.

Expression Longitude example (expected 139.7671250) Issue
loc.lng * 1e-7 139.767135620 Rounded to steps of about 1.4 m
(double)loc.lng * 1e-7 139.767126633 The steps are gone, but there is always an offset of about 0.15 m to the east
(double)loc.lng / 1.0e7 139.767125000 No error

@github-actions

Copy link
Copy Markdown

Global Size Summary (Total Flash delta in bytes)

Built from 415e61c rebased onto 7246115

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

@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: ACCEPT

Reviewed at head 415e61c584.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/ardupilot/34925/1.html#pr34925

This two-line fix looks good to merge: dividing the int32 coordinates by 1.0e7 in double precision gives the Xacti float64 lat/lon fields full 1e-7 deg precision, where the old float multiply lost up to about 1.8 m. The author's reply to the cast-only suggestion checks out too, since keeping * 1e-7 leaves a small fixed bias because the constant is still a float.

Note

  • libraries/AP_DDS/AP_DDS_Client.cpp:705 (outside this PR): the DDS goal topic has the same lat * 1e-7 float conversion into GeoPoint doubles. A follow-up PR could use the same (double)x / 1.0e7 form. This does not block this PR.

Not fully reviewed: behaviour on a real Xacti camera or DroneCAN bus, and builds for single-precision-FPU boards, were not exercised.

@peterbarker peterbarker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

This is only one of many, many places that would require the same fix.

-fsingle-precision-constant is a mistake IMO. Not when we introduced it, but now with new tooling and whatnot I think we can do better.

@peterbarker
peterbarker merged commit 278a68a into ArduPilot:master Oct 29, 2026
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Pending

Development

Successfully merging this pull request may close these issues.

5 participants