Rev 685 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 685 | Rev 743 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include "91x_lib.h" |
56 | #include "91x_lib.h" |
57 | #include "compass.h" |
57 | #include "compass.h" |
58 | #include "mk3mag.h" |
58 | #include "mk3mag.h" |
59 | #include "ncmag.h" |
59 | #include "ncmag.h" |
60 | #include "spi_slave.h" |
60 | #include "spi_slave.h" |
61 | #include "mymath.h" |
61 | #include "mymath.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "fifo.h" |
63 | #include "fifo.h" |
64 | #include "led.h" |
64 | #include "led.h" |
65 | #include "main.h" |
65 | #include "main.h" |
66 | 66 | ||
67 | u8 CompassCalStateQueue[10]; |
67 | u8 CompassCalStateQueue[10]; |
68 | fifo_t CompassCalcStateFiFo; |
68 | fifo_t CompassCalcStateFiFo; |
69 | 69 | ||
70 | volatile s16vec_t MagVector; // is written by mk3mag or ncmag implementation |
70 | volatile s16vec_t MagVector; // is written by mk3mag or ncmag implementation |
71 | volatile s16vec_t AccVector; // current acceleration vector of compass, not supported by any HW version |
71 | volatile s16vec_t AccVector; // current acceleration vector of compass, not supported by any HW version |
72 | volatile s16vec_t MagVectorHorizontal; // vector componenents in horizontal projection |
72 | volatile s16vec_t MagVectorHorizontal; // vector componenents in horizontal projection |
73 | volatile s16 Compass_Heading; // is written by mk3mag or ncmag implementation |
73 | volatile s16 Compass_Heading; // is written by mk3mag or ncmag implementation |
74 | volatile u8 Compass_CalState; // is written by mk3mag or ncmag implementation |
74 | volatile u8 Compass_CalState; // is written by mk3mag or ncmag implementation |
75 | 75 | ||
76 | s32 EarthMagneticField = 100; |
76 | s32 EarthMagneticField = 100; |
77 | s32 EarthMagneticFieldFiltered = 100; |
77 | s32 EarthMagneticFieldFiltered = 100; |
78 | s32 EarthMagneticInclination = 0; |
78 | s32 EarthMagneticInclination = 0; |
79 | s32 EarthMagneticInclinationFiltered = 0; |
79 | s32 EarthMagneticInclinationFiltered = 0; |
80 | s32 EarthMagneticInclinationTheoretic = 0; |
80 | s32 EarthMagneticInclinationTheoretic = 0; |
81 | u8 ErrorDisturbedEarthMagnetField = 0; |
81 | u8 ErrorDisturbedEarthMagnetField = 0; |
82 | s16 EarthMagneticStrengthTheoretic = 0; // in mT (50 in Germany - 22 in Brazil) |
82 | s16 EarthMagneticStrengthTheoretic = 0; // in mT (50 in Germany - 22 in Brazil) |
83 | u32 CompassValueErrorCount = 0; |
83 | u32 CompassValueErrorCount = 0; |
84 | 84 | ||
85 | #define COMPASS_NONE 0 |
85 | #define COMPASS_NONE 0 |
86 | #define COMPASS_MK3MAG 1 |
86 | #define COMPASS_MK3MAG 1 |
87 | #define COMPASS_NCMAG 2 |
87 | #define COMPASS_NCMAG 2 |
88 | u8 Compass_Device = COMPASS_NONE; |
88 | u8 Compass_Device = COMPASS_NONE; |
89 | I2C_TypeDef* Compass_I2CPort = I2C1; |
89 | I2C_TypeDef* Compass_I2CPort = I2C1; |
90 | 90 | ||
91 | void Compass_Init(void) |
91 | void Compass_Init(void) |
92 | { |
92 | { |
93 | if(UART_VersionInfo.HWMajor >= 30) NCMAG_Compass_use_Orientation = 1; else NCMAG_Compass_use_Orientation = 0; |
- | |
94 | - | ||
95 | switch(Compass_Device) |
93 | switch(Compass_Device) |
96 | { |
94 | { |
97 | case COMPASS_NONE: |
95 | case COMPASS_NONE: |
98 | UART1_PutString("\r\n Looking for compass"); |
96 | UART1_PutString("\r\n Looking for compass"); |
99 | if(UART_VersionInfo.HWMajor >= 20) |
97 | if(UART_VersionInfo.HWMajor > 20) |
100 | { |
98 | { |
101 | if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
99 | if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
102 | } |
100 | } |
103 | else |
101 | else |
104 | { |
102 | { |
105 | if( MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG; |
103 | if( MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG; |
106 | else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
104 | else if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
107 | } |
105 | } |
108 | break; |
106 | break; |
109 | 107 | ||
110 | case COMPASS_NCMAG: |
108 | case COMPASS_NCMAG: |
111 | if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
109 | if( NCMAG_Init() ) Compass_Device = COMPASS_NCMAG; |
112 | else Compass_Device = COMPASS_NONE; |
110 | else Compass_Device = COMPASS_NONE; |
113 | break; |
111 | break; |
114 | 112 | ||
115 | case COMPASS_MK3MAG: |
113 | case COMPASS_MK3MAG: |
116 | if( MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG; |
114 | if( MK3MAG_Init() ) Compass_Device = COMPASS_MK3MAG; |
117 | else Compass_Device = COMPASS_NONE; |
115 | else Compass_Device = COMPASS_NONE; |
118 | break; |
116 | break; |
119 | 117 | ||
120 | default: |
118 | default: |
121 | // nothing to do |
119 | // nothing to do |
122 | break; |
120 | break; |
123 | 121 | ||
124 | } |
122 | } |
125 | fifo_init(&CompassCalcStateFiFo, CompassCalStateQueue, sizeof(CompassCalStateQueue), NO_ITLine, NO_ITLine); |
123 | fifo_init(&CompassCalcStateFiFo, CompassCalStateQueue, sizeof(CompassCalStateQueue), NO_ITLine, NO_ITLine); |
126 | 124 | ||
127 | if(Compass_Device == COMPASS_MK3MAG) UART_VersionInfo.Flags |= NC_VERSION_FLAG_MK3MAG_PRESENT; else UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_MK3MAG_PRESENT; |
125 | if(Compass_Device == COMPASS_MK3MAG) UART_VersionInfo.Flags |= NC_VERSION_FLAG_MK3MAG_PRESENT; else UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_MK3MAG_PRESENT; |
128 | 126 | ||
129 | MagVector.X = 0; |
127 | MagVector.X = 0; |
130 | MagVector.Y = 0; |
128 | MagVector.Y = 0; |
131 | MagVector.Z = 0; |
129 | MagVector.Z = 0; |
132 | Compass_Heading = -1; |
130 | Compass_Heading = -1; |
133 | } |
131 | } |
134 | 132 | ||
135 | 133 | ||
136 | void Compass_Check(void) |
134 | void Compass_Check(void) |
137 | { |
135 | { |
138 | switch(Compass_Device) |
136 | switch(Compass_Device) |
139 | { |
137 | { |
140 | case COMPASS_NCMAG: |
138 | case COMPASS_NCMAG: |
141 | NCMAG_CheckOrientation(); |
139 | NCMAG_CheckOrientation(); |
142 | break; |
140 | break; |
143 | 141 | ||
144 | case COMPASS_MK3MAG: |
142 | case COMPASS_MK3MAG: |
145 | case COMPASS_NONE: |
143 | case COMPASS_NONE: |
146 | default: |
144 | default: |
147 | // nothing to do |
145 | // nothing to do |
148 | break; |
146 | break; |
149 | } |
147 | } |
150 | } |
148 | } |
151 | 149 | ||
152 | void Compass_CalcHeading(void) |
150 | void Compass_CalcHeading(void) |
153 | { |
151 | { |
154 | if((UART_VersionInfo.HardwareError[0] & NC_ERROR0_SPI_RX) || Compass_CalState) |
152 | if((UART_VersionInfo.HardwareError[0] & NC_ERROR0_SPI_RX) || Compass_CalState) |
155 | { |
153 | { |
156 | Compass_Heading = -1; |
154 | Compass_Heading = -1; |
157 | } |
155 | } |
158 | else // fc attitude is avialable and no compass calibration active |
156 | else // fc attitude is avialable and no compass calibration active |
159 | { |
157 | { |
160 | // calculate attitude correction |
158 | // calculate attitude correction |
161 | s16 tmp; |
159 | s16 tmp; |
162 | s32 sinnick, cosnick, sinroll, cosroll; |
160 | s32 sinnick, cosnick, sinroll, cosroll; |
163 | tmp = FromFlightCtrl.AngleNick/10; // in deg |
161 | tmp = FromFlightCtrl.AngleNick/10; // in deg |
164 | sinnick = (s32)c_sin_8192(tmp); |
162 | sinnick = (s32)c_sin_8192(tmp); |
165 | cosnick = (s32)c_cos_8192(tmp); |
163 | cosnick = (s32)c_cos_8192(tmp); |
166 | tmp = FromFlightCtrl.AngleRoll/10; // in deg |
164 | tmp = FromFlightCtrl.AngleRoll/10; // in deg |
167 | sinroll = (s32)c_sin_8192(tmp); |
165 | sinroll = (s32)c_sin_8192(tmp); |
168 | cosroll = (s32)c_cos_8192(tmp); |
166 | cosroll = (s32)c_cos_8192(tmp); |
169 | MagVectorHorizontal.X = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L); |
167 | MagVectorHorizontal.X = (s16)((MagVector.Y * cosnick + MagVector.Z * sinnick)/8192L); |
170 | MagVectorHorizontal.Y = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L); |
168 | MagVectorHorizontal.Y = (s16)((MagVector.X * cosroll - MagVector.Z * sinroll)/8192L); |
171 | // calculate heading |
169 | // calculate heading |
172 | tmp = (s16)(c_atan2_546(MagVectorHorizontal.Y, MagVectorHorizontal.X)/546L); |
170 | tmp = (s16)(c_atan2_546(MagVectorHorizontal.Y, MagVectorHorizontal.X)/546L); |
173 | if (tmp > 0) tmp = 360 - tmp; |
171 | if (tmp > 0) tmp = 360 - tmp; |
174 | else tmp = -tmp; |
172 | else tmp = -tmp; |
175 | Compass_Heading = tmp; |
173 | Compass_Heading = tmp; |
176 | } |
174 | } |
177 | } |
175 | } |
178 | 176 | ||
179 | 177 | ||
180 | void Compass_Update(void) |
178 | void Compass_Update(void) |
181 | { |
179 | { |
182 | static s16vec_t old; |
180 | static s16vec_t old; |
183 | static u32 check_value_counter = 0; |
181 | static u32 check_value_counter = 0; |
184 | // check for new cal state |
182 | // check for new cal state |
185 | Compass_UpdateCalState(); |
183 | Compass_UpdateCalState(); |
186 | if(Compass_CalState) FC_is_Calibrated = 0; |
184 | if(Compass_CalState) FC_is_Calibrated = 0; |
187 | // initiate new compass communication |
185 | // initiate new compass communication |
188 | switch(Compass_Device) |
186 | switch(Compass_Device) |
189 | { |
187 | { |
190 | case COMPASS_MK3MAG: |
188 | case COMPASS_MK3MAG: |
191 | MK3MAG_Update(); |
189 | MK3MAG_Update(); |
192 | break; |
190 | break; |
193 | case COMPASS_NCMAG: |
191 | case COMPASS_NCMAG: |
194 | NCMAG_Update(0); |
192 | NCMAG_Update(0); |
195 | break; |
193 | break; |
196 | default: |
194 | default: |
197 | break; |
195 | break; |
198 | } |
196 | } |
199 | 197 | ||
200 | DebugOut.Analog[24] = MagVector.X; |
198 | DebugOut.Analog[24] = MagVector.X; |
201 | DebugOut.Analog[25] = MagVector.Y; |
199 | DebugOut.Analog[25] = MagVector.Y; |
202 | DebugOut.Analog[26] = MagVector.Z; |
200 | DebugOut.Analog[26] = MagVector.Z; |
203 | 201 | ||
204 | if(!((old.X == MagVector.X) || (old.Y == MagVector.Y) || (old.Z == MagVector.Z))) check_value_counter = 0; // Values are normaly changing |
202 | if(!((old.X == MagVector.X) || (old.Y == MagVector.Y) || (old.Z == MagVector.Z))) check_value_counter = 0; // Values are normaly changing |
205 | 203 | ||
206 | if(check_value_counter == 2000) // 2 seconds no change of the compass values |
204 | if(check_value_counter == 2000) // 2 seconds no change of the compass values |
207 | { |
205 | { |
208 | UART1_PutString("\n\r Init Mag.-Sensor"); |
206 | UART1_PutString("\n\r Init Mag.-Sensor"); |
209 | Compass_Init(); |
207 | Compass_Init(); |
210 | } |
208 | } |
211 | 209 | ||
212 | if(check_value_counter > 5000) // 5 seconds no change of the compass values |
210 | if(check_value_counter > 5000) // 5 seconds no change of the compass values |
213 | { |
211 | { |
214 | Compass_Heading = -1; // -> probably a compass-fault |
212 | Compass_Heading = -1; // -> probably a compass-fault |
215 | } |
213 | } |
216 | else check_value_counter++; |
214 | else check_value_counter++; |
217 | 215 | ||
218 | old.X = MagVector.X; |
216 | old.X = MagVector.X; |
219 | old.Y = MagVector.Y; |
217 | old.Y = MagVector.Y; |
220 | old.Z = MagVector.Z; |
218 | old.Z = MagVector.Z; |
221 | } |
219 | } |
222 | 220 | ||
223 | // put cal state into fifo |
221 | // put cal state into fifo |
224 | void Compass_SetCalState(u8 CalState) |
222 | void Compass_SetCalState(u8 CalState) |
225 | { |
223 | { |
226 | fifo_put(&CompassCalcStateFiFo, CalState); |
224 | fifo_put(&CompassCalcStateFiFo, CalState); |
227 | } |
225 | } |
228 | 226 | ||
229 | // get cal state from fifo |
227 | // get cal state from fifo |
230 | void Compass_UpdateCalState() |
228 | void Compass_UpdateCalState() |
231 | { |
229 | { |
232 | fifo_get(&CompassCalcStateFiFo, (u8*)&Compass_CalState); |
230 | fifo_get(&CompassCalcStateFiFo, (u8*)&Compass_CalState); |
233 | } |
231 | } |
234 | 232 | ||
235 | 233 |