Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1180 | killagreg | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + Nur für den privaten Gebrauch |
||
4 | // + www.MikroKopter.com |
||
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
11 | // + Verkauf von Luftbildaufnahmen, usw. |
||
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
17 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
18 | // + eindeutig als Ursprung verlinkt werden |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
21 | // + Benutzung auf eigene Gefahr |
||
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
25 | // + mit unserer Zustimmung zulässig |
||
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
30 | // + this list of conditions and the following disclaimer. |
||
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
32 | // + from this software without specific prior written permission. |
||
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
||
34 | // + for non-commercial use (directly or indirectly) |
||
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
36 | // + with our written permission |
||
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
38 | // + clearly linked as origin |
||
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
||
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
48 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
49 | // + POSSIBILITY OF SUCH DAMAGE. |
||
50 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
886 | killagreg | 51 | #include <inttypes.h> |
52 | #include <stdlib.h> |
||
53 | #include "fc.h" |
||
54 | #include "ubx.h" |
||
55 | #include "mymath.h" |
||
56 | #include "timer0.h" |
||
1180 | killagreg | 57 | #include "uart0.h" |
886 | killagreg | 58 | #include "rc.h" |
59 | #include "eeprom.h" |
||
60 | |||
936 | killagreg | 61 | typedef enum |
62 | { |
||
63 | GPS_FLIGHT_MODE_UNDEF, |
||
64 | GPS_FLIGHT_MODE_FREE, |
||
65 | GPS_FLIGHT_MODE_AID, |
||
66 | GPS_FLIGHT_MODE_HOME, |
||
67 | } FlightMode_t; |
||
886 | killagreg | 68 | |
949 | killagreg | 69 | #define GPS_POSINTEGRAL_LIMIT 32000 |
70 | #define GPS_STICK_LIMIT 45 // limit of gps stick control to avoid critical flight attitudes |
||
71 | #define GPS_P_LIMIT 25 |
||
886 | killagreg | 72 | |
73 | |||
74 | typedef struct |
||
75 | { |
||
76 | int32_t Longitude; |
||
77 | int32_t Latitude; |
||
78 | int32_t Altitude; |
||
936 | killagreg | 79 | Status_t Status; |
886 | killagreg | 80 | } GPS_Pos_t; |
81 | |||
82 | // GPS coordinates for hold position |
||
83 | GPS_Pos_t HoldPosition = {0,0,0,INVALID}; |
||
84 | // GPS coordinates for home position |
||
85 | GPS_Pos_t HomePosition = {0,0,0,INVALID}; |
||
936 | killagreg | 86 | // the current flight mode |
87 | FlightMode_t FlightMode = GPS_FLIGHT_MODE_UNDEF; |
||
886 | killagreg | 88 | |
89 | |||
90 | // --------------------------------------------------------------------------------- |
||
936 | killagreg | 91 | void GPS_UpdateParameter(void) |
886 | killagreg | 92 | { |
936 | killagreg | 93 | static FlightMode_t FlightModeOld = GPS_FLIGHT_MODE_UNDEF; |
886 | killagreg | 94 | |
936 | killagreg | 95 | if((RC_Quality < 100) || (MKFlags & MKFLAG_EMERGENCY_LANDING)) |
886 | killagreg | 96 | { |
936 | killagreg | 97 | FlightMode = GPS_FLIGHT_MODE_FREE; |
886 | killagreg | 98 | } |
99 | else |
||
100 | { |
||
936 | killagreg | 101 | if (FCParam.NaviGpsModeControl < 50) FlightMode = GPS_FLIGHT_MODE_AID; |
102 | else if(FCParam.NaviGpsModeControl < 180) FlightMode = GPS_FLIGHT_MODE_FREE; |
||
103 | else FlightMode = GPS_FLIGHT_MODE_HOME; |
||
886 | killagreg | 104 | } |
936 | killagreg | 105 | if (FlightMode != FlightModeOld) |
106 | { |
||
107 | BeepTime = 100; |
||
108 | } |
||
109 | FlightModeOld = FlightMode; |
||
886 | killagreg | 110 | } |
111 | |||
936 | killagreg | 112 | |
113 | |||
114 | // --------------------------------------------------------------------------------- |
||
115 | // This function defines a good GPS signal condition |
||
116 | uint8_t GPS_IsSignalOK(void) |
||
886 | killagreg | 117 | { |
936 | killagreg | 118 | static uint8_t GPSFix = 0; |
119 | if( (GPSInfo.status != INVALID) && (GPSInfo.satfix == SATFIX_3D) && (GPSInfo.flags & FLAG_GPSFIXOK) && ((GPSInfo.satnum >= ParamSet.NaviGpsMinSat) || GPSFix)) |
||
886 | killagreg | 120 | { |
936 | killagreg | 121 | GPSFix = 1; |
122 | return(1); |
||
123 | |||
886 | killagreg | 124 | } |
936 | killagreg | 125 | else return (0); |
126 | |||
127 | } |
||
128 | // --------------------------------------------------------------------------------- |
||
129 | // rescale xy-vector length to limit |
||
130 | uint8_t GPS_LimitXY(int32_t *x, int32_t *y, int32_t limit) |
||
131 | { |
||
132 | uint8_t retval = 0; |
||
133 | int32_t len; |
||
134 | len = (int32_t)c_sqrt(*x * *x + *y * *y); |
||
135 | if (len > limit) |
||
886 | killagreg | 136 | { |
936 | killagreg | 137 | // normalize control vector components to the limit |
138 | *x = (*x * limit) / len; |
||
139 | *y = (*y * limit) / len; |
||
140 | retval = 1; |
||
886 | killagreg | 141 | } |
936 | killagreg | 142 | return(retval); |
886 | killagreg | 143 | } |
144 | |||
936 | killagreg | 145 | // checks nick and roll sticks for manual control |
146 | uint8_t GPS_IsManualControlled(void) |
||
886 | killagreg | 147 | { |
936 | killagreg | 148 | if ( (abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) < ParamSet.NaviStickThreshold) && (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < ParamSet.NaviStickThreshold)) return 0; |
149 | else return 1; |
||
886 | killagreg | 150 | } |
151 | |||
936 | killagreg | 152 | // set given position to current gps position |
153 | uint8_t GPS_SetCurrPosition(GPS_Pos_t * pGPSPos) |
||
154 | { |
||
155 | uint8_t retval = 0; |
||
156 | if(pGPSPos == NULL) return(retval); // bad pointer |
||
157 | |||
158 | if(GPS_IsSignalOK()) |
||
159 | { // is GPS signal condition is fine |
||
160 | pGPSPos->Longitude = GPSInfo.longitude; |
||
161 | pGPSPos->Latitude = GPSInfo.latitude; |
||
162 | pGPSPos->Altitude = GPSInfo.altitude; |
||
163 | pGPSPos->Status = NEWDATA; |
||
164 | retval = 1; |
||
165 | } |
||
166 | else |
||
167 | { // bad GPS signal condition |
||
168 | pGPSPos->Status = INVALID; |
||
169 | retval = 0; |
||
170 | } |
||
171 | return(retval); |
||
172 | } |
||
173 | |||
174 | // clear position |
||
175 | uint8_t GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
||
176 | { |
||
177 | uint8_t retval = 0; |
||
178 | if(pGPSPos == NULL) return(retval); // bad pointer |
||
179 | else |
||
180 | { |
||
181 | pGPSPos->Longitude = 0; |
||
182 | pGPSPos->Latitude = 0; |
||
183 | pGPSPos->Altitude = 0; |
||
184 | pGPSPos->Status = INVALID; |
||
185 | retval = 1; |
||
186 | } |
||
187 | return (retval); |
||
188 | } |
||
189 | |||
886 | killagreg | 190 | // disable GPS control sticks |
191 | void GPS_Neutral(void) |
||
192 | { |
||
1180 | killagreg | 193 | GPSStickNick = 0; |
194 | GPSStickRoll = 0; |
||
886 | killagreg | 195 | } |
196 | |||
197 | // calculates the GPS control stick values from the deviation to target position |
||
198 | // if the pointer to the target positin is NULL or is the target position invalid |
||
199 | // then the P part of the controller is deactivated. |
||
200 | void GPS_PIDController(GPS_Pos_t *pTargetPos) |
||
201 | { |
||
938 | killagreg | 202 | static int32_t PID_Nick, PID_Roll; |
886 | killagreg | 203 | int32_t coscompass, sincompass; |
204 | int32_t GPSPosDev_North, GPSPosDev_East; // Position deviation in cm |
||
205 | int32_t P_North = 0, D_North = 0, P_East = 0, D_East = 0, I_North = 0, I_East = 0; |
||
206 | int32_t PID_North = 0, PID_East = 0; |
||
207 | static int32_t cos_target_latitude = 1; |
||
208 | static int32_t GPSPosDevIntegral_North = 0, GPSPosDevIntegral_East = 0; |
||
209 | static GPS_Pos_t *pLastTargetPos = 0; |
||
210 | |||
211 | // if GPS data and Compass are ok |
||
936 | killagreg | 212 | if( GPS_IsSignalOK() && (CompassHeading >= 0) ) |
886 | killagreg | 213 | { |
214 | |||
215 | if(pTargetPos != NULL) // if there is a target position |
||
216 | { |
||
217 | if(pTargetPos->Status != INVALID) // and the position data are valid |
||
218 | { |
||
219 | // if the target data are updated or the target pointer has changed |
||
220 | if ((pTargetPos->Status != PROCESSED) || (pTargetPos != pLastTargetPos) ) |
||
221 | { |
||
222 | // reset error integral |
||
223 | GPSPosDevIntegral_North = 0; |
||
224 | GPSPosDevIntegral_East = 0; |
||
225 | // recalculate latitude projection |
||
226 | cos_target_latitude = (int32_t)c_cos_8192((int16_t)(pTargetPos->Latitude/10000000L)); |
||
227 | // remember last target pointer |
||
228 | pLastTargetPos = pTargetPos; |
||
229 | // mark data as processed |
||
230 | pTargetPos->Status = PROCESSED; |
||
231 | } |
||
232 | // calculate position deviation from latitude and longitude differences |
||
233 | GPSPosDev_North = (GPSInfo.latitude - pTargetPos->Latitude); // to calculate real cm we would need *111/100 additionally |
||
234 | GPSPosDev_East = (GPSInfo.longitude - pTargetPos->Longitude); // to calculate real cm we would need *111/100 additionally |
||
235 | // calculate latitude projection |
||
236 | GPSPosDev_East *= cos_target_latitude; |
||
237 | GPSPosDev_East /= 8192; |
||
238 | } |
||
239 | else // no valid target position available |
||
240 | { |
||
241 | // reset error |
||
242 | GPSPosDev_North = 0; |
||
243 | GPSPosDev_East = 0; |
||
244 | // reset error integral |
||
245 | GPSPosDevIntegral_North = 0; |
||
246 | GPSPosDevIntegral_East = 0; |
||
247 | } |
||
248 | } |
||
249 | else // no target position available |
||
250 | { |
||
251 | // reset error |
||
252 | GPSPosDev_North = 0; |
||
253 | GPSPosDev_East = 0; |
||
254 | // reset error integral |
||
255 | GPSPosDevIntegral_North = 0; |
||
256 | GPSPosDevIntegral_East = 0; |
||
257 | } |
||
258 | |||
938 | killagreg | 259 | //Calculate PID-components of the controller |
886 | killagreg | 260 | |
939 | killagreg | 261 | // D-Part |
949 | killagreg | 262 | D_North = ((int32_t)FCParam.NaviGpsD * GPSInfo.velnorth)/512; |
263 | D_East = ((int32_t)FCParam.NaviGpsD * GPSInfo.veleast)/512; |
||
939 | killagreg | 264 | |
886 | killagreg | 265 | // P-Part |
949 | killagreg | 266 | P_North = ((int32_t)FCParam.NaviGpsP * GPSPosDev_North)/2048; |
267 | P_East = ((int32_t)FCParam.NaviGpsP * GPSPosDev_East)/2048; |
||
886 | killagreg | 268 | |
269 | // I-Part |
||
939 | killagreg | 270 | I_North = ((int32_t)FCParam.NaviGpsI * GPSPosDevIntegral_North)/8192; |
271 | I_East = ((int32_t)FCParam.NaviGpsI * GPSPosDevIntegral_East)/8192; |
||
886 | killagreg | 272 | |
273 | |||
949 | killagreg | 274 | // combine P & I |
275 | PID_North = P_North + I_North; |
||
276 | PID_East = P_East + I_East; |
||
277 | if(!GPS_LimitXY(&PID_North, &PID_East, GPS_P_LIMIT)) |
||
278 | { |
||
279 | GPSPosDevIntegral_North += GPSPosDev_North/16; |
||
280 | GPSPosDevIntegral_East += GPSPosDev_East/16; |
||
1238 | killagreg | 281 | GPS_LimitXY(&GPSPosDevIntegral_North, &GPSPosDevIntegral_East, GPS_POSINTEGRAL_LIMIT); |
949 | killagreg | 282 | } |
283 | |||
284 | // combine PI- and D-Part |
||
285 | PID_North += D_North; |
||
286 | PID_East += D_East; |
||
287 | |||
288 | |||
936 | killagreg | 289 | // scale combination with gain. |
937 | killagreg | 290 | PID_North = (PID_North * (int32_t)FCParam.NaviGpsGain) / 100; |
291 | PID_East = (PID_East * (int32_t)FCParam.NaviGpsGain) / 100; |
||
936 | killagreg | 292 | |
911 | killagreg | 293 | // GPS to nick and roll settings |
886 | killagreg | 294 | |
911 | killagreg | 295 | // A positive nick angle moves head downwards (flying forward). |
886 | killagreg | 296 | // A positive roll angle tilts left side downwards (flying left). |
297 | // If compass heading is 0 the head of the copter is in north direction. |
||
911 | killagreg | 298 | // A positive nick angle will fly to north and a positive roll angle will fly to west. |
886 | killagreg | 299 | // In case of a positive north deviation/velocity the |
911 | killagreg | 300 | // copter should fly to south (negative nick). |
886 | killagreg | 301 | // In case of a positive east position deviation and a positive east velocity the |
302 | // copter should fly to west (positive roll). |
||
1180 | killagreg | 303 | // The influence of the GPSStickNick and GPSStickRoll variable is contrarily to the stick values |
886 | killagreg | 304 | // in the fc.c. Therefore a positive north deviation/velocity should result in a positive |
1180 | killagreg | 305 | // GPSStickNick and a positive east deviation/velocity should result in a negative GPSStickRoll. |
886 | killagreg | 306 | |
1186 | killagreg | 307 | coscompass = (int32_t)c_cos_8192(YawGyroHeading / GYRO_DEG_FACTOR); |
308 | sincompass = (int32_t)c_sin_8192(YawGyroHeading / GYRO_DEG_FACTOR); |
||
949 | killagreg | 309 | PID_Nick = (coscompass * PID_North + sincompass * PID_East) / 8192; |
310 | PID_Roll = (sincompass * PID_North - coscompass * PID_East) / 8192; |
||
886 | killagreg | 311 | |
938 | killagreg | 312 | |
886 | killagreg | 313 | // limit resulting GPS control vector |
936 | killagreg | 314 | GPS_LimitXY(&PID_Nick, &PID_Roll, GPS_STICK_LIMIT); |
886 | killagreg | 315 | |
1180 | killagreg | 316 | GPSStickNick = (int16_t)PID_Nick; |
317 | GPSStickRoll = (int16_t)PID_Roll; |
||
886 | killagreg | 318 | } |
319 | else // invalid GPS data or bad compass reading |
||
320 | { |
||
321 | GPS_Neutral(); // do nothing |
||
322 | // reset error integral |
||
323 | GPSPosDevIntegral_North = 0; |
||
324 | GPSPosDevIntegral_East = 0; |
||
325 | } |
||
326 | } |
||
327 | |||
328 | |||
329 | |||
330 | |||
936 | killagreg | 331 | void GPS_Main(void) |
886 | killagreg | 332 | { |
333 | static uint8_t GPS_P_Delay = 0; |
||
938 | killagreg | 334 | static uint16_t beep_rythm = 0; |
886 | killagreg | 335 | |
936 | killagreg | 336 | GPS_UpdateParameter(); |
886 | killagreg | 337 | |
936 | killagreg | 338 | // store home position if start of flight flag is set |
339 | if(MKFlags & MKFLAG_CALIBRATE) |
||
340 | { |
||
938 | killagreg | 341 | if(GPS_SetCurrPosition(&HomePosition)) BeepTime = 700; |
936 | killagreg | 342 | } |
886 | killagreg | 343 | |
344 | switch(GPSInfo.status) |
||
345 | { |
||
346 | case INVALID: // invalid gps data |
||
347 | GPS_Neutral(); |
||
936 | killagreg | 348 | if(FlightMode != GPS_FLIGHT_MODE_FREE) |
886 | killagreg | 349 | { |
350 | BeepTime = 100; // beep if signal is neccesary |
||
351 | } |
||
352 | break; |
||
353 | case PROCESSED: // if gps data are already processed do nothing |
||
354 | // downcount timeout |
||
355 | if(GPSTimeout) GPSTimeout--; |
||
356 | // if no new data arrived within timeout set current data invalid |
||
357 | // and therefore disable GPS |
||
358 | else |
||
359 | { |
||
360 | GPS_Neutral(); |
||
361 | GPSInfo.status = INVALID; |
||
362 | } |
||
363 | break; |
||
936 | killagreg | 364 | case NEWDATA: // new valid data from gps device |
886 | killagreg | 365 | // if the gps data quality is good |
936 | killagreg | 366 | beep_rythm++; |
367 | |||
368 | if (GPS_IsSignalOK()) |
||
886 | killagreg | 369 | { |
936 | killagreg | 370 | switch(FlightMode) // check what's to do |
886 | killagreg | 371 | { |
936 | killagreg | 372 | case GPS_FLIGHT_MODE_FREE: |
886 | killagreg | 373 | // update hold position to current gps position |
936 | killagreg | 374 | GPS_SetCurrPosition(&HoldPosition); // can get invalid if gps signal is bad |
886 | killagreg | 375 | // disable gps control |
376 | GPS_Neutral(); |
||
936 | killagreg | 377 | break; |
378 | |||
379 | case GPS_FLIGHT_MODE_AID: |
||
886 | killagreg | 380 | if(HoldPosition.Status != INVALID) |
381 | { |
||
936 | killagreg | 382 | if( GPS_IsManualControlled() ) // MK controlled by user |
886 | killagreg | 383 | { |
384 | // update hold point to current gps position |
||
936 | killagreg | 385 | GPS_SetCurrPosition(&HoldPosition); |
886 | killagreg | 386 | // disable gps control |
387 | GPS_Neutral(); |
||
388 | GPS_P_Delay = 0; |
||
389 | } |
||
390 | else // GPS control active |
||
391 | { |
||
936 | killagreg | 392 | if(GPS_P_Delay < 7) |
886 | killagreg | 393 | { // delayed activation of P-Part for 8 cycles (8*0.25s = 2s) |
394 | GPS_P_Delay++; |
||
936 | killagreg | 395 | GPS_SetCurrPosition(&HoldPosition); // update hold point to current gps position |
886 | killagreg | 396 | GPS_PIDController(NULL); // activates only the D-Part |
397 | } |
||
398 | else GPS_PIDController(&HoldPosition);// activates the P&D-Part |
||
399 | } |
||
400 | } |
||
401 | else // invalid Hold Position |
||
402 | { // try to catch a valid hold position from gps data input |
||
936 | killagreg | 403 | GPS_SetCurrPosition(&HoldPosition); |
886 | killagreg | 404 | GPS_Neutral(); |
405 | } |
||
936 | killagreg | 406 | break; |
407 | |||
408 | case GPS_FLIGHT_MODE_HOME: |
||
886 | killagreg | 409 | if(HomePosition.Status != INVALID) |
410 | { |
||
411 | // update hold point to current gps position |
||
412 | // to avoid a flight back if home comming is deactivated |
||
936 | killagreg | 413 | GPS_SetCurrPosition(&HoldPosition); |
414 | if( GPS_IsManualControlled() ) // MK controlled by user |
||
886 | killagreg | 415 | { |
416 | GPS_Neutral(); |
||
417 | } |
||
418 | else // GPS control active |
||
419 | { |
||
420 | GPS_PIDController(&HomePosition); |
||
421 | } |
||
422 | } |
||
423 | else // bad home position |
||
424 | { |
||
425 | BeepTime = 50; // signal invalid home position |
||
426 | // try to hold at least the position as a fallback option |
||
427 | |||
428 | if (HoldPosition.Status != INVALID) |
||
429 | { |
||
936 | killagreg | 430 | if( GPS_IsManualControlled() ) // MK controlled by user |
886 | killagreg | 431 | { |
432 | GPS_Neutral(); |
||
433 | } |
||
434 | else // GPS control active |
||
435 | { |
||
436 | GPS_PIDController(&HoldPosition); |
||
437 | } |
||
438 | } |
||
439 | else |
||
440 | { // try to catch a valid hold position |
||
936 | killagreg | 441 | GPS_SetCurrPosition(&HoldPosition); |
886 | killagreg | 442 | GPS_Neutral(); |
443 | } |
||
444 | } |
||
445 | break; // eof TSK_HOME |
||
446 | default: // unhandled task |
||
447 | GPS_Neutral(); |
||
448 | break; // eof default |
||
449 | } // eof switch GPS_Task |
||
936 | killagreg | 450 | } // eof gps data quality is good |
451 | else // gps data quality is bad |
||
886 | killagreg | 452 | { // disable gps control |
453 | GPS_Neutral(); |
||
939 | killagreg | 454 | if(FlightMode != GPS_FLIGHT_MODE_FREE) |
455 | { |
||
456 | // beep if signal is not sufficient |
||
457 | if(!(GPSInfo.flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100; |
||
458 | else if (GPSInfo.satnum < ParamSet.NaviGpsMinSat && !(beep_rythm % 5)) BeepTime = 10; |
||
459 | } |
||
886 | killagreg | 460 | } |
461 | // set current data as processed to avoid further calculations on the same gps data |
||
462 | GPSInfo.status = PROCESSED; |
||
463 | break; |
||
464 | } // eof GPSInfo.status |
||
465 | } |
||
466 |