fix(lat_lon_alt): use fabs() in fromEcef(), std::abs() resolves to int abs() on NuttX (#28333)

PX4 NuttX builds compile with -nostdinc++ and NuttX's own C++ headers,
whose <cstdlib> provides only the C int abs(int) and whose <cmath> has no
floating std::abs overloads. std::abs(p_ecef(2)) therefore binds to
int abs(int) and the ECEF Z coordinate is truncated to whole metres on
every call. LatLonAlt::fromEcef() is what SIH uses to turn its ECEF
position into latitude and longitude each physics step, so on hardware
the groundtruth and simulated GPS latitude advanced at sin^2(lat) of the
true rate and jumped cos(lat) m every 1/cos(lat) m of northing. SITL
links libstdc++ and was never affected. fabs() has only a floating
signature, so the same source compiles correctly on every target.
This commit is contained in:
Mike Pehel authored and GitHub committed 2026-08-21 14:43:22 -06:00
1 parent 6e18edd500
commit 62acf66021
1 file changed
+1 -1
+1 -1
View File
@@ -41,7 +41,7 @@ LatLonAlt LatLonAlt::fromEcef(const Vector3d &p_ecef)
{
// Convert position using Borkowski closed-form exact solution
// P. D. Groves, "Principles of GNSS, inertial, and multisensor integrated navigation systems, 2nd edition (appendix C)
const double k1 = sqrt(1 - Wgs84::eccentricity2) * std::abs(p_ecef(2));
const double k1 = sqrt(1 - Wgs84::eccentricity2) * fabs(p_ecef(2));
const double k2 = Wgs84::eccentricity2 * Wgs84::equatorial_radius;
const double beta = sqrt(p_ecef(0) * p_ecef(0) + p_ecef(1) * p_ecef(1));
const double E = (k1 - k2) / beta;