Rev 983 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
966 | MikeW | 1 | /* |
2 | Copyright 2008, by Michael Walter |
||
3 | |||
4 | All functions written by Michael Walter are free software and can be redistributed and/or modified under the terms of the GNU Lesser |
||
5 | General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but |
||
6 | WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
7 | See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public |
||
8 | License along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
9 | |||
10 | Please note: The software is based on the framework provided by H. Buss and I. Busker in their Mikrokopter projekt. All functions that |
||
11 | are not written by Michael Walter are under the license by H. Buss and I. Busker (license_buss.txt) published by www.mikrokopter.de |
||
12 | unless it is stated otherwise. |
||
13 | */ |
||
14 | |||
15 | |||
16 | /***************************************************************************** |
||
17 | INCLUDES |
||
18 | **************************************************************************** */ |
||
19 | #include "kafi.h" |
||
20 | #include "FlightControl.h" |
||
21 | #include "main.h" |
||
22 | #include "mm3.h" |
||
23 | #include "main.h" |
||
24 | #include "eeprom.c" |
||
25 | |||
26 | /***************************************************************************** |
||
27 | (SYMBOLIC) CONSTANTS |
||
28 | *****************************************************************************/ |
||
29 | #define MAX_GAS 250 |
||
30 | #define MIN_GAS 15 |
||
31 | |||
32 | #define sin45 sin(45.F / 180.F * PI) |
||
33 | #define cos45 cos(45.F / 180.F * PI) |
||
34 | |||
35 | /***************************************************************************** |
||
36 | VARIABLES |
||
37 | *****************************************************************************/ |
||
38 | |||
39 | extern void GPSupdate(void); |
||
40 | |||
973 | MikeW | 41 | f32_t AdNeutralNick = 0.0F, AdNeutralRoll = 0.0F, AdNeutralGier = 0.0F; |
966 | MikeW | 42 | int NeutralAccX = 0, NeutralAccY = 0, NeutralAccZ = 0; |
973 | MikeW | 43 | int AverageRoll = 0, AverageNick = 0, AverageGier = 0; |
966 | MikeW | 44 | int AveragerACC_X = 0, AveragerACC_Y = 0, AveragerACC_Z = 0; |
45 | |||
46 | f32_t Roll_X_Offset = 0.F, Roll_Y_Offset = 0.F, Roll_Z_Offset = 0.F; |
||
47 | f32_t ACC_X_Offset = 0.F, ACC_Y_Offset = 0.F, ACC_Z_Offset = 0.F; |
||
48 | |||
49 | int DeltaAltitude = 0, CurrentAltitude = 0, LastAltitude = 0, InitialAltitude = 0; |
||
50 | int SummeNick=0,SummeRoll=0, StickNick = 0,StickRoll = 0,StickGier = 0, sollGier = 0; |
||
51 | int GierMischanteil, GasMischanteil; |
||
52 | |||
53 | unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count; |
||
54 | unsigned char MotorWert[5]; |
||
55 | unsigned char SenderOkay = 0; |
||
56 | unsigned int I2CTimeout = 100; |
||
57 | char MotorenEin = 0; |
||
983 | MikeW | 58 | unsigned int modell_fliegt = 0; |
966 | MikeW | 59 | |
60 | extern unsigned long maxDistance; |
||
61 | extern signed int GPS_Nick, GPS_Roll; |
||
62 | extern int RemoteLinkLost; |
||
987 | mikew | 63 | extern int InvalidAttitude; |
966 | MikeW | 64 | struct mk_param_struct EE_Parameter; |
65 | |||
66 | /* **************************************************************************** |
||
67 | Functionname: SetNeutral */ /*! |
||
68 | Description: |
||
69 | |||
70 | @param[in] |
||
71 | |||
72 | @return void |
||
73 | @pre - |
||
74 | @post - |
||
75 | @author Michael Walter |
||
76 | **************************************************************************** */ |
||
77 | void SetNeutral(void) |
||
78 | { |
||
983 | MikeW | 79 | beeptime = 2000; |
966 | MikeW | 80 | Delay_ms(1000); |
81 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
82 | { |
||
83 | if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750)) |
||
84 | { |
||
85 | SucheLuftruckOffset(); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | LastAltitude = CurrentAltitude; |
||
90 | Delay_ms_Mess(300); |
||
91 | |||
92 | ANALOG_OFF; |
||
973 | MikeW | 93 | AdNeutralNick = (f32_t) AdWertNick_Raw; |
94 | AdNeutralRoll = (f32_t) AdWertRoll_Raw; |
||
95 | AdNeutralGier = (f32_t) AdWertGier_Raw; |
||
966 | MikeW | 96 | NeutralAccY = AdWertAccRoll_Raw; |
97 | NeutralAccX = AdWertAccNick_Raw; |
||
98 | NeutralAccZ = AdWertAccHoch_Raw; |
||
99 | |||
100 | Roll_X_Offset = 0.F; |
||
101 | Roll_Y_Offset = 0.F; |
||
102 | Roll_Z_Offset = 0.F; |
||
103 | ACC_X_Offset = 0.F; |
||
104 | ACC_Y_Offset = 0.F; |
||
105 | ACC_Z_Offset = 0.F; |
||
106 | |||
107 | AccumulatedACC_X = 0; |
||
108 | AccumulatedACC_X_cnt = 0; |
||
109 | AccumulatedACC_Y = 0; |
||
110 | AccumulatedACC_Y_cnt = 0; |
||
111 | AccumulatedACC_Z = 0; |
||
112 | AccumulatedACC_Z_cnt = 0; |
||
113 | |||
973 | MikeW | 114 | AccumulatedRoll = 0; |
115 | AccumulatedRoll_cnt = 0; |
||
116 | AccumulatedNick = 0; |
||
117 | AccumulatedNick_cnt = 0; |
||
118 | AccumulatedGier = 0; |
||
119 | AccumulatedGier_cnt = 0; |
||
966 | MikeW | 120 | |
121 | AveragerACC_X = 0; |
||
122 | AveragerACC_Y = 0; |
||
123 | AveragerACC_Z = 0; |
||
124 | |||
125 | AccumulatedACC_X = 0; |
||
126 | AccumulatedACC_X_cnt = 0; |
||
127 | AccumulatedACC_Y = 0; |
||
128 | AccumulatedACC_Y_cnt = 0; |
||
129 | AccumulatedACC_Z = 0; |
||
130 | AccumulatedACC_Z_cnt = 0; |
||
131 | ANALOG_ON; |
||
132 | |||
133 | SummeRoll = 0; |
||
134 | SummeNick = 0; |
||
135 | |||
136 | sollGier = status.iPsi10; |
||
137 | InitialAltitude = AdWertAirPressure_Raw; |
||
987 | mikew | 138 | |
139 | InvalidAttitude = 0; |
||
966 | MikeW | 140 | beeptime = 2000; |
141 | } |
||
142 | |||
143 | |||
144 | /* **************************************************************************** |
||
145 | Functionname: GetMeasurements */ /*! |
||
146 | Description: CalculateAverage |
||
147 | |||
148 | @param[in] |
||
149 | |||
150 | @return void |
||
151 | @pre - |
||
152 | @post - |
||
153 | @author Michael Walter |
||
154 | **************************************************************************** */ |
||
155 | void GetMeasurements(void) |
||
156 | { |
||
157 | ANALOG_OFF; |
||
973 | MikeW | 158 | AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt; |
159 | AverageNick = AccumulatedNick / AccumulatedNick_cnt; |
||
160 | AverageGier = AccumulatedGier / AccumulatedGier_cnt; |
||
966 | MikeW | 161 | |
162 | /* Get Pressure Differenz */ |
||
163 | CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt; |
||
164 | AccumulatedAirPressure_cnt = 0; |
||
165 | AccumulatedAirPressure = 0; |
||
166 | |||
167 | static char AirPressureCnt = 0; |
||
168 | if (AirPressureCnt % 25 == 1) |
||
169 | { |
||
170 | DeltaAltitude = CurrentAltitude - LastAltitude; |
||
171 | LastAltitude = CurrentAltitude; |
||
172 | } |
||
173 | AirPressureCnt++; |
||
983 | MikeW | 174 | |
175 | if(modell_fliegt < 0x250) |
||
966 | MikeW | 176 | { |
983 | MikeW | 177 | //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10)) |
178 | AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw; |
||
179 | AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw; |
||
180 | if (abs(StickGier) < 15 || MotorenEin == 0) |
||
181 | { |
||
182 | AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw; |
||
183 | } |
||
184 | } |
||
185 | else if(modell_fliegt < 0x2000) |
||
186 | { |
||
187 | //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10)) |
||
973 | MikeW | 188 | AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw; |
189 | AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw; |
||
966 | MikeW | 190 | if (abs(StickGier) < 15 || MotorenEin == 0) |
191 | { |
||
983 | MikeW | 192 | AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw; |
966 | MikeW | 193 | } |
194 | } |
||
983 | MikeW | 195 | else |
196 | { |
||
197 | AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw; |
||
198 | AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw; |
||
199 | if (abs(StickGier) < 15 || MotorenEin == 0) |
||
200 | { |
||
201 | AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw; |
||
202 | } |
||
203 | } |
||
966 | MikeW | 204 | |
205 | #if 1 |
||
973 | MikeW | 206 | DebugOut.Analog[6] = AdWertNick_Raw; |
207 | DebugOut.Analog[7] = AdWertRoll_Raw; |
||
208 | DebugOut.Analog[8] = AdWertGier_Raw; |
||
209 | |||
210 | DebugOut.Analog[9] = AdNeutralNick; |
||
211 | DebugOut.Analog[10] = AdNeutralRoll; |
||
212 | DebugOut.Analog[11] = AdNeutralGier; |
||
966 | MikeW | 213 | #endif |
983 | MikeW | 214 | |
973 | MikeW | 215 | AccumulatedRoll = 0; |
216 | AccumulatedRoll_cnt = 0; |
||
217 | AccumulatedNick = 0; |
||
218 | AccumulatedNick_cnt = 0; |
||
219 | AccumulatedGier = 0; |
||
220 | AccumulatedGier_cnt = 0; |
||
966 | MikeW | 221 | |
222 | #if 0 |
||
223 | ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt); |
||
224 | ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt); |
||
225 | ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt); |
||
226 | #endif |
||
227 | |||
228 | AveragerACC_X = AccumulatedACC_X / AccumulatedACC_X_cnt; |
||
229 | AveragerACC_Y = AccumulatedACC_Y / AccumulatedACC_Y_cnt; |
||
230 | AveragerACC_Z = AccumulatedACC_Z / AccumulatedACC_Z_cnt; |
||
231 | |||
232 | AccumulatedACC_X = 0; |
||
233 | AccumulatedACC_X_cnt = 0; |
||
234 | AccumulatedACC_Y = 0; |
||
235 | AccumulatedACC_Y_cnt = 0; |
||
236 | AccumulatedACC_Z = 0; |
||
237 | AccumulatedACC_Z_cnt = 0; |
||
238 | |||
239 | ANALOG_ON; |
||
240 | } |
||
241 | |||
242 | /* **************************************************************************** |
||
243 | Functionname: SendMotorData */ /*! |
||
244 | Description: Senden der Motorwerte per I2C-Bus |
||
245 | |||
246 | @return void |
||
247 | @pre - |
||
248 | @post - |
||
249 | @author H. Buss / I. Busker |
||
250 | **************************************************************************** */ |
||
251 | void SendMotorData(void) |
||
252 | { |
||
253 | if(!MotorenEin) |
||
254 | { |
||
255 | Motor_Hinten = 0; |
||
256 | Motor_Vorne = 0; |
||
257 | Motor_Rechts = 0; |
||
258 | Motor_Links = 0; |
||
259 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
||
260 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
||
261 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
||
262 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
||
263 | } |
||
264 | |||
265 | //Start I2C Interrupt Mode |
||
266 | twi_state = 0; |
||
267 | motor = 0; |
||
268 | i2c_start(); |
||
269 | } |
||
270 | |||
271 | |||
272 | /* **************************************************************************** |
||
273 | Functionname: RemoteControl */ /*! |
||
274 | Description: |
||
275 | |||
276 | @return void |
||
277 | @pre - |
||
278 | @post - |
||
279 | @author H. Buss / I. Busker |
||
280 | **************************************************************************** */ |
||
281 | void RemoteControl(void) |
||
282 | { |
||
283 | static unsigned char delay_neutral = 0; |
||
284 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
285 | |||
286 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
287 | // Gaswert ermitteln |
||
288 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
289 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
||
290 | if(GasMischanteil < 0) |
||
291 | { |
||
292 | GasMischanteil = 0; |
||
293 | } |
||
294 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
295 | // Emfang schlecht |
||
296 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
297 | if(SenderOkay < 100) |
||
298 | { |
||
299 | if(!PcZugriff) |
||
300 | { |
||
301 | if(BeepMuster == 0xffff) |
||
302 | { |
||
303 | beeptime = 15000; |
||
304 | BeepMuster = 0x0c00; |
||
305 | } |
||
306 | } |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
311 | // Emfang gut |
||
312 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
313 | if(SenderOkay > 140) |
||
314 | { |
||
315 | if(GasMischanteil > 40) |
||
316 | { |
||
317 | if(modell_fliegt < 0xffff) |
||
318 | { |
||
319 | modell_fliegt++; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | |||
324 | if((GasMischanteil > 200) && |
||
325 | (MotorenEin == 0)) |
||
326 | { |
||
327 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
328 | // auf Nullwerte kalibrieren |
||
329 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
330 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
||
331 | { |
||
332 | if(++delay_neutral > 50) // nicht sofort |
||
333 | { |
||
334 | MotorenEin = 0; |
||
335 | delay_neutral = 0; |
||
336 | modell_fliegt = 0; |
||
337 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
338 | { |
||
339 | if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750)) |
||
340 | { |
||
341 | SucheLuftruckOffset(); |
||
342 | } |
||
343 | } |
||
344 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
345 | SetNeutral(); |
||
346 | } |
||
347 | } |
||
348 | else |
||
349 | { |
||
350 | delay_neutral = 0; |
||
351 | } |
||
352 | } |
||
353 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
354 | // Gas ist unten |
||
355 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
356 | if(GasMischanteil < 35) |
||
357 | { |
||
358 | // Starten |
||
359 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
||
360 | { |
||
361 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
362 | // Einschalten |
||
363 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
364 | if(++delay_einschalten > 100) |
||
365 | { |
||
366 | MotorenEin = 1; |
||
367 | modell_fliegt = 1; |
||
368 | delay_einschalten = 100; |
||
369 | } |
||
370 | } |
||
371 | else |
||
372 | { |
||
373 | delay_einschalten = 0; |
||
374 | } |
||
375 | //Auf Neutralwerte setzen |
||
376 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
377 | // Auschalten |
||
378 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
379 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
||
380 | { |
||
381 | if(++delay_ausschalten > 50) // nicht sofort |
||
382 | { |
||
383 | MotorenEin = 0; |
||
384 | modell_fliegt = 0; |
||
385 | delay_ausschalten = 50; |
||
386 | } |
||
387 | } |
||
388 | else |
||
389 | { |
||
390 | delay_ausschalten = 0; |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | } |
||
395 | } |
||
396 | |||
397 | |||
398 | |||
399 | |||
400 | /* **************************************************************************** |
||
401 | Functionname: PD_Regler */ /*! |
||
402 | Description: |
||
403 | |||
404 | @return void |
||
405 | @pre - |
||
406 | @post - |
||
407 | @author Michael Walter |
||
408 | **************************************************************************** */ |
||
409 | void PD_Regler(void) |
||
410 | { |
||
411 | int StickNick45,StickRoll45; |
||
412 | int DiffNick,DiffRoll, DiffGier; |
||
413 | int motorwert = 0; |
||
414 | int pd_ergebnis; |
||
415 | |||
416 | /***************************************************************************** |
||
417 | Update noimial attitude |
||
418 | **************************************************************************** */ |
||
419 | if(!NewPpmData--) |
||
420 | { |
||
421 | StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
||
422 | StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
||
423 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
||
424 | } // Ende neue Funken-Werte |
||
425 | |||
426 | #ifdef USE_GPS |
||
427 | /* G P S U p d a t e */ |
||
428 | GPSupdate(); |
||
429 | #endif |
||
430 | |||
431 | static float AverageGasMischanteil = 50.F; |
||
432 | if((GasMischanteil > 30) && |
||
433 | (MotorenEin == 1) && |
||
434 | (RemoteLinkLost == 0) ) |
||
435 | { /* Average the average throttle to find the hover setting */ |
||
436 | AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil; |
||
437 | } |
||
438 | /* Overide GasMischanteil */ |
||
439 | static unsigned int DescentCnt = 32000; |
||
440 | if ((RemoteLinkLost == 1) && |
||
441 | (MotorenEin == 1)) |
||
442 | { |
||
443 | if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/ |
||
444 | (maxDistance / 10 < 12)) /* we reached our target position */ |
||
445 | { |
||
446 | if (DescentCnt > 0) |
||
447 | { |
||
448 | DescentCnt--; |
||
449 | } |
||
450 | else |
||
451 | { /* We reached our target (hopefully) */ |
||
452 | MotorenEin = 0; |
||
453 | RemoteLinkLost = 0; |
||
454 | } |
||
455 | } |
||
456 | else |
||
457 | { |
||
458 | DescentCnt = 32000; |
||
459 | } |
||
460 | /* Bias the throttle for a slow descent */ |
||
461 | GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F)); |
||
462 | } |
||
463 | else |
||
464 | { |
||
465 | DescentCnt = 32000; |
||
466 | } |
||
467 | |||
468 | //DebugOut.Analog[13] = (int) GasMischanteil; |
||
469 | |||
972 | MikeW | 470 | #ifdef X_FORMATION |
966 | MikeW | 471 | /* Overide in case the remote link got lost */ |
472 | if (RemoteLinkLost == 0) |
||
473 | { /* We are flying in X-Formation */ |
||
474 | StickRoll45 = (int) (0.707F * (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick)); |
||
475 | StickNick45 = (int) (0.707F * (float)(StickRoll - GPS_Roll) + 0.707F * (float)(StickNick - GPS_Nick)); |
||
476 | } |
||
477 | else |
||
478 | { /* GPS overide is aktive */ |
||
479 | StickRoll45 = (int) (0.707F * (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick)); |
||
480 | StickNick45 = (int) (0.707F * (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick)); |
||
481 | StickGier = 0; |
||
482 | } |
||
972 | MikeW | 483 | #else |
484 | /* Overide in case the remote link got lost */ |
||
485 | if (RemoteLinkLost == 0) |
||
486 | { /* We are flying in X-Formation */ |
||
487 | StickRoll45 = StickRoll - GPS_Roll; |
||
488 | StickNick45 = StickNick - GPS_Nick; |
||
489 | } |
||
490 | else |
||
491 | { /* GPS overide is aktive */ |
||
492 | StickRoll45 = -GPS_Roll; |
||
493 | StickNick45 = -GPS_Nick; |
||
494 | StickGier = 0; |
||
495 | } |
||
496 | #endif |
||
497 | |||
966 | MikeW | 498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
499 | // Yaw |
||
500 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
501 | |||
502 | if(GasMischanteil < 20) |
||
503 | { |
||
504 | sollGier = status.iPsi10; |
||
505 | SummeRoll = 0; |
||
506 | SummeNick = 0; |
||
507 | } |
||
508 | |||
509 | /* Gier-Anteil */ |
||
510 | if (abs(StickGier) > 4) |
||
511 | { |
||
512 | sollGier = status.iPsi10 + 4 * StickGier; |
||
513 | } |
||
514 | DiffGier = (sollGier - status.iPsi10); |
||
973 | MikeW | 515 | GierMischanteil = (int) (-4 * DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10; |
966 | MikeW | 516 | |
517 | #define MUL_G 0.8 |
||
518 | if(GierMischanteil > MUL_G * GasMischanteil) |
||
519 | { |
||
520 | GierMischanteil = MUL_G * GasMischanteil; |
||
521 | } |
||
522 | if(GierMischanteil < -MUL_G * GasMischanteil) |
||
523 | { |
||
524 | GierMischanteil = -MUL_G * GasMischanteil; |
||
525 | } |
||
526 | if(GierMischanteil > 50) |
||
527 | { |
||
528 | GierMischanteil = 50; |
||
529 | } |
||
530 | if(GierMischanteil < -50) |
||
531 | { |
||
532 | GierMischanteil = -50; |
||
533 | } |
||
534 | |||
535 | /***************************************************************************** |
||
536 | PD-Control |
||
537 | **************************************************************************** */ |
||
538 | int scale_p; |
||
539 | int scale_d; |
||
540 | |||
541 | scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20); |
||
542 | scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20); |
||
543 | |||
544 | scale_p = 6; |
||
545 | scale_d = 7; |
||
546 | |||
547 | //DebugOut.Analog[14] = scale_p; |
||
548 | //DebugOut.Analog[15] = scale_d; |
||
549 | |||
550 | /* Pitch */ |
||
551 | DiffNick = -(status.iTheta10 + StickNick45); |
||
552 | /* R o l l */ |
||
553 | DiffRoll = -(status.iPhi10 + StickRoll45); |
||
554 | |||
555 | SummeNick += DiffNick; |
||
556 | if(SummeNick > 10000) |
||
557 | { |
||
558 | SummeNick = 10000; |
||
559 | } |
||
560 | if(SummeNick < -10000) |
||
561 | { |
||
562 | SummeNick = -10000; |
||
563 | } |
||
564 | |||
565 | SummeRoll += DiffRoll; |
||
566 | if(SummeRoll > 10000) |
||
567 | { |
||
568 | SummeRoll = 10000; |
||
569 | } |
||
570 | if(SummeRoll < -10000) |
||
571 | { |
||
572 | SummeRoll = -10000; |
||
573 | } |
||
574 | |||
973 | MikeW | 575 | pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); |
966 | MikeW | 576 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
577 | { |
||
578 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
||
579 | } |
||
580 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
||
581 | { |
||
582 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
||
583 | } |
||
584 | |||
585 | /* M o t o r V o r n */ |
||
586 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; |
||
587 | if ((motorwert < 0)) |
||
588 | { |
||
589 | motorwert = 0; |
||
590 | } |
||
591 | else if(motorwert > MAX_GAS) |
||
592 | { |
||
593 | motorwert = MAX_GAS; |
||
594 | } |
||
595 | if (motorwert < MIN_GAS) |
||
596 | { |
||
597 | motorwert = MIN_GAS; |
||
598 | } |
||
599 | Motor_Vorne = motorwert; |
||
600 | |||
601 | /* M o t o r H e c k */ |
||
602 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
||
603 | if ((motorwert < 0)) |
||
604 | { |
||
605 | motorwert = 0; |
||
606 | } |
||
607 | else if(motorwert > MAX_GAS) |
||
608 | { |
||
609 | motorwert = MAX_GAS; |
||
610 | } |
||
611 | if (motorwert < MIN_GAS) |
||
612 | { |
||
613 | motorwert = MIN_GAS; |
||
614 | } |
||
615 | Motor_Hinten = motorwert; |
||
616 | |||
973 | MikeW | 617 | pd_ergebnis = ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000); |
966 | MikeW | 618 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
619 | { |
||
620 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
||
621 | } |
||
622 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
||
623 | { |
||
624 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
||
625 | } |
||
626 | |||
627 | /* M o t o r L i n k s */ |
||
628 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
||
629 | if(motorwert > MAX_GAS) |
||
630 | { |
||
631 | motorwert = MAX_GAS; |
||
632 | } |
||
633 | if (motorwert < MIN_GAS) |
||
634 | { |
||
635 | motorwert = MIN_GAS; |
||
636 | } |
||
637 | Motor_Links = motorwert; |
||
638 | |||
639 | /* M o t o r R e c h t s */ |
||
640 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
||
641 | if(motorwert > MAX_GAS) |
||
642 | { |
||
643 | motorwert = MAX_GAS; |
||
644 | } |
||
645 | if (motorwert < MIN_GAS) |
||
646 | { |
||
647 | motorwert = MIN_GAS; |
||
648 | } |
||
649 | Motor_Rechts = motorwert; |
||
650 | |||
651 | #if 1 |
||
652 | DebugOut.Analog[0] = status.iTheta10; |
||
653 | DebugOut.Analog[1] = status.iPhi10; |
||
654 | DebugOut.Analog[2] = status.iPsi10 / 10; |
||
655 | #endif |
||
656 | } |