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