mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
feat(lat_lon_alt): add latitude-dependent gravity helper
Add LatLonAlt::Wgs84::gravity(), the Somigliana normal-gravity formula returning surface gravity as a function of latitude (~9.780 m/s^2 at the equator to ~9.832 m/s^2 at the poles), plus a unit test against known reference values.
This commit is contained in:
1 parent
7f77f10828
commit
846766d0bc
2 files changed
+27
No files matched your search
@@ -112,6 +112,18 @@ public:
|
||||
static constexpr double eccentricity2 = eccentricity * eccentricity;
|
||||
static constexpr double meridian_radius_of_curvature_numerator = equatorial_radius * (1.0 - eccentricity2);
|
||||
static constexpr double gravity_equator = 9.7803253359;
|
||||
static constexpr double somigliana_coefficient = 0.001931851353;
|
||||
|
||||
// Normal gravity at the ellipsoid surface as a function of latitude (Somigliana formula).
|
||||
// Captures the ~9.780 (equator) to ~9.832 m/s^2 (pole) variation. Input in radians.
|
||||
static float gravity(const double latitude_rad)
|
||||
{
|
||||
const double sin_lat = sin(latitude_rad);
|
||||
const double sin_lat2 = sin_lat * sin_lat;
|
||||
const double g = gravity_equator * (1.0 + somigliana_coefficient * sin_lat2)
|
||||
/ std::sqrt(1.0 - eccentricity2 * sin_lat2);
|
||||
return static_cast<float>(g);
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -119,3 +119,18 @@ TEST(TestLatLonAlt, fromAndToECEF)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestLatLonAlt, somiglianaGravity)
|
||||
{
|
||||
// Somigliana normal-gravity reference values (m/s^2)
|
||||
EXPECT_NEAR(LatLonAlt::Wgs84::gravity(radians(0.0)), 9.7803253359f, 1e-3f); // equator
|
||||
EXPECT_NEAR(LatLonAlt::Wgs84::gravity(radians(45.0)), 9.8061992f, 1e-3f); // mid-latitude
|
||||
EXPECT_NEAR(LatLonAlt::Wgs84::gravity(radians(90.0)), 9.8321849f, 1e-3f); // pole
|
||||
|
||||
// symmetric about the equator, and monotonically increasing towards the pole
|
||||
EXPECT_FLOAT_EQ(LatLonAlt::Wgs84::gravity(radians(-30.0)), LatLonAlt::Wgs84::gravity(radians(30.0)));
|
||||
EXPECT_GT(LatLonAlt::Wgs84::gravity(radians(60.0)), LatLonAlt::Wgs84::gravity(radians(30.0)));
|
||||
|
||||
// stays within the physical envelope and close to the constant used as the pre-global-position default
|
||||
EXPECT_NEAR(LatLonAlt::Wgs84::gravity(radians(48.0)), CONSTANTS_ONE_G, 0.02f);
|
||||
}
|
||||
Reference in new issue
Block a user