diff --git a/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp b/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp index 4f1835f4f..62579bddc 100644 --- a/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp +++ b/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp @@ -143,6 +143,29 @@ int CoordinateConversions::GetLLA(double homeLLA[3], double NED[3], double posit return 0; } +/** + * Get the current location in Longitude, Latitude Altitude (above WSG-48 ellipsoid) + * @param[in] BaseECEF the ECEF of the home location (in cm) + * @param[in] position three element double for position in degrees and meters + * @param[out] NED the offset from the home location (in m) + * @returns + * @arg 0 success + * @arg -1 for failure + */ +int CoordinateConversions::GetNED(double homeLLA[3], double position[3], double NED[3]) +{ + double T[3]; + T[0] = homeLLA[2]+6.378137E6f * M_PI / 180.0; + T[1] = cosf(homeLLA[0] * M_PI / 180.0)*(homeLLA[2]+6.378137E6f) * M_PI / 180.0; + T[2] = -1.0f; + + NED[0] = (position[0] - homeLLA[0]) * T[0]; + NED[1] = (position[1] - homeLLA[1]) * T[1]; + NED[2] = (position[2] - homeLLA[2]) * T[2]; + + return 0; +} + void CoordinateConversions::LLA2Base(double LLA[3], double BaseECEF[3], float Rne[3][3], float NED[3]) { double ECEF[3]; diff --git a/ground/openpilotgcs/src/libs/utils/coordinateconversions.h b/ground/openpilotgcs/src/libs/utils/coordinateconversions.h index f6f47a8d7..bc0e7a9c5 100644 --- a/ground/openpilotgcs/src/libs/utils/coordinateconversions.h +++ b/ground/openpilotgcs/src/libs/utils/coordinateconversions.h @@ -42,6 +42,7 @@ class QTCREATOR_UTILS_EXPORT CoordinateConversions public: CoordinateConversions(); int GetLLA(double LLA[3], double NED[3], double position[3]); + int GetNED(double homeLLA[3], double position[3], double NED[3]); void RneFromLLA(double LLA[3], double Rne[3][3]); void LLA2ECEF(double LLA[3], double ECEF[3]); int ECEF2LLA(double ECEF[3], double LLA[3]);