Rev 935 | Rev 937 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 935 | Rev 936 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | #include "timer0.h" |
6 | #include "timer0.h" |
7 | //#include "uart.h" |
7 | //#include "uart.h" |
8 | #include "rc.h" |
8 | #include "rc.h" |
9 | #include "eeprom.h" |
9 | #include "eeprom.h" |
Line -... | Line 10... | ||
- | 10 | ||
- | 11 | typedef enum |
|
- | 12 | { |
|
10 | 13 | GPS_FLIGHT_MODE_UNDEF, |
|
11 | #define TSK_IDLE 0 |
14 | GPS_FLIGHT_MODE_FREE, |
12 | #define TSK_HOLD 1 |
15 | GPS_FLIGHT_MODE_AID, |
- | 16 | GPS_FLIGHT_MODE_HOME, |
|
Line 13... | Line -... | ||
13 | #define TSK_HOME 2 |
- | |
14 | 17 | } FlightMode_t; |
|
15 | #define GPS_STICK_SENSE 15 // must be at least in a range where 90% of the trimming does not switch of the GPS function |
18 | |
16 | #define GPS_STICK_LIMIT 45 // limit of gps stick control to avoid critical flight attitudes |
19 | #define GPS_STICK_LIMIT 200 // limit of gps stick control to avoid critical flight attitudes |
17 | #define GPS_POSDEV_INTEGRAL_LIMIT 32000 // limit for the position error integral |
- | |
18 | #define GPS_P_LIMIT 25 |
- | |
19 | - | ||
20 | - | ||
Line 21... | Line 20... | ||
21 | uint8_t GPS_P_Factor = 0, GPS_I_Factor = 0, GPS_D_Factor = 0; |
20 | #define GPS_POSDEV_INTEGRAL_LIMIT 32000 // limit for the position error integral |
22 | 21 | #define GPS_P_LIMIT 3200 |
|
23 | 22 | ||
24 | 23 | ||
25 | typedef struct |
24 | typedef struct |
26 | { |
25 | { |
27 | int32_t Longitude; |
26 | int32_t Longitude; |
Line 28... | Line 27... | ||
28 | int32_t Latitude; |
27 | int32_t Latitude; |
29 | int32_t Altitude; |
28 | int32_t Altitude; |
30 | uint8_t Status; |
29 | Status_t Status; |
31 | } GPS_Pos_t; |
30 | } GPS_Pos_t; |
- | 31 | ||
- | 32 | // GPS coordinates for hold position |
|
Line 32... | Line 33... | ||
32 | 33 | GPS_Pos_t HoldPosition = {0,0,0,INVALID}; |
|
- | 34 | // GPS coordinates for home position |
|
- | 35 | GPS_Pos_t HomePosition = {0,0,0,INVALID}; |
|
- | 36 | // the current flight mode |
|
Line 33... | Line 37... | ||
33 | // GPS coordinates for hold position |
37 | FlightMode_t FlightMode = GPS_FLIGHT_MODE_UNDEF; |
34 | GPS_Pos_t HoldPosition = {0,0,0,INVALID}; |
- | |
35 | // GPS coordinates for home position |
38 | |
- | 39 | ||
- | 40 | // --------------------------------------------------------------------------------- |
|
- | 41 | void GPS_UpdateParameter(void) |
|
- | 42 | { |
|
36 | GPS_Pos_t HomePosition = {0,0,0,INVALID}; |
43 | static FlightMode_t FlightModeOld = GPS_FLIGHT_MODE_UNDEF; |
- | 44 | ||
- | 45 | if((RC_Quality < 100) || (MKFlags & MKFLAG_EMERGENCY_LANDING)) |
|
- | 46 | { |
|
- | 47 | FlightMode = GPS_FLIGHT_MODE_FREE; |
|
- | 48 | } |
|
37 | 49 | else |
|
- | 50 | { |
|
- | 51 | if (FCParam.NaviGpsModeControl < 50) FlightMode = GPS_FLIGHT_MODE_AID; |
|
38 | 52 | else if(FCParam.NaviGpsModeControl < 180) FlightMode = GPS_FLIGHT_MODE_FREE; |
|
Line -... | Line 53... | ||
- | 53 | else FlightMode = GPS_FLIGHT_MODE_HOME; |
|
- | 54 | } |
|
- | 55 | if (FlightMode != FlightModeOld) |
|
39 | // --------------------------------------------------------------------------------- |
56 | { |
40 | 57 | BeepTime = 100; |
|
41 | // checks nick and roll sticks for manual control |
58 | } |
- | 59 | FlightModeOld = FlightMode; |
|
42 | uint8_t IsManualControlled(void) |
60 | } |
43 | { |
61 | |
44 | if ( (abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) < GPS_STICK_SENSE) && (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < GPS_STICK_SENSE)) return 0; |
- | |
45 | else return 1; |
- | |
46 | } |
62 | |
47 | 63 | ||
48 | // set home position to current positon |
- | |
- | 64 | // --------------------------------------------------------------------------------- |
|
49 | void GPS_SetHomePosition(void) |
65 | // This function defines a good GPS signal condition |
50 | { |
66 | uint8_t GPS_IsSignalOK(void) |
- | 67 | { |
|
- | 68 | static uint8_t GPSFix = 0; |
|
- | 69 | if( (GPSInfo.status != INVALID) && (GPSInfo.satfix == SATFIX_3D) && (GPSInfo.flags & FLAG_GPSFIXOK) && ((GPSInfo.satnum >= ParamSet.NaviGpsMinSat) || GPSFix)) |
|
- | 70 | { |
|
- | 71 | GPSFix = 1; |
|
- | 72 | return(1); |
|
- | 73 | ||
- | 74 | } |
|
- | 75 | else return (0); |
|
- | 76 | ||
51 | if( ((GPSInfo.status == VALID) || (GPSInfo.status == PROCESSED)) && GPSInfo.satfix == SATFIX_3D) |
77 | } |
- | 78 | // --------------------------------------------------------------------------------- |
|
- | 79 | // rescale xy-vector length to limit |
|
52 | { |
80 | uint8_t GPS_LimitXY(int32_t *x, int32_t *y, int32_t limit) |
- | 81 | { |
|
53 | HomePosition.Longitude = GPSInfo.longitude; |
82 | uint8_t retval = 0; |
- | 83 | int32_t len; |
|
54 | HomePosition.Latitude = GPSInfo.latitude; |
84 | len = (int32_t)c_sqrt(*x * *x + *y * *y); |
Line 55... | Line 85... | ||
55 | HomePosition.Altitude = GPSInfo.altitude; |
85 | if (len > limit) |
56 | HomePosition.Status = VALID; |
86 | { |
57 | BeepTime = 1000; // signal if new home position was set |
87 | // normalize control vector components to the limit |
- | 88 | *x = (*x * limit) / len; |
|
- | 89 | *y = (*y * limit) / len; |
|
- | 90 | retval = 1; |
|
- | 91 | } |
|
- | 92 | return(retval); |
|
58 | } |
93 | } |
59 | else |
94 | |
- | 95 | // checks nick and roll sticks for manual control |
|
- | 96 | uint8_t GPS_IsManualControlled(void) |
|
- | 97 | { |
|
- | 98 | if ( (abs(PPM_in[ParamSet.ChannelAssignment[CH_NICK]]) < ParamSet.NaviStickThreshold) && (abs(PPM_in[ParamSet.ChannelAssignment[CH_ROLL]]) < ParamSet.NaviStickThreshold)) return 0; |
|
- | 99 | else return 1; |
|
60 | { |
100 | } |
61 | HomePosition.Status = INVALID; |
101 | |
62 | } |
102 | // set given position to current gps position |
63 | } |
103 | uint8_t GPS_SetCurrPosition(GPS_Pos_t * pGPSPos) |
- | 104 | { |
|
64 | 105 | uint8_t retval = 0; |
|
65 | // set hold position to current positon |
106 | if(pGPSPos == NULL) return(retval); // bad pointer |
66 | void GPS_SetHoldPosition(void) |
107 | |
67 | { |
108 | if(GPS_IsSignalOK()) |
- | 109 | { // is GPS signal condition is fine |
|
68 | if( ((GPSInfo.status == VALID) || (GPSInfo.status == PROCESSED)) && GPSInfo.satfix == SATFIX_3D) |
110 | pGPSPos->Longitude = GPSInfo.longitude; |
- | 111 | pGPSPos->Latitude = GPSInfo.latitude; |
|
69 | { |
112 | pGPSPos->Altitude = GPSInfo.altitude; |
Line 70... | Line 113... | ||
70 | HoldPosition.Longitude = GPSInfo.longitude; |
113 | pGPSPos->Status = NEWDATA; |
71 | HoldPosition.Latitude = GPSInfo.latitude; |
114 | retval = 1; |
72 | HoldPosition.Altitude = GPSInfo.altitude; |
115 | } |
- | 116 | else |
|
- | 117 | { // bad GPS signal condition |
|
- | 118 | pGPSPos->Status = INVALID; |
|
- | 119 | retval = 0; |
|
- | 120 | } |
|
- | 121 | return(retval); |
|
- | 122 | } |
|
73 | HoldPosition.Status = VALID; |
123 | |
- | 124 | // clear position |
|
- | 125 | uint8_t GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
|
- | 126 | { |
|
74 | } |
127 | uint8_t retval = 0; |
Line 75... | Line 128... | ||
75 | else |
128 | if(pGPSPos == NULL) return(retval); // bad pointer |
76 | { |
129 | else |
77 | HoldPosition.Status = INVALID; |
130 | { |
Line 94... | Line 147... | ||
94 | // calculates the GPS control stick values from the deviation to target position |
147 | // calculates the GPS control stick values from the deviation to target position |
95 | // if the pointer to the target positin is NULL or is the target position invalid |
148 | // if the pointer to the target positin is NULL or is the target position invalid |
96 | // then the P part of the controller is deactivated. |
149 | // then the P part of the controller is deactivated. |
97 | void GPS_PIDController(GPS_Pos_t *pTargetPos) |
150 | void GPS_PIDController(GPS_Pos_t *pTargetPos) |
98 | { |
151 | { |
99 | int32_t temp, temp1, PID_Nick, PID_Roll; |
152 | int32_t PID_Nick, PID_Roll; |
100 | int32_t coscompass, sincompass; |
153 | int32_t coscompass, sincompass; |
101 | int32_t GPSPosDev_North, GPSPosDev_East; // Position deviation in cm |
154 | int32_t GPSPosDev_North, GPSPosDev_East; // Position deviation in cm |
102 | int32_t P_North = 0, D_North = 0, P_East = 0, D_East = 0, I_North = 0, I_East = 0; |
155 | int32_t P_North = 0, D_North = 0, P_East = 0, D_East = 0, I_North = 0, I_East = 0; |
103 | int32_t PID_North = 0, PID_East = 0; |
156 | int32_t PID_North = 0, PID_East = 0; |
104 | static int32_t cos_target_latitude = 1; |
157 | static int32_t cos_target_latitude = 1; |
105 | static int32_t GPSPosDevIntegral_North = 0, GPSPosDevIntegral_East = 0; |
158 | static int32_t GPSPosDevIntegral_North = 0, GPSPosDevIntegral_East = 0; |
106 | static GPS_Pos_t *pLastTargetPos = 0; |
159 | static GPS_Pos_t *pLastTargetPos = 0; |
Line 107... | Line 160... | ||
107 | 160 | ||
108 | // if GPS data and Compass are ok |
161 | // if GPS data and Compass are ok |
109 | if((GPSInfo.status == VALID) && (GPSInfo.satfix == SATFIX_3D) && (CompassHeading >= 0) ) |
162 | if( GPS_IsSignalOK() && (CompassHeading >= 0) ) |
Line 110... | Line 163... | ||
110 | { |
163 | { |
111 | 164 | ||
112 | if(pTargetPos != NULL) // if there is a target position |
165 | if(pTargetPos != NULL) // if there is a target position |
Line 154... | Line 207... | ||
154 | } |
207 | } |
Line 155... | Line 208... | ||
155 | 208 | ||
Line 156... | Line 209... | ||
156 | //Calculate PID-components of the controller (negative sign for compensation) |
209 | //Calculate PID-components of the controller (negative sign for compensation) |
157 | 210 | ||
158 | // P-Part |
211 | // P-Part |
Line 159... | Line 212... | ||
159 | P_North = -((int32_t)GPS_P_Factor * GPSPosDev_North)/2048; |
212 | P_North = -((int32_t)FCParam.NaviGpsP * GPSPosDev_North)/16; |
160 | P_East = -((int32_t)GPS_P_Factor * GPSPosDev_East)/2048; |
213 | P_East = -((int32_t)FCParam.NaviGpsP * GPSPosDev_East)/16; |
161 | 214 | ||
Line 162... | Line 215... | ||
162 | // I-Part |
215 | // I-Part |
163 | I_North = -((int32_t)GPS_I_Factor * GPSPosDevIntegral_North)/8192; |
216 | I_North = -((int32_t)FCParam.NaviGpsI * GPSPosDevIntegral_North)/64; |
164 | I_East = -((int32_t)GPS_I_Factor * GPSPosDevIntegral_East)/8192; |
217 | I_East = -((int32_t)FCParam.NaviGpsI * GPSPosDevIntegral_East)/64; |
Line 165... | Line 218... | ||
165 | 218 | ||
166 | // combine P- & I-Part |
- | |
167 | PID_North = P_North + I_North; |
- | |
168 | PID_East = P_East + I_East; |
- | |
169 | - | ||
170 | //limit PI-Part to limit the max velocity |
- | |
171 | //temp1 = ((int32_t)GPS_D_Factor * MAX_VELOCITY)/512; // the PI-Part limit |
219 | // combine P- & I-Part |
172 | temp = (int32_t)c_sqrt(PID_North*PID_North + PID_East*PID_East); // the current PI-Part |
- | |
173 | if(temp > GPS_P_LIMIT) // P-Part limit is reached |
- | |
174 | { |
- | |
175 | // normalize P-part components to the P-Part limit |
220 | PID_North = P_North + I_North; |
- | 221 | PID_East = P_East + I_East; |
|
176 | PID_North = (PID_North * GPS_P_LIMIT)/temp; |
222 | |
177 | PID_East = (PID_East * GPS_P_LIMIT)/temp; |
223 | //limit PI-Part |
178 | } |
224 | if(!GPS_LimitXY(&PID_North, &PID_East, GPS_P_LIMIT)) |
179 | else // PI-Part under its limit |
225 | { |
180 | { |
226 | // P-Part limit is not reached |
181 | // update position error integrals |
227 | // update position error integrals |
182 | GPSPosDevIntegral_North += GPSPosDev_North/16; |
228 | GPSPosDevIntegral_North += GPSPosDev_North/16; |
183 | if( GPSPosDevIntegral_North > GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_North = GPS_POSDEV_INTEGRAL_LIMIT; |
229 | if( GPSPosDevIntegral_North > GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_North = GPS_POSDEV_INTEGRAL_LIMIT; |
Line 184... | Line 230... | ||
184 | else if (GPSPosDevIntegral_North < -GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_North = -GPS_POSDEV_INTEGRAL_LIMIT; |
230 | else if (GPSPosDevIntegral_North < -GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_North = -GPS_POSDEV_INTEGRAL_LIMIT; |
185 | GPSPosDevIntegral_East += GPSPosDev_East/16; |
231 | GPSPosDevIntegral_East += GPSPosDev_East/16; |
186 | if( GPSPosDevIntegral_East > GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_East = GPS_POSDEV_INTEGRAL_LIMIT; |
232 | if( GPSPosDevIntegral_East > GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_East = GPS_POSDEV_INTEGRAL_LIMIT; |
187 | else if (GPSPosDevIntegral_East < -GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_East = -GPS_POSDEV_INTEGRAL_LIMIT; |
- | |
Line 188... | Line 233... | ||
188 | } |
233 | else if (GPSPosDevIntegral_East < -GPS_POSDEV_INTEGRAL_LIMIT) GPSPosDevIntegral_East = -GPS_POSDEV_INTEGRAL_LIMIT; |
189 | 234 | } |
|
190 | // D-Part |
235 | |
Line -... | Line 236... | ||
- | 236 | // D-Part |
|
- | 237 | D_North = -((int32_t)FCParam.NaviGpsD * GPSInfo.velnorth)/4; |
|
- | 238 | D_East = -((int32_t)FCParam.NaviGpsD * GPSInfo.veleast)/4; |
|
- | 239 | ||
191 | D_North = -((int32_t)GPS_D_Factor * GPSInfo.velnorth)/512; |
240 | // combine PI- and D-Part |
Line 192... | Line 241... | ||
192 | D_East = -((int32_t)GPS_D_Factor * GPSInfo.veleast)/512; |
241 | PID_North += D_North; |
193 | 242 | PID_East += D_East; |
|
194 | 243 | ||
Line 208... | Line 257... | ||
208 | // copter should fly to west (positive roll). |
257 | // copter should fly to west (positive roll). |
209 | // The influence of the GPS_Nick and GPS_Roll variable is contrarily to the stick values |
258 | // The influence of the GPS_Nick and GPS_Roll variable is contrarily to the stick values |
210 | // in the fc.c. Therefore a positive north deviation/velocity should result in a positive |
259 | // in the fc.c. Therefore a positive north deviation/velocity should result in a positive |
211 | // GPS_Nick and a positive east deviation/velocity should result in a negative GPS_Roll. |
260 | // GPS_Nick and a positive east deviation/velocity should result in a negative GPS_Roll. |
Line 212... | Line 261... | ||
212 | 261 | ||
213 | coscompass = (int32_t)c_cos_8192(CompassHeading); |
262 | coscompass = (int32_t)c_cos_8192(YawGyroHeading / YAW_GYRO_DEG_FACTOR); |
214 | sincompass = (int32_t)c_sin_8192(CompassHeading); |
263 | sincompass = (int32_t)c_sin_8192(YawGyroHeading / YAW_GYRO_DEG_FACTOR); |
215 | PID_Roll = (coscompass * PID_East - sincompass * PID_North) / 8192; |
264 | PID_Roll = (coscompass * PID_East - sincompass * PID_North) / 8192; |
Line 216... | Line 265... | ||
216 | PID_Nick = -1*((sincompass * PID_East + coscompass * PID_North) / 8192); |
265 | PID_Nick = -1*((sincompass * PID_East + coscompass * PID_North) / 8192); |
217 | - | ||
218 | // limit resulting GPS control vector |
- | |
219 | temp = (int32_t)c_sqrt(PID_Roll*PID_Roll + PID_Nick*PID_Nick); |
- | |
220 | if (temp > GPS_STICK_LIMIT) |
- | |
221 | { |
- | |
222 | // normalize control vector components to the limit |
266 | |
223 | PID_Roll = (PID_Roll * GPS_STICK_LIMIT)/temp; |
- | |
Line 224... | Line -... | ||
224 | PID_Nick = (PID_Nick * GPS_STICK_LIMIT)/temp; |
- | |
225 | } |
267 | // limit resulting GPS control vector |
226 | - | ||
- | 268 | GPS_LimitXY(&PID_Nick, &PID_Roll, GPS_STICK_LIMIT); |
|
227 | GPS_Roll = (int16_t)PID_Roll; |
269 | |
228 | GPS_Nick = (int16_t)PID_Nick; |
270 | GPS_Nick = (int16_t)PID_Nick; |
229 | 271 | GPS_Roll = (int16_t)PID_Roll; |
|
230 | } |
272 | } |
231 | else // invalid GPS data or bad compass reading |
273 | else // invalid GPS data or bad compass reading |
Line 238... | Line 280... | ||
238 | } |
280 | } |
Line 239... | Line 281... | ||
239 | 281 | ||
240 | 282 | ||
241 | - | ||
242 | 283 | ||
243 | void GPS_Main(uint8_t ctrl) |
284 | |
Line 244... | Line 285... | ||
244 | { |
285 | void GPS_Main(void) |
245 | static uint8_t GPS_Task = TSK_IDLE; |
- | |
246 | static uint8_t GPS_P_Delay = 0; |
- | |
247 | int16_t satbeep; |
- | |
Line -... | Line 286... | ||
- | 286 | { |
|
- | 287 | static uint8_t GPS_P_Delay = 0; |
|
- | 288 | uint16_t beep_rythm = 0; |
|
- | 289 | ||
- | 290 | GPS_UpdateParameter(); |
|
Line 248... | Line 291... | ||
248 | 291 | ||
249 | // ctrl enables the gps feature |
292 | // store home position if start of flight flag is set |
250 | if(ctrl < 70) GPS_Task = TSK_IDLE; |
293 | if(MKFlags & MKFLAG_CALIBRATE) |
251 | else if (ctrl < 160) GPS_Task = TSK_HOLD; |
294 | { |
252 | else GPS_Task = TSK_HOME; // ctrl >= 160 |
295 | GPS_SetCurrPosition(&HomePosition); |
253 | 296 | } |
|
254 | 297 | ||
255 | switch(GPSInfo.status) |
298 | switch(GPSInfo.status) |
256 | { |
299 | { |
257 | case INVALID: // invalid gps data |
300 | case INVALID: // invalid gps data |
Line 270... | Line 313... | ||
270 | { |
313 | { |
271 | GPS_Neutral(); |
314 | GPS_Neutral(); |
272 | GPSInfo.status = INVALID; |
315 | GPSInfo.status = INVALID; |
273 | } |
316 | } |
274 | break; |
317 | break; |
275 | case VALID: // new valid data from gps device |
318 | case NEWDATA: // new valid data from gps device |
276 | // if the gps data quality is good |
319 | // if the gps data quality is good |
- | 320 | beep_rythm++; |
|
- | 321 | ||
277 | if (GPSInfo.satfix == SATFIX_3D) |
322 | if (GPS_IsSignalOK()) |
278 | { |
323 | { |
279 | switch(GPS_Task) // check what's to do |
324 | switch(FlightMode) // check what's to do |
280 | { |
325 | { |
281 | case TSK_IDLE: |
326 | case GPS_FLIGHT_MODE_FREE: |
282 | // update hold position to current gps position |
327 | // update hold position to current gps position |
283 | GPS_SetHoldPosition(); // can get invalid if gps signal is bad |
328 | GPS_SetCurrPosition(&HoldPosition); // can get invalid if gps signal is bad |
284 | // disable gps control |
329 | // disable gps control |
285 | GPS_Neutral(); |
330 | GPS_Neutral(); |
286 | break; // eof TSK_IDLE |
331 | break; |
- | 332 | ||
287 | case TSK_HOLD: |
333 | case GPS_FLIGHT_MODE_AID: |
288 | if(HoldPosition.Status != INVALID) |
334 | if(HoldPosition.Status != INVALID) |
289 | { |
335 | { |
290 | if( IsManualControlled() ) // MK controlled by user |
336 | if( GPS_IsManualControlled() ) // MK controlled by user |
291 | { |
337 | { |
292 | // update hold point to current gps position |
338 | // update hold point to current gps position |
293 | GPS_SetHoldPosition(); |
339 | GPS_SetCurrPosition(&HoldPosition); |
294 | // disable gps control |
340 | // disable gps control |
295 | GPS_Neutral(); |
341 | GPS_Neutral(); |
296 | GPS_P_Delay = 0; |
342 | GPS_P_Delay = 0; |
297 | } |
343 | } |
298 | else // GPS control active |
344 | else // GPS control active |
299 | { |
345 | { |
300 | if(GPS_P_Delay<7) |
346 | if(GPS_P_Delay < 7) |
301 | { // delayed activation of P-Part for 8 cycles (8*0.25s = 2s) |
347 | { // delayed activation of P-Part for 8 cycles (8*0.25s = 2s) |
302 | GPS_P_Delay++; |
348 | GPS_P_Delay++; |
303 | GPS_SetHoldPosition(); // update hold point to current gps position |
349 | GPS_SetCurrPosition(&HoldPosition); // update hold point to current gps position |
304 | GPS_PIDController(NULL); // activates only the D-Part |
350 | GPS_PIDController(NULL); // activates only the D-Part |
305 | } |
351 | } |
306 | else GPS_PIDController(&HoldPosition);// activates the P&D-Part |
352 | else GPS_PIDController(&HoldPosition);// activates the P&D-Part |
307 | } |
353 | } |
308 | } |
354 | } |
309 | else // invalid Hold Position |
355 | else // invalid Hold Position |
310 | { // try to catch a valid hold position from gps data input |
356 | { // try to catch a valid hold position from gps data input |
311 | GPS_SetHoldPosition(); |
357 | GPS_SetCurrPosition(&HoldPosition); |
312 | GPS_Neutral(); |
358 | GPS_Neutral(); |
313 | } |
359 | } |
314 | break; // eof TSK_HOLD |
360 | break; |
- | 361 | ||
315 | case TSK_HOME: |
362 | case GPS_FLIGHT_MODE_HOME: |
316 | if(HomePosition.Status != INVALID) |
363 | if(HomePosition.Status != INVALID) |
317 | { |
364 | { |
318 | // update hold point to current gps position |
365 | // update hold point to current gps position |
319 | // to avoid a flight back if home comming is deactivated |
366 | // to avoid a flight back if home comming is deactivated |
320 | GPS_SetHoldPosition(); |
367 | GPS_SetCurrPosition(&HoldPosition); |
321 | if( IsManualControlled() ) // MK controlled by user |
368 | if( GPS_IsManualControlled() ) // MK controlled by user |
322 | { |
369 | { |
323 | GPS_Neutral(); |
370 | GPS_Neutral(); |
324 | } |
371 | } |
325 | else // GPS control active |
372 | else // GPS control active |
326 | { |
373 | { |
Line 332... | Line 379... | ||
332 | BeepTime = 50; // signal invalid home position |
379 | BeepTime = 50; // signal invalid home position |
333 | // try to hold at least the position as a fallback option |
380 | // try to hold at least the position as a fallback option |
Line 334... | Line 381... | ||
334 | 381 | ||
335 | if (HoldPosition.Status != INVALID) |
382 | if (HoldPosition.Status != INVALID) |
336 | { |
383 | { |
337 | if( IsManualControlled() ) // MK controlled by user |
384 | if( GPS_IsManualControlled() ) // MK controlled by user |
338 | { |
385 | { |
339 | GPS_Neutral(); |
386 | GPS_Neutral(); |
340 | } |
387 | } |
341 | else // GPS control active |
388 | else // GPS control active |
342 | { |
389 | { |
343 | GPS_PIDController(&HoldPosition); |
390 | GPS_PIDController(&HoldPosition); |
344 | } |
391 | } |
345 | } |
392 | } |
346 | else |
393 | else |
347 | { // try to catch a valid hold position |
394 | { // try to catch a valid hold position |
348 | GPS_SetHoldPosition(); |
395 | GPS_SetCurrPosition(&HoldPosition); |
349 | GPS_Neutral(); |
396 | GPS_Neutral(); |
350 | } |
397 | } |
351 | } |
398 | } |
352 | break; // eof TSK_HOME |
399 | break; // eof TSK_HOME |
353 | default: // unhandled task |
400 | default: // unhandled task |
354 | GPS_Neutral(); |
401 | GPS_Neutral(); |
355 | break; // eof default |
402 | break; // eof default |
356 | } // eof switch GPS_Task |
403 | } // eof switch GPS_Task |
357 | } // eof 3D-FIX |
404 | } // eof gps data quality is good |
358 | else // no 3D-SATFIX |
405 | else // gps data quality is bad |
359 | { // disable gps control |
406 | { // disable gps control |
360 | GPS_Neutral(); |
407 | GPS_Neutral(); |
361 | if(GPS_Task != TSK_IDLE) |
- | |
362 | { |
408 | // beep if signal is not sufficient |
363 | satbeep = 1600 - (int16_t)GPSInfo.satnum * 200; // is zero at 8 sats |
- | |
364 | if (satbeep < 0) satbeep = 0; |
409 | if(!(GPSInfo.flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100; |
365 | BeepTime = 50 + (uint16_t)satbeep; // max 1650 * 0.1 ms = |
- | |
366 | } |
410 | else if (GPSInfo.satnum < ParamSet.NaviGpsMinSat && !(beep_rythm % 5)) BeepTime = 10; |
367 | } |
411 | } |
368 | // set current data as processed to avoid further calculations on the same gps data |
412 | // set current data as processed to avoid further calculations on the same gps data |
369 | GPSInfo.status = PROCESSED; |
413 | GPSInfo.status = PROCESSED; |
370 | break; |
414 | break; |