AP_Common: Location gets named constructor

This commit is contained in:
Randy Mackay
2025-12-17 08:03:10 +09:00
parent d017af7832
commit fa18fa7e4b
2 changed files with 12 additions and 28 deletions
+8 -26
View File
@@ -65,37 +65,19 @@ Location::Location(const Vector3d &ekf_offset_neu_cm, AltFrame frame)
}
}
Location::Location(AltFrame frame, const Vector3f &ekf_offset_ned_m)
// named constructors
Location Location::from_ekf_offset_NED_m(const Vector3f& ekf_offset_ned_m, AltFrame frame)
{
zero();
// store alt and alt frame
set_alt_cm(-ekf_offset_ned_m.z * 100.0, frame);
// calculate lat, lon
Location ekf_origin;
if (AP::ahrs().get_origin(ekf_origin)) {
lat = ekf_origin.lat;
lng = ekf_origin.lng;
offset(ekf_offset_ned_m.x, ekf_offset_ned_m.y);
}
const Vector3f ekf_offset_neu_cm(ekf_offset_ned_m.x * 100.0, ekf_offset_ned_m.y * 100.0, -ekf_offset_ned_m.z * 100.0);
return Location(ekf_offset_neu_cm, frame);
}
Location::Location(AltFrame frame, const Vector3d &ekf_offset_ned_m)
Location Location::from_ekf_offset_NED_m(const Vector3d& ekf_offset_ned_m, AltFrame frame)
{
zero();
// store alt and alt frame
set_alt_cm(-ekf_offset_ned_m.z * 100.0, frame);
// calculate lat, lon
Location ekf_origin;
if (AP::ahrs().get_origin(ekf_origin)) {
lat = ekf_origin.lat;
lng = ekf_origin.lng;
offset(ekf_offset_ned_m.x, ekf_offset_ned_m.y);
}
const Vector3d ekf_offset_neu_cm(ekf_offset_ned_m.x * 100.0, ekf_offset_ned_m.y * 100.0, -ekf_offset_ned_m.z * 100.0);
return Location(ekf_offset_neu_cm, frame);
}
#endif // AP_AHRS_ENABLED
void Location::set_alt_cm(int32_t alt_cm, AltFrame frame)
+4 -2
View File
@@ -32,8 +32,10 @@ public:
Location(int32_t latitude, int32_t longitude, int32_t alt_in_cm, AltFrame frame);
Location(const Vector3f &ekf_offset_neu_cm, AltFrame frame);
Location(const Vector3d &ekf_offset_neu_cm, AltFrame frame);
Location(AltFrame frame, const Vector3f &ekf_offset_ned_m);
Location(AltFrame frame, const Vector3d &ekf_offset_ned_m);
// named constructors
static Location from_ekf_offset_NED_m(const Vector3f& ekf_offset_ned_m, AltFrame frame);
static Location from_ekf_offset_NED_m(const Vector3d& ekf_offset_ned_m, AltFrame frame);
// set altitude
void set_alt_cm(int32_t alt_cm, AltFrame frame);