2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @brief Include file of the WorldMagModel internal functionality.
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifndef WMMINTERNAL_H_
28 #define WMMINTERNAL_H_
29 #include <pios_math.h>
32 #define TRUE ((uint16_t)1)
33 #define FALSE ((uint16_t)0)
34 #define WMM_MAX_MODEL_DEGREES 12
35 #define WMM_MAX_SECULAR_VARIATION_MODEL_DEGREES 12
36 #define NUMTERMS 91 // ((WMM_MAX_MODEL_DEGREES+1)*(WMM_MAX_MODEL_DEGREES+2)/2);
37 #define NUMPCUP 92 // NUMTERMS +1
38 #define NUMPCUPS 13 // WMM_MAX_MODEL_DEGREES +1
40 // internal structure definitions
43 float epoch
; // Base time of Geomagnetic model epoch (yrs)
45 // float Main_Field_Coeff_G[NUMTERMS]; // C - Gauss coefficients of main geomagnetic model (nT)
46 // float Main_Field_Coeff_H[NUMTERMS]; // C - Gauss coefficients of main geomagnetic model (nT)
47 // float Secular_Var_Coeff_G[NUMTERMS]; // CD - Gauss coefficients of secular geomagnetic model (nT/yr)
48 // float Secular_Var_Coeff_H[NUMTERMS]; // CD - Gauss coefficients of secular geomagnetic model (nT/yr)
49 uint16_t nMax
; // Maximum degree of spherical harmonic model
50 uint16_t nMaxSecVar
; // Maxumum degree of spherical harmonic secular model
51 uint16_t SecularVariationUsed
; // Whether or not the magnetic secular variation vector will be needed by program
52 } WMMtype_MagneticModel
;
55 float a
; // semi-major axis of the ellipsoid
56 float b
; // semi-minor axis of the ellipsoid
57 float fla
; // flattening
58 float epssq
; // first eccentricity squared
59 float eps
; // first eccentricity
60 float re
; // mean radius of ellipsoid
64 float lambda
; // longitude
65 float phi
; // geodetic latitude
66 float HeightAboveEllipsoid
; // height above the ellipsoid (HaE)
67 } WMMtype_CoordGeodetic
;
70 float lambda
; // longitude
71 float phig
; // geocentric latitude
72 float r
; // distance from the center of the ellipsoid
73 } WMMtype_CoordSpherical
;
83 float Pcup
[NUMPCUP
]; // Legendre Function
84 float dPcup
[NUMPCUP
]; // Derivative of Lagendre fn
85 } WMMtype_LegendreFunction
;
91 } WMMtype_MagneticResults
;
94 float RelativeRadiusPower
[WMM_MAX_MODEL_DEGREES
+ 1]; // [earth_reference_radius_km / sph. radius ]^n
95 float cos_mlambda
[WMM_MAX_MODEL_DEGREES
+ 1]; // cp(m) - cosine of (m*spherical coord. longitude
96 float sin_mlambda
[WMM_MAX_MODEL_DEGREES
+ 1]; // sp(m) - sine of (m*spherical coord. longitude)
97 } WMMtype_SphericalHarmonicVariables
;
100 float Decl
; /* 1. Angle between the magnetic field vector and true north, positive east */
101 float Incl
; /*2. Angle between the magnetic field vector and the horizontal plane, positive down */
102 float F
; /*3. Magnetic Field Strength */
103 float H
; /*4. Horizontal Magnetic Field Strength */
104 float X
; /*5. Northern component of the magnetic field vector */
105 float Y
; /*6. Eastern component of the magnetic field vector */
106 float Z
; /*7. Downward component of the magnetic field vector */
107 float GV
; /*8. The Grid Variation */
108 float Decldot
; /*9. Yearly Rate of change in declination */
109 float Incldot
; /*10. Yearly Rate of change in inclination */
110 float Fdot
; /*11. Yearly rate of change in Magnetic field strength */
111 float Hdot
; /*12. Yearly rate of change in horizontal field strength */
112 float Xdot
; /*13. Yearly rate of change in the northern component */
113 float Ydot
; /*14. Yearly rate of change in the eastern component */
114 float Zdot
; /*15. Yearly rate of change in the downward component */
115 float GVdot
; /*16. Yearly rate of chnage in grid variation */
116 } WMMtype_GeoMagneticElements
;
118 // Internal Function Prototypes
119 void WMM_Set_Coeff_Array();
120 int WMM_GeodeticToSpherical(WMMtype_CoordGeodetic
*CoordGeodetic
, WMMtype_CoordSpherical
*CoordSpherical
);
121 int WMM_DateToYear(uint16_t month
, uint16_t day
, uint16_t year
);
122 int WMM_Geomag(WMMtype_CoordSpherical
*CoordSpherical
,
123 WMMtype_CoordGeodetic
*CoordGeodetic
, WMMtype_GeoMagneticElements
*GeoMagneticElements
);
125 int WMM_AssociatedLegendreFunction(WMMtype_CoordSpherical
*CoordSpherical
, uint16_t nMax
, WMMtype_LegendreFunction
*LegendreFunction
);
127 int WMM_CalculateGeoMagneticElements(WMMtype_MagneticResults
*MagneticResultsGeo
, WMMtype_GeoMagneticElements
*GeoMagneticElements
);
129 int WMM_CalculateSecularVariation(WMMtype_MagneticResults
*MagneticVariation
, WMMtype_GeoMagneticElements
*MagneticElements
);
131 int WMM_ComputeSphericalHarmonicVariables(WMMtype_CoordSpherical
*
132 CoordSpherical
, uint16_t nMax
, WMMtype_SphericalHarmonicVariables
*SphVariables
);
134 int WMM_PcupLow(float *Pcup
, float *dPcup
, float x
, uint16_t nMax
);
136 int WMM_PcupHigh(float *Pcup
, float *dPcup
, float x
, uint16_t nMax
);
138 int WMM_RotateMagneticVector(WMMtype_CoordSpherical
*,
139 WMMtype_CoordGeodetic
*CoordGeodetic
,
140 WMMtype_MagneticResults
*MagneticResultsSph
, WMMtype_MagneticResults
*MagneticResultsGeo
);
142 int WMM_SecVarSummation(WMMtype_LegendreFunction
*LegendreFunction
,
143 WMMtype_SphericalHarmonicVariables
*
144 SphVariables
, WMMtype_CoordSpherical
*CoordSpherical
, WMMtype_MagneticResults
*MagneticResults
);
146 int WMM_SecVarSummationSpecial(WMMtype_SphericalHarmonicVariables
*
147 SphVariables
, WMMtype_CoordSpherical
*CoordSpherical
, WMMtype_MagneticResults
*MagneticResults
);
149 int WMM_Summation(WMMtype_LegendreFunction
*LegendreFunction
,
150 WMMtype_SphericalHarmonicVariables
*SphVariables
,
151 WMMtype_CoordSpherical
*CoordSpherical
, WMMtype_MagneticResults
*MagneticResults
);
153 int WMM_SummationSpecial(WMMtype_SphericalHarmonicVariables
*
154 SphVariables
, WMMtype_CoordSpherical
*CoordSpherical
, WMMtype_MagneticResults
*MagneticResults
);
156 float WMM_get_main_field_coeff_g(uint16_t index
);
157 float WMM_get_main_field_coeff_h(uint16_t index
);
158 float WMM_get_secular_var_coeff_g(uint16_t index
);
159 float WMM_get_secular_var_coeff_h(uint16_t index
);
161 #endif /* WMMINTERNAL_H_ */