From ea3e4cdb92f0ca216d8ccb28f72743738311f3b9 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 30 Jul 2015 11:10:58 +0200 Subject: [PATCH] [module] geo_mag: cleanup and add setting to recalc on demand --- conf/modules/geo_mag.xml | 28 +++++++++++++++------------ sw/airborne/modules/geo_mag/geo_mag.c | 10 ++++------ sw/airborne/modules/geo_mag/geo_mag.h | 1 + 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/conf/modules/geo_mag.xml b/conf/modules/geo_mag.xml index 78b2ddca93..cbd288642e 100644 --- a/conf/modules/geo_mag.xml +++ b/conf/modules/geo_mag.xml @@ -4,30 +4,34 @@ GeoMagnetic field vector. - Calculation of the normalized geomagnetic field vector (saved to ahrs_impl.mag_h) at startup as soon as a valid location is aquired. - Method uses is based on the the ngdc noaa DODWMM model and data (http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml). - To obtain the a magnetic heading to be used by the autopilot, the program must know the magnetic declination at all the points en route, at the indicated flight altitude. - It's very important to keep declination into account because a flight in some geographical areas without considering declination, could lead to unacceptable autopilot navigation errors. - The magnetic declination, that is the difference between true heading and magnetic heading, varies in time and space according to undefined rules, whose long-term progress can be considered substantially random. - To determine the magnetic declination for a point through mathematical calculations is thus indispensable to resort to a model, which represents the progress of the earth magnetic field all over the surface of the globe. The WMM is based on earth magnetic field - measuring at an high number of sites on the whole globe and on its mathematical representation through a series of characteristic values listed in a file (WMM.COF) which has a five-year validity. The autopilot used data derived from this file to make the complex - calculation of declination. Every 5 years (2015, 2020) an updated geomagnetic model is released and datatables in the code must be updated accordingly for more accurate flight. + Calculation of the normalized geomagnetic field vector at startup as soon as a valid location is aquired. + The result is published via the GEO_MAG ABI message. + The AHRS algorithms need to know the magnetic field vector at the current position in order to accurately calculate the heading. + + Method uses is based on the the ngdc noaa DODWMM model and data (http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml). + The WMM is based on earth magnetic field measuring at an high number of sites on the whole globe and on its mathematical representation through a series of characteristic values listed in a file (WMM.COF) which has a five-year validity. + The autopilot used data derived from this file to make the complex calculation of declination. + Every 5 years (2015, 2020) an updated geomagnetic model is released and datatables in the code must be updated accordingly for more accurate flight. + + + + + + +
- + - - - diff --git a/sw/airborne/modules/geo_mag/geo_mag.c b/sw/airborne/modules/geo_mag/geo_mag.c index c1ef8b53c2..0d20eab8c6 100644 --- a/sw/airborne/modules/geo_mag/geo_mag.c +++ b/sw/airborne/modules/geo_mag/geo_mag.c @@ -40,12 +40,11 @@ #define GEO_MAG_SENDER_ID 1 #endif -bool_t geo_mag_calc_flag; struct GeoMag geo_mag; void geo_mag_init(void) { - geo_mag_calc_flag = FALSE; + geo_mag.calc_once = FALSE; geo_mag.ready = FALSE; } @@ -53,14 +52,13 @@ void geo_mag_periodic(void) { //FIXME: kill_throttle has no place in a geomag module if (!geo_mag.ready && gps.fix == GPS_FIX_3D && kill_throttle) { - geo_mag_calc_flag = TRUE; + geo_mag.calc_once = TRUE; } } void geo_mag_event(void) { - - if (geo_mag_calc_flag) { + if (geo_mag.calc_once) { double gha[MAXCOEFF]; // Geomag global variables int32_t nmax; @@ -90,5 +88,5 @@ void geo_mag_event(void) geo_mag.ready = TRUE; } - geo_mag_calc_flag = FALSE; + geo_mag.calc_once = FALSE; } diff --git a/sw/airborne/modules/geo_mag/geo_mag.h b/sw/airborne/modules/geo_mag/geo_mag.h index 0c3a7d36ad..bc3ca49145 100644 --- a/sw/airborne/modules/geo_mag/geo_mag.h +++ b/sw/airborne/modules/geo_mag/geo_mag.h @@ -34,6 +34,7 @@ struct GeoMag { struct DoubleVect3 vect; + bool_t calc_once; bool_t ready; };