Rev 973 | Rev 987 | 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; |
||
63 | |||
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; |
||
138 | beeptime = 2000; |
||
139 | } |
||
140 | |||
141 | |||
142 | /* **************************************************************************** |
||
143 | Functionname: GetMeasurements */ /*! |
||
144 | Description: CalculateAverage |
||
145 | |||
146 | @param[in] |
||
147 | |||
148 | @return void |
||
149 | @pre - |
||
150 | @post - |
||
151 | @author Michael Walter |
||
152 | **************************************************************************** */ |
||
153 | void GetMeasurements(void) |
||
154 | { |
||
155 | ANALOG_OFF; |
||
973 | MikeW | 156 | AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt; |
157 | AverageNick = AccumulatedNick / AccumulatedNick_cnt; |
||
158 | AverageGier = AccumulatedGier / AccumulatedGier_cnt; |
||
966 | MikeW | 159 | |
160 | /* Get Pressure Differenz */ |
||
161 | CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt; |
||
162 | AccumulatedAirPressure_cnt = 0; |
||
163 | AccumulatedAirPressure = 0; |
||
164 | |||
165 | static char AirPressureCnt = 0; |
||
166 | if (AirPressureCnt % 25 == 1) |
||
167 | { |
||
168 | DeltaAltitude = CurrentAltitude - LastAltitude; |
||
169 | LastAltitude = CurrentAltitude; |
||
170 | } |
||
171 | AirPressureCnt++; |
||
983 | MikeW | 172 | |
173 | if(modell_fliegt < 0x250) |
||
966 | MikeW | 174 | { |
983 | MikeW | 175 | //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10)) |
176 | AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw; |
||
177 | AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw; |
||
178 | if (abs(StickGier) < 15 || MotorenEin == 0) |
||
179 | { |
||
180 | AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw; |
||
181 | } |
||
182 | } |
||
183 | else if(modell_fliegt < 0x2000) |
||
184 | { |
||
185 | //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10)) |
||
973 | MikeW | 186 | AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw; |
187 | AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw; |
||
966 | MikeW | 188 | if (abs(StickGier) < 15 || MotorenEin == 0) |
189 | { |
||
983 | MikeW | 190 | AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw; |
966 | MikeW | 191 | } |
192 | } |
||
983 | MikeW | 193 | else |
194 | { |
||
195 | AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw; |
||
196 | AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw; |
||
197 | if (abs(StickGier) < 15 || MotorenEin == 0) |
||
198 | { |
||
199 | AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw; |
||
200 | } |
||
201 | } |
||
966 | MikeW | 202 | |
203 | #if 1 |
||
973 | MikeW | 204 | DebugOut.Analog[6] = AdWertNick_Raw; |
205 | DebugOut.Analog[7] = AdWertRoll_Raw; |
||
206 | DebugOut.Analog[8] = AdWertGier_Raw; |
||
207 | |||
208 | DebugOut.Analog[9] = AdNeutralNick; |
||
209 | DebugOut.Analog[10] = AdNeutralRoll; |
||
210 | DebugOut.Analog[11] = AdNeutralGier; |
||
966 | MikeW | 211 | #endif |
983 | MikeW | 212 | |
973 | MikeW | 213 | AccumulatedRoll = 0; |
214 | AccumulatedRoll_cnt = 0; |
||
215 | AccumulatedNick = 0; |
||
216 | AccumulatedNick_cnt = 0; |
||
217 | AccumulatedGier = 0; |
||
218 | AccumulatedGier_cnt = 0; |
||
966 | MikeW | 219 | |
220 | #if 0 |
||
221 | ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt); |
||
222 | ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt); |
||
223 | ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt); |
||
224 | #endif |
||
225 | |||
226 | AveragerACC_X = AccumulatedACC_X / AccumulatedACC_X_cnt; |
||
227 | AveragerACC_Y = AccumulatedACC_Y / AccumulatedACC_Y_cnt; |
||
228 | AveragerACC_Z = AccumulatedACC_Z / AccumulatedACC_Z_cnt; |
||
229 | |||
230 | AccumulatedACC_X = 0; |
||
231 | AccumulatedACC_X_cnt = 0; |
||
232 | AccumulatedACC_Y = 0; |
||
233 | AccumulatedACC_Y_cnt = 0; |
||
234 | AccumulatedACC_Z = 0; |
||
235 | AccumulatedACC_Z_cnt = 0; |
||
236 | |||
237 | ANALOG_ON; |
||
238 | } |
||
239 | |||
240 | /* **************************************************************************** |
||
241 | Functionname: SendMotorData */ /*! |
||
242 | Description: Senden der Motorwerte per I2C-Bus |
||
243 | |||
244 | @return void |
||
245 | @pre - |
||
246 | @post - |
||
247 | @author H. Buss / I. Busker |
||
248 | **************************************************************************** */ |
||
249 | void SendMotorData(void) |
||
250 | { |
||
251 | if(!MotorenEin) |
||
252 | { |
||
253 | Motor_Hinten = 0; |
||
254 | Motor_Vorne = 0; |
||
255 | Motor_Rechts = 0; |
||
256 | Motor_Links = 0; |
||
257 | if(MotorTest[0]) Motor_Vorne = MotorTest[0]; |
||
258 | if(MotorTest[1]) Motor_Hinten = MotorTest[1]; |
||
259 | if(MotorTest[2]) Motor_Links = MotorTest[2]; |
||
260 | if(MotorTest[3]) Motor_Rechts = MotorTest[3]; |
||
261 | } |
||
262 | |||
263 | //Start I2C Interrupt Mode |
||
264 | twi_state = 0; |
||
265 | motor = 0; |
||
266 | i2c_start(); |
||
267 | } |
||
268 | |||
269 | |||
270 | /* **************************************************************************** |
||
271 | Functionname: RemoteControl */ /*! |
||
272 | Description: |
||
273 | |||
274 | @return void |
||
275 | @pre - |
||
276 | @post - |
||
277 | @author H. Buss / I. Busker |
||
278 | **************************************************************************** */ |
||
279 | void RemoteControl(void) |
||
280 | { |
||
281 | static unsigned char delay_neutral = 0; |
||
282 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
||
283 | |||
284 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
285 | // Gaswert ermitteln |
||
286 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
287 | GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120; |
||
288 | if(GasMischanteil < 0) |
||
289 | { |
||
290 | GasMischanteil = 0; |
||
291 | } |
||
292 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
293 | // Emfang schlecht |
||
294 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
295 | if(SenderOkay < 100) |
||
296 | { |
||
297 | if(!PcZugriff) |
||
298 | { |
||
299 | if(BeepMuster == 0xffff) |
||
300 | { |
||
301 | beeptime = 15000; |
||
302 | BeepMuster = 0x0c00; |
||
303 | } |
||
304 | } |
||
305 | } |
||
306 | else |
||
307 | { |
||
308 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
309 | // Emfang gut |
||
310 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
311 | if(SenderOkay > 140) |
||
312 | { |
||
313 | if(GasMischanteil > 40) |
||
314 | { |
||
315 | if(modell_fliegt < 0xffff) |
||
316 | { |
||
317 | modell_fliegt++; |
||
318 | } |
||
319 | } |
||
320 | |||
321 | |||
322 | if((GasMischanteil > 200) && |
||
323 | (MotorenEin == 0)) |
||
324 | { |
||
325 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
326 | // auf Nullwerte kalibrieren |
||
327 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
328 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
||
329 | { |
||
330 | if(++delay_neutral > 50) // nicht sofort |
||
331 | { |
||
332 | MotorenEin = 0; |
||
333 | delay_neutral = 0; |
||
334 | modell_fliegt = 0; |
||
335 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
||
336 | { |
||
337 | if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750)) |
||
338 | { |
||
339 | SucheLuftruckOffset(); |
||
340 | } |
||
341 | } |
||
342 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
||
343 | SetNeutral(); |
||
344 | } |
||
345 | } |
||
346 | else |
||
347 | { |
||
348 | delay_neutral = 0; |
||
349 | } |
||
350 | } |
||
351 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
352 | // Gas ist unten |
||
353 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
354 | if(GasMischanteil < 35) |
||
355 | { |
||
356 | // Starten |
||
357 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) |
||
358 | { |
||
359 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
360 | // Einschalten |
||
361 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
362 | if(++delay_einschalten > 100) |
||
363 | { |
||
364 | MotorenEin = 1; |
||
365 | modell_fliegt = 1; |
||
366 | delay_einschalten = 100; |
||
367 | } |
||
368 | } |
||
369 | else |
||
370 | { |
||
371 | delay_einschalten = 0; |
||
372 | } |
||
373 | //Auf Neutralwerte setzen |
||
374 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
375 | // Auschalten |
||
376 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
377 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) |
||
378 | { |
||
379 | if(++delay_ausschalten > 50) // nicht sofort |
||
380 | { |
||
381 | MotorenEin = 0; |
||
382 | modell_fliegt = 0; |
||
383 | delay_ausschalten = 50; |
||
384 | } |
||
385 | } |
||
386 | else |
||
387 | { |
||
388 | delay_ausschalten = 0; |
||
389 | } |
||
390 | } |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | |||
395 | |||
396 | |||
397 | |||
398 | /* **************************************************************************** |
||
399 | Functionname: PD_Regler */ /*! |
||
400 | Description: |
||
401 | |||
402 | @return void |
||
403 | @pre - |
||
404 | @post - |
||
405 | @author Michael Walter |
||
406 | **************************************************************************** */ |
||
407 | void PD_Regler(void) |
||
408 | { |
||
409 | int StickNick45,StickRoll45; |
||
410 | int DiffNick,DiffRoll, DiffGier; |
||
411 | int motorwert = 0; |
||
412 | int pd_ergebnis; |
||
413 | |||
414 | /***************************************************************************** |
||
415 | Update noimial attitude |
||
416 | **************************************************************************** */ |
||
417 | if(!NewPpmData--) |
||
418 | { |
||
419 | StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4; |
||
420 | StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4; |
||
421 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
||
422 | } // Ende neue Funken-Werte |
||
423 | |||
424 | #ifdef USE_GPS |
||
425 | /* G P S U p d a t e */ |
||
426 | GPSupdate(); |
||
427 | #endif |
||
428 | |||
429 | static float AverageGasMischanteil = 50.F; |
||
430 | if((GasMischanteil > 30) && |
||
431 | (MotorenEin == 1) && |
||
432 | (RemoteLinkLost == 0) ) |
||
433 | { /* Average the average throttle to find the hover setting */ |
||
434 | AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil; |
||
435 | } |
||
436 | /* Overide GasMischanteil */ |
||
437 | static unsigned int DescentCnt = 32000; |
||
438 | if ((RemoteLinkLost == 1) && |
||
439 | (MotorenEin == 1)) |
||
440 | { |
||
441 | if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/ |
||
442 | (maxDistance / 10 < 12)) /* we reached our target position */ |
||
443 | { |
||
444 | if (DescentCnt > 0) |
||
445 | { |
||
446 | DescentCnt--; |
||
447 | } |
||
448 | else |
||
449 | { /* We reached our target (hopefully) */ |
||
450 | MotorenEin = 0; |
||
451 | RemoteLinkLost = 0; |
||
452 | } |
||
453 | } |
||
454 | else |
||
455 | { |
||
456 | DescentCnt = 32000; |
||
457 | } |
||
458 | /* Bias the throttle for a slow descent */ |
||
459 | GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F)); |
||
460 | } |
||
461 | else |
||
462 | { |
||
463 | DescentCnt = 32000; |
||
464 | } |
||
465 | |||
466 | //DebugOut.Analog[13] = (int) GasMischanteil; |
||
467 | |||
972 | MikeW | 468 | #ifdef X_FORMATION |
966 | MikeW | 469 | /* Overide in case the remote link got lost */ |
470 | if (RemoteLinkLost == 0) |
||
471 | { /* We are flying in X-Formation */ |
||
472 | StickRoll45 = (int) (0.707F * (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick)); |
||
473 | StickNick45 = (int) (0.707F * (float)(StickRoll - GPS_Roll) + 0.707F * (float)(StickNick - GPS_Nick)); |
||
474 | } |
||
475 | else |
||
476 | { /* GPS overide is aktive */ |
||
477 | StickRoll45 = (int) (0.707F * (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick)); |
||
478 | StickNick45 = (int) (0.707F * (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick)); |
||
479 | StickGier = 0; |
||
480 | } |
||
972 | MikeW | 481 | #else |
482 | /* Overide in case the remote link got lost */ |
||
483 | if (RemoteLinkLost == 0) |
||
484 | { /* We are flying in X-Formation */ |
||
485 | StickRoll45 = StickRoll - GPS_Roll; |
||
486 | StickNick45 = StickNick - GPS_Nick; |
||
487 | } |
||
488 | else |
||
489 | { /* GPS overide is aktive */ |
||
490 | StickRoll45 = -GPS_Roll; |
||
491 | StickNick45 = -GPS_Nick; |
||
492 | StickGier = 0; |
||
493 | } |
||
494 | #endif |
||
495 | |||
966 | MikeW | 496 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
497 | // Yaw |
||
498 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
499 | |||
500 | if(GasMischanteil < 20) |
||
501 | { |
||
502 | sollGier = status.iPsi10; |
||
503 | SummeRoll = 0; |
||
504 | SummeNick = 0; |
||
505 | } |
||
506 | |||
507 | /* Gier-Anteil */ |
||
508 | if (abs(StickGier) > 4) |
||
509 | { |
||
510 | sollGier = status.iPsi10 + 4 * StickGier; |
||
511 | } |
||
512 | DiffGier = (sollGier - status.iPsi10); |
||
973 | MikeW | 513 | GierMischanteil = (int) (-4 * DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10; |
966 | MikeW | 514 | |
515 | #define MUL_G 0.8 |
||
516 | if(GierMischanteil > MUL_G * GasMischanteil) |
||
517 | { |
||
518 | GierMischanteil = MUL_G * GasMischanteil; |
||
519 | } |
||
520 | if(GierMischanteil < -MUL_G * GasMischanteil) |
||
521 | { |
||
522 | GierMischanteil = -MUL_G * GasMischanteil; |
||
523 | } |
||
524 | if(GierMischanteil > 50) |
||
525 | { |
||
526 | GierMischanteil = 50; |
||
527 | } |
||
528 | if(GierMischanteil < -50) |
||
529 | { |
||
530 | GierMischanteil = -50; |
||
531 | } |
||
532 | |||
533 | /***************************************************************************** |
||
534 | PD-Control |
||
535 | **************************************************************************** */ |
||
536 | int scale_p; |
||
537 | int scale_d; |
||
538 | |||
539 | scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20); |
||
540 | scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20); |
||
541 | |||
542 | scale_p = 6; |
||
543 | scale_d = 7; |
||
544 | |||
545 | //DebugOut.Analog[14] = scale_p; |
||
546 | //DebugOut.Analog[15] = scale_d; |
||
547 | |||
548 | /* Pitch */ |
||
549 | DiffNick = -(status.iTheta10 + StickNick45); |
||
550 | /* R o l l */ |
||
551 | DiffRoll = -(status.iPhi10 + StickRoll45); |
||
552 | |||
553 | SummeNick += DiffNick; |
||
554 | if(SummeNick > 10000) |
||
555 | { |
||
556 | SummeNick = 10000; |
||
557 | } |
||
558 | if(SummeNick < -10000) |
||
559 | { |
||
560 | SummeNick = -10000; |
||
561 | } |
||
562 | |||
563 | SummeRoll += DiffRoll; |
||
564 | if(SummeRoll > 10000) |
||
565 | { |
||
566 | SummeRoll = 10000; |
||
567 | } |
||
568 | if(SummeRoll < -10000) |
||
569 | { |
||
570 | SummeRoll = -10000; |
||
571 | } |
||
572 | |||
973 | MikeW | 573 | pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); |
966 | MikeW | 574 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
575 | { |
||
576 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
||
577 | } |
||
578 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
||
579 | { |
||
580 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
||
581 | } |
||
582 | |||
583 | /* M o t o r V o r n */ |
||
584 | motorwert = GasMischanteil + pd_ergebnis + GierMischanteil; |
||
585 | if ((motorwert < 0)) |
||
586 | { |
||
587 | motorwert = 0; |
||
588 | } |
||
589 | else if(motorwert > MAX_GAS) |
||
590 | { |
||
591 | motorwert = MAX_GAS; |
||
592 | } |
||
593 | if (motorwert < MIN_GAS) |
||
594 | { |
||
595 | motorwert = MIN_GAS; |
||
596 | } |
||
597 | Motor_Vorne = motorwert; |
||
598 | |||
599 | /* M o t o r H e c k */ |
||
600 | motorwert = GasMischanteil - pd_ergebnis + GierMischanteil; |
||
601 | if ((motorwert < 0)) |
||
602 | { |
||
603 | motorwert = 0; |
||
604 | } |
||
605 | else if(motorwert > MAX_GAS) |
||
606 | { |
||
607 | motorwert = MAX_GAS; |
||
608 | } |
||
609 | if (motorwert < MIN_GAS) |
||
610 | { |
||
611 | motorwert = MIN_GAS; |
||
612 | } |
||
613 | Motor_Hinten = motorwert; |
||
614 | |||
973 | MikeW | 615 | pd_ergebnis = ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000); |
966 | MikeW | 616 | if(pd_ergebnis > (GasMischanteil + abs(GierMischanteil))) |
617 | { |
||
618 | pd_ergebnis = (GasMischanteil + abs(GierMischanteil)); |
||
619 | } |
||
620 | if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil))) |
||
621 | { |
||
622 | pd_ergebnis = -(GasMischanteil + abs(GierMischanteil)); |
||
623 | } |
||
624 | |||
625 | /* M o t o r L i n k s */ |
||
626 | motorwert = GasMischanteil + pd_ergebnis - GierMischanteil; |
||
627 | if(motorwert > MAX_GAS) |
||
628 | { |
||
629 | motorwert = MAX_GAS; |
||
630 | } |
||
631 | if (motorwert < MIN_GAS) |
||
632 | { |
||
633 | motorwert = MIN_GAS; |
||
634 | } |
||
635 | Motor_Links = motorwert; |
||
636 | |||
637 | /* M o t o r R e c h t s */ |
||
638 | motorwert = GasMischanteil - pd_ergebnis - GierMischanteil; |
||
639 | if(motorwert > MAX_GAS) |
||
640 | { |
||
641 | motorwert = MAX_GAS; |
||
642 | } |
||
643 | if (motorwert < MIN_GAS) |
||
644 | { |
||
645 | motorwert = MIN_GAS; |
||
646 | } |
||
647 | Motor_Rechts = motorwert; |
||
648 | |||
649 | #if 1 |
||
650 | DebugOut.Analog[0] = status.iTheta10; |
||
651 | DebugOut.Analog[1] = status.iPhi10; |
||
652 | DebugOut.Analog[2] = status.iPsi10 / 10; |
||
653 | #endif |
||
654 | } |