Rev 2167 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2167 | Rev 2172 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Flight Control |
2 | Flight Control |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
Line 172... | Line 172... | ||
172 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
172 | volatile unsigned char FC_StatusFlags = 0, FC_StatusFlags2 = 0; |
173 | long GIER_GRAD_FAKTOR = 1291; |
173 | long GIER_GRAD_FAKTOR = 1291; |
174 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
174 | signed int KopplungsteilNickRoll,KopplungsteilRollNick; |
175 | signed int tmp_motorwert[MAX_MOTORS]; |
175 | signed int tmp_motorwert[MAX_MOTORS]; |
176 | char VarioCharacter = ' '; |
176 | char VarioCharacter = ' '; |
177 | unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
177 | unsigned int HoverGasEmergencyPercent = 0; // The gas value for Emergency landing |
- | 178 | ||
- | 179 | static int HoehenRegelung(int GasMischanteil); |
|
Line 178... | Line 180... | ||
178 | 180 | ||
179 | #define LIMIT_MIN(value, min) {if(value <= min) value = min;} |
181 | #define LIMIT_MIN(value, min) {if(value <= min) value = min;} |
180 | #define LIMIT_MAX(value, max) {if(value >= max) value = max;} |
182 | #define LIMIT_MAX(value, max) {if(value >= max) value = max;} |
Line 184... | Line 186... | ||
184 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
186 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
185 | // Debugwerte zuordnen |
187 | // Debugwerte zuordnen |
186 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
188 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
187 | void CopyDebugValues(void) |
189 | void CopyDebugValues(void) |
188 | { |
190 | { |
189 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
191 | DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4); |
190 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
192 | DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4); |
191 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
193 | DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
192 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
194 | DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
193 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
195 | DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
194 | DebugOut.Analog[5] = HoehenWert/5; |
196 | DebugOut.Analog[5] = HoehenWert/5; |
195 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
197 | DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az; |
196 | DebugOut.Analog[8] = KompassValue; |
198 | DebugOut.Analog[8] = KompassValue; |
197 | DebugOut.Analog[9] = UBat; |
199 | DebugOut.Analog[9] = UBat; |
198 | DebugOut.Analog[10] = SenderOkay; |
200 | DebugOut.Analog[10] = SenderOkay; |
199 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
201 | DebugOut.Analog[11] = ErsatzKompassInGrad; |
200 | DebugOut.Analog[12] = Motor[0].SetPoint; |
202 | DebugOut.Analog[12] = Motor[0].SetPoint; |
201 | DebugOut.Analog[13] = Motor[1].SetPoint; |
203 | DebugOut.Analog[13] = Motor[1].SetPoint; |
202 | DebugOut.Analog[14] = Motor[2].SetPoint; |
204 | DebugOut.Analog[14] = Motor[2].SetPoint; |
203 | DebugOut.Analog[15] = Motor[3].SetPoint; |
205 | DebugOut.Analog[15] = Motor[3].SetPoint; |
204 | DebugOut.Analog[20] = ServoNickValue; |
206 | DebugOut.Analog[20] = ServoNickValue; |
205 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
207 | DebugOut.Analog[22] = Capacity.ActualCurrent; |
206 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
208 | DebugOut.Analog[23] = Capacity.UsedCapacity; |
207 | DebugOut.Analog[24] = SollHoehe/5; |
209 | DebugOut.Analog[24] = SollHoehe/5; |
208 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
210 | // DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
209 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
211 | // DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
210 | DebugOut.Analog[27] = KompassSollWert; |
212 | DebugOut.Analog[27] = KompassSollWert; |
211 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
213 | DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
212 | DebugOut.Analog[30] = GPS_Nick; |
214 | DebugOut.Analog[30] = GPS_Nick; |
213 | DebugOut.Analog[31] = GPS_Roll; |
215 | DebugOut.Analog[31] = GPS_Roll; |
214 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
216 | if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
215 | } |
217 | } |
Line 216... | Line 218... | ||
216 | 218 | ||
217 | 219 | ||
218 | 220 | ||
219 | void Piep(unsigned char Anzahl, unsigned int dauer) |
221 | void Piep(unsigned char Anzahl, unsigned int dauer) |
220 | { |
222 | { |
221 | if(MotorenEin) return; //auf keinen Fall im Flug! |
223 | if(MotorenEin) return; //auf keinen Fall im Flug! |
222 | GRN_OFF; |
224 | GRN_OFF; |
223 | while(Anzahl--) |
225 | while(Anzahl--) |
224 | { |
226 | { |
225 | beeptime = dauer; |
227 | beeptime = dauer; |
226 | while(beeptime); |
228 | while(beeptime); |
227 | Delay_ms(dauer * 2); |
229 | Delay_ms(dauer * 2); |
Line 228... | Line 230... | ||
228 | } |
230 | } |
229 | GRN_ON; |
231 | GRN_ON; |
230 | } |
232 | } |
231 | 233 | ||
232 | //############################################################################ |
234 | //############################################################################ |
233 | // Messwerte beim Ermitteln der Nullage |
235 | // Messwerte beim Ermitteln der Nullage |
234 | void CalibrierMittelwert(void) |
236 | void CalibrierMittelwert(void) |
235 | //############################################################################ |
237 | //############################################################################ |
236 | { |
238 | { |
237 | unsigned char i; |
239 | unsigned char i; |
238 | if(PlatinenVersion == 13) SucheGyroOffset(); |
240 | if(PlatinenVersion == 13) SucheGyroOffset(); |
239 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
241 | // ADC auschalten, damit die Werte sich nicht während der Berechnung ändern |
240 | ANALOG_OFF; |
242 | ANALOG_OFF; |
241 | MesswertNick = AdWertNick; |
243 | MesswertNick = AdWertNick; |
242 | MesswertRoll = AdWertRoll; |
244 | MesswertRoll = AdWertRoll; |
243 | MesswertGier = AdWertGier; |
245 | MesswertGier = AdWertGier; |
244 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
246 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
245 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
247 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
246 | // ADC einschalten |
248 | // ADC einschalten |
247 | ANALOG_ON; |
249 | ANALOG_ON; |
248 | for(i=0;i<8;i++) |
250 | for(i=0;i<8;i++) |
249 | { |
251 | { |
250 | int tmp; |
252 | int tmp; |
251 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
253 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
252 | LIMIT_MIN_MAX(tmp, 0, 255); |
254 | LIMIT_MIN_MAX(tmp, 0, 255); |
253 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
255 | if(Poti[i] > tmp) Poti[i]--; else if(Poti[i] < tmp) Poti[i]++; |
Line 261... | Line 263... | ||
261 | void SetNeutral(unsigned char AccAdjustment) |
263 | void SetNeutral(unsigned char AccAdjustment) |
262 | //############################################################################ |
264 | //############################################################################ |
263 | { |
265 | { |
264 | unsigned char i; |
266 | unsigned char i; |
265 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
267 | unsigned int gier_neutral=0, nick_neutral=0, roll_neutral=0; |
266 | VersionInfo.HardwareError[0] = 0; |
268 | VersionInfo.HardwareError[0] = 0; |
267 | // HEF4017Reset_ON; |
269 | // HEF4017Reset_ON; |
268 | NeutralAccX = 0; |
270 | NeutralAccX = 0; |
269 | NeutralAccY = 0; |
271 | NeutralAccY = 0; |
270 | NeutralAccZ = 0; |
272 | NeutralAccZ = 0; |
271 | 273 | ||
272 | AdNeutralNick = 0; |
274 | AdNeutralNick = 0; |
273 | AdNeutralRoll = 0; |
275 | AdNeutralRoll = 0; |
274 | AdNeutralGier = 0; |
276 | AdNeutralGier = 0; |
275 | 277 | ||
276 | Parameter_AchsKopplung1 = 0; |
278 | Parameter_AchsKopplung1 = 0; |
277 | Parameter_AchsKopplung2 = 0; |
279 | Parameter_AchsKopplung2 = 0; |
278 | 280 | ||
279 | ExpandBaro = 0; |
281 | ExpandBaro = 0; |
280 | - | ||
281 | CalibrierMittelwert(); |
- | |
282 | Delay_ms_Mess(100); |
- | |
283 | 282 | ||
284 | CalibrierMittelwert(); |
283 | CalibrierMittelwert(); |
- | 284 | Delay_ms_Mess(100); |
|
285 | 285 | ||
- | 286 | CalibrierMittelwert(); |
|
- | 287 | ||
286 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
288 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
287 | { |
289 | { |
288 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
290 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
289 | } |
291 | } |
290 | #define NEUTRAL_FILTER 32 |
292 | #define NEUTRAL_FILTER 32 |
291 | for(i=0; i<NEUTRAL_FILTER; i++) |
293 | for(i=0; i<NEUTRAL_FILTER; i++) |
292 | { |
294 | { |
293 | Delay_ms_Mess(10); |
295 | Delay_ms_Mess(10); |
294 | gier_neutral += AdWertGier; |
296 | gier_neutral += AdWertGier; |
295 | nick_neutral += AdWertNick; |
297 | nick_neutral += AdWertNick; |
296 | roll_neutral += AdWertRoll; |
298 | roll_neutral += AdWertRoll; |
297 | } |
299 | } |
298 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
300 | AdNeutralNick= (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
299 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
301 | AdNeutralRoll= (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8); |
300 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
302 | AdNeutralGier= (gier_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER); |
301 | 303 | ||
302 | StartNeutralRoll = AdNeutralRoll; |
304 | StartNeutralRoll = AdNeutralRoll; |
303 | StartNeutralNick = AdNeutralNick; |
305 | StartNeutralNick = AdNeutralNick; |
304 | 306 | ||
305 | if(AccAdjustment) |
307 | if(AccAdjustment) |
306 | { |
308 | { |
307 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
309 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
308 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
310 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
309 | NeutralAccZ = Aktuell_az; |
311 | NeutralAccZ = Aktuell_az; |
310 | 312 | ||
311 | // Save ACC neutral settings to eeprom |
313 | // Save ACC neutral settings to eeprom |
312 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
314 | SetParamWord(PID_ACC_NICK, (uint16_t)NeutralAccX); |
313 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
315 | SetParamWord(PID_ACC_ROLL, (uint16_t)NeutralAccY); |
314 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
316 | SetParamWord(PID_ACC_TOP, (uint16_t)NeutralAccZ); |
315 | } |
317 | } |
316 | else |
318 | else |
317 | { |
319 | { |
318 | // restore from eeprom |
320 | // restore from eeprom |
319 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
321 | NeutralAccX = (int16_t)GetParamWord(PID_ACC_NICK); |
320 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
322 | NeutralAccY = (int16_t)GetParamWord(PID_ACC_ROLL); |
321 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
323 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
322 | // strange settings? |
324 | // strange settings? |
323 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
325 | if(((unsigned int) NeutralAccX > 2048) || ((unsigned int) NeutralAccY > 2048) || ((unsigned int) NeutralAccZ > 1024)) |
324 | { |
326 | { |
325 | printf("\n\rACC not calibrated!\r\n"); |
327 | printf("\n\rACC not calibrated!\r\n"); |
326 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
328 | NeutralAccX = abs(Mittelwert_AccNick) / (2*ACC_AMPLIFY); |
327 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
329 | NeutralAccY = abs(Mittelwert_AccRoll) / (2*ACC_AMPLIFY); |
328 | NeutralAccZ = Aktuell_az; |
330 | NeutralAccZ = Aktuell_az; |
329 | } |
331 | } |
330 | } |
332 | } |
331 | 333 | ||
332 | MesswertNick = 0; |
334 | MesswertNick = 0; |
333 | MesswertRoll = 0; |
335 | MesswertRoll = 0; |
334 | MesswertGier = 0; |
336 | MesswertGier = 0; |
335 | Delay_ms_Mess(100); |
337 | Delay_ms_Mess(100); |
336 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
338 | Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick; |
337 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
339 | Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll; |
338 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
340 | IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
339 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
341 | IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
340 | Mess_IntegralNick = IntegralNick; |
342 | Mess_IntegralNick = IntegralNick; |
341 | Mess_IntegralRoll = IntegralRoll; |
343 | Mess_IntegralRoll = IntegralRoll; |
342 | Mess_Integral_Gier = 0; |
344 | Mess_Integral_Gier = 0; |
343 | StartLuftdruck = Luftdruck; |
345 | StartLuftdruck = Luftdruck; |
344 | VarioMeter = 0; |
346 | VarioMeter = 0; |
345 | Mess_Integral_Hoch = 0; |
347 | Mess_Integral_Hoch = 0; |
346 | KompassSollWert = KompassValue; |
348 | KompassSollWert = KompassValue; |
347 | KompassSignalSchlecht = 100; |
349 | KompassSignalSchlecht = 100; |
348 | beeptime = 50; |
350 | beeptime = 50; |
349 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
351 | Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L; |
350 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
352 | Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L; |
351 | ExternHoehenValue = 0; |
353 | ExternHoehenValue = 0; |
352 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
354 | ErsatzKompass = KompassValue * GIER_GRAD_FAKTOR; |
353 | GierGyroFehler = 0; |
355 | GierGyroFehler = 0; |
354 | LED_Init(); |
356 | LED_Init(); |
355 | FC_StatusFlags |= FC_STATUS_CALIBRATE; |
357 | FC_StatusFlags |= FC_STATUS_CALIBRATE; |
356 | FromNaviCtrl_Value.Kalman_K = -1; |
358 | FromNaviCtrl_Value.Kalman_K = -1; |
357 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
359 | FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
358 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
360 | FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
359 | for(i=0;i<8;i++) |
361 | for(i=0;i<8;i++) |
360 | { |
362 | { |
361 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
363 | Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
362 | } |
364 | } |
363 | SenderOkay = 100; |
365 | SenderOkay = 100; |
364 | if(ServoActive) |
366 | if(ServoActive) |
365 | { |
367 | { |
366 | // HEF4017Reset_ON; |
368 | // HEF4017Reset_ON; |
367 | DDRD |=0x80; // enable J7 -> Servo signal |
369 | DDRD |=0x80; // enable J7 -> Servo signal |
368 | } |
370 | } |
369 | 371 | ||
370 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
372 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
371 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
373 | if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
372 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
374 | if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
373 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
375 | if((NeutralAccX < 300) || (NeutralAccX > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_NICK; }; |
374 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
376 | if((NeutralAccY < 300) || (NeutralAccY > 750)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_ROLL; }; |
375 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
377 | if((NeutralAccZ < 512) || (NeutralAccZ > 850)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; }; |
376 | carefree_old = 70; |
378 | carefree_old = 70; |
377 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
379 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
378 | LIBFC_HoTT_Clear(); |
380 | LIBFC_HoTT_Clear(); |
379 | #endif |
381 | #endif |
380 | } |
382 | } |
Line 381... | Line 383... | ||
381 | 383 | ||
382 | 384 | ||
383 | //############################################################################ |
385 | //############################################################################ |
384 | // Bearbeitet die Messwerte |
386 | // Bearbeitet die Messwerte |
385 | void Mittelwert(void) |
387 | void Mittelwert(void) |
386 | //############################################################################ |
388 | //############################################################################ |
387 | { |
389 | { |
388 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
390 | static signed long tmpl,tmpl2,tmpl3,tmpl4; |
389 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
391 | static signed int oldNick, oldRoll, d2Roll, d2Nick; |
390 | signed long winkel_nick, winkel_roll; |
392 | signed long winkel_nick, winkel_roll; |
391 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
393 | MesswertGier = (signed int) AdNeutralGier - AdWertGier; |
392 | MesswertNick = (signed int) AdWertNickFilter / 8; |
394 | MesswertNick = (signed int) AdWertNickFilter / 8; |
393 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
395 | MesswertRoll = (signed int) AdWertRollFilter / 8; |
394 | RohMesswertNick = MesswertNick; |
396 | RohMesswertNick = MesswertNick; |
395 | RohMesswertRoll = MesswertRoll; |
397 | RohMesswertRoll = MesswertRoll; |
396 | 398 | ||
397 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
399 | // Beschleunigungssensor ++++++++++++++++++++++++++++++++++++++++++++++++ |
398 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
400 | Mittelwert_AccNick = (Mittelwert_AccNick * 3 + ((ACC_AMPLIFY * AdWertAccNick))) / 4L; |
399 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
401 | Mittelwert_AccRoll = (Mittelwert_AccRoll * 3 + ((ACC_AMPLIFY * AdWertAccRoll))) / 4L; |
400 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
402 | IntegralAccNick += ACC_AMPLIFY * AdWertAccNick; |
401 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
403 | IntegralAccRoll += ACC_AMPLIFY * AdWertAccRoll; |
402 | NaviAccNick += AdWertAccNick; |
404 | NaviAccNick += AdWertAccNick; |
403 | NaviAccRoll += AdWertAccRoll; |
405 | NaviAccRoll += AdWertAccRoll; |
404 | NaviCntAcc++; |
406 | NaviCntAcc++; |
405 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
407 | IntegralAccZ += Aktuell_az - NeutralAccZ; |
406 | 408 | ||
407 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
409 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
408 | // ADC einschalten |
410 | // ADC einschalten |
409 | ANALOG_ON; |
411 | ANALOG_ON; |
410 | AdReady = 0; |
412 | AdReady = 0; |
411 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
413 | //++++++++++++++++++++++++++++++++++++++++++++++++ |
412 | 414 | ||
413 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
415 | if(Mess_IntegralRoll > 93000L) winkel_roll = 93000L; |
414 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
416 | else if(Mess_IntegralRoll <-93000L) winkel_roll = -93000L; |
415 | else winkel_roll = Mess_IntegralRoll; |
417 | else winkel_roll = Mess_IntegralRoll; |
416 | 418 | ||
417 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
419 | if(Mess_IntegralNick > 93000L) winkel_nick = 93000L; |
527 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
529 | else if(RohMesswertRoll < -256) MesswertRoll += 1 * (RohMesswertRoll + 256); |
Line 528... | Line 530... | ||
528 | } |
530 | } |
529 | } |
531 | } |
530 | 532 | ||
531 | //############################################################################ |
533 | //############################################################################ |
532 | // Senden der Motorwerte per I2C-Bus |
534 | // Senden der Motorwerte per I2C-Bus |
533 | void SendMotorData(void) |
535 | void SendMotorData(void) |
534 | //############################################################################ |
536 | //############################################################################ |
535 | { |
537 | { |
536 | unsigned char i; |
538 | unsigned char i; |
537 | if(!MotorenEin) |
539 | if(!MotorenEin) |
538 | { |
540 | { |
539 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
541 | FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
540 | for(i=0;i<MAX_MOTORS;i++) |
542 | for(i=0;i<MAX_MOTORS;i++) |
541 | { |
543 | { |
542 | if(!PC_MotortestActive) MotorTest[i] = 0; |
544 | if(!PC_MotortestActive) MotorTest[i] = 0; |
543 | Motor[i].SetPoint = MotorTest[i]; |
545 | Motor[i].SetPoint = MotorTest[i]; |
544 | Motor[i].SetPointLowerBits = 0; |
546 | Motor[i].SetPointLowerBits = 0; |
545 | /* |
547 | /* |
546 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
548 | Motor[i].SetPoint = MotorTest[i] / 4; // testing the high resolution |
547 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
549 | Motor[i].SetPointLowerBits = MotorTest[i] % 4; |
548 | */ |
550 | */ |
549 | } |
551 | } |
550 | if(PC_MotortestActive) PC_MotortestActive--; |
552 | if(PC_MotortestActive) PC_MotortestActive--; |
551 | } |
553 | } |
552 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
554 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
553 | 555 | ||
554 | if(I2C_TransferActive) |
556 | if(I2C_TransferActive) |
555 | { |
557 | { |
556 | I2C_TransferActive = 0; // enable for the next time |
558 | I2C_TransferActive = 0; // enable for the next time |
557 | } |
559 | } |
558 | else |
560 | else |
559 | { |
561 | { |
560 | motor_write = 0; |
562 | motor_write = 0; |
Line 561... | Line 563... | ||
561 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
563 | I2C_Start(TWI_STATE_MOTOR_TX); //Start I2C Interrupt Mode |
562 | } |
564 | } |
563 | } |
565 | } |
564 | 566 | ||
565 | 567 | ||
667 | { |
673 | { |
Line 668... | Line 674... | ||
668 | beeptime = 15000; |
674 | beeptime = 15000; |
669 | BeepMuster = 0xA400; |
675 | BeepMuster = 0xA400; |
670 | CareFree = 0; |
676 | CareFree = 0; |
671 | } |
677 | } |
672 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
678 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
673 | } |
679 | } |
674 | 680 | ||
675 | //############################################################################ |
681 | //############################################################################ |
676 | // |
682 | // |
677 | void MotorRegler(void) |
683 | void MotorRegler(void) |
678 | //############################################################################ |
684 | //############################################################################ |
679 | { |
685 | { |
680 | int pd_ergebnis_nick,pd_ergebnis_roll,tmp_int, tmp_int2; |
686 | int pd_ergebnis_nick,pd_ergebnis_roll; |
681 | int GierMischanteil,GasMischanteil; |
687 | int GierMischanteil,GasMischanteil; |
682 | static long sollGier = 0,tmp_long,tmp_long2; |
688 | static long sollGier = 0; |
683 | static long IntegralFehlerNick = 0; |
689 | static long IntegralFehlerNick = 0; |
684 | static long IntegralFehlerRoll = 0; |
690 | static long IntegralFehlerRoll = 0; |
685 | static unsigned int RcLostTimer; |
691 | static unsigned int RcLostTimer; |
686 | static unsigned char delay_neutral = 0; |
692 | static unsigned char delay_neutral = 0; |
687 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
693 | static unsigned char delay_einschalten = 0,delay_ausschalten = 0; |
688 | static signed char move_safety_switch = 0; |
694 | static signed char move_safety_switch = 0; |
689 | static long ausgleichNick, ausgleichRoll; |
695 | static long ausgleichNick, ausgleichRoll; |
690 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
696 | int IntegralNickMalFaktor,IntegralRollMalFaktor; |
691 | unsigned char i; |
697 | unsigned char i; |
692 | Mittelwert(); |
698 | Mittelwert(); |
693 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
699 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
694 | // Gaswert ermitteln |
700 | // Gaswert ermitteln |
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
696 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
702 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
- | 703 | { |
|
- | 704 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
|
- | 705 | { |
|
Line 697... | Line -... | ||
697 | { |
- | |
698 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
706 | HoverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
- | 707 | } |
|
699 | { |
708 | else HoverGasEmergencyPercent = 45; // default if the Hovergas was could not calculated yet |
700 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
709 | } else HoverGasEmergencyPercent = EE_Parameter.NotGas; |
701 | } |
710 | |
702 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
- | |
703 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
- | |
704 | 711 | GasMischanteil = StickGas; |
|
705 | GasMischanteil = StickGas; |
712 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
706 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
713 | |
707 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
714 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
708 | // Empfang schlecht |
715 | { |
709 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
710 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
717 | // Empfang schlecht |
711 | { |
718 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
712 | if(RcLostTimer) RcLostTimer--; |
719 | if(RcLostTimer) RcLostTimer--; |
713 | else |
720 | else |
714 | { |
721 | { |
715 | MotorenEin = 0; |
722 | MotorenEin = 0; |
716 | modell_fliegt = 0; |
723 | modell_fliegt = 0; |
717 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
724 | FC_StatusFlags &= ~(FC_STATUS_EMERGENCY_LANDING | FC_STATUS_FLY); |
718 | } |
725 | } |
719 | ROT_ON; |
726 | ROT_ON; |
720 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
727 | if(modell_fliegt > 1000 && Capacity.MinOfMaxPWM > 100) // wahrscheinlich in der Luft --> langsam absenken |
721 | { |
728 | { |
722 | GasMischanteil = HooverGasEmergencyPercent; |
729 | GasMischanteil = HoverGasEmergencyPercent; |
723 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
730 | FC_StatusFlags |= FC_STATUS_EMERGENCY_LANDING; |
724 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
731 | PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
725 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
732 | PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
726 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
733 | PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0; |
727 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
734 | PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0; |
728 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
735 | PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0; |
729 | } |
736 | } |
730 | else |
737 | else |
731 | { |
738 | { |
732 | MotorenEin = 0; |
739 | MotorenEin = 0; |
733 | } |
740 | } |
734 | } |
741 | } |
735 | else |
742 | else |
736 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
743 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
737 | // Emfang gut |
744 | // Emfang gut |
738 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
745 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
739 | if(SenderOkay > 140) |
746 | if(SenderOkay > 140) |
740 | { |
747 | { |
741 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
748 | FC_StatusFlags &= ~FC_STATUS_EMERGENCY_LANDING; |
742 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
749 | RcLostTimer = EE_Parameter.NotGasZeit * 50; |
743 | if(GasMischanteil > 40 && MotorenEin) |
750 | if(GasMischanteil > 40 && MotorenEin) |
744 | { |
751 | { |
- | 752 | if(modell_fliegt < 0xffff) modell_fliegt++; |
|
745 | if(modell_fliegt < 0xffff) modell_fliegt++; |
753 | } |
746 | } |
754 | if((modell_fliegt < 256)) |
747 | if((modell_fliegt < 256)) |
755 | { |
748 | { |
756 | SummeNick = 0; |
749 | SummeNick = 0; |
757 | SummeRoll = 0; |
750 | SummeRoll = 0; |
758 | sollGier = 0; |
751 | sollGier = 0; |
759 | Mess_Integral_Gier = 0; |
752 | Mess_Integral_Gier = 0; |
760 | } else |
753 | } else FC_StatusFlags |= FC_STATUS_FLY; |
761 | FC_StatusFlags |= FC_STATUS_FLY; |
754 | 762 | ||
755 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
763 | if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
756 | { |
764 | { |
757 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
765 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
758 | // auf Nullwerte kalibrieren |
766 | // auf Nullwerte kalibrieren |
759 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
767 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
760 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
768 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) // Neutralwerte |
761 | { |
769 | { |
762 | if(++delay_neutral > 200) // nicht sofort |
770 | if(++delay_neutral > 200) // nicht sofort |
763 | { |
771 | { |
764 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
772 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
765 | SpeakHoTT = SPEAK_CALIBRATE; |
773 | SpeakHoTT = SPEAK_CALIBRATE; |
766 | #endif |
774 | #endif |
767 | delay_neutral = 0; |
775 | delay_neutral = 0; |
768 | modell_fliegt = 0; |
776 | modell_fliegt = 0; |
769 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
777 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) > 70) |
770 | { |
778 | { |
771 | unsigned char setting=1; |
779 | unsigned char setting=1; |
772 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
780 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 1; |
773 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
781 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 2; |
774 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
782 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < 70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 3; |
775 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
783 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > 70) setting = 4; |
776 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
784 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] <-70 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < 70) setting = 5; |
777 | SetActiveParamSet(setting); // aktiven Datensatz merken |
785 | SetActiveParamSet(setting); // aktiven Datensatz merken |
778 | } |
786 | } |
779 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
787 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 30 && PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) |
780 | { |
788 | { |
781 | WinkelOut.CalcState = 1; |
789 | WinkelOut.CalcState = 1; |
782 | CalibrationDone = 0; |
790 | CalibrationDone = 0; |
783 | beeptime = 1000; |
791 | beeptime = 1000; |
784 | } |
792 | } |
785 | else |
793 | else |
786 | { |
794 | { |
787 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
795 | ParamSet_ReadFromEEProm(GetActiveParamSet()); |
788 | LipoDetection(0); |
796 | LipoDetection(0); |
789 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
797 | LIBFC_ReceiverInit(EE_Parameter.Receiver); |
790 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
798 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) // Höhenregelung aktiviert? |
791 | { |
799 | { |
792 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
800 | if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset(); |
793 | } |
801 | } |
794 | // ServoActive = 0; |
802 | // ServoActive = 0; |
795 | SetNeutral(0); |
803 | SetNeutral(0); |
796 | CalibrationDone = 1; |
804 | CalibrationDone = 1; |
797 | ServoActive = 1; |
805 | ServoActive = 1; |
798 | DDRD |=0x80; // enable J7 -> Servo signal |
806 | DDRD |=0x80; // enable J7 -> Servo signal |
799 | Piep(GetActiveParamSet(),120); |
807 | Piep(GetActiveParamSet(),120); |
800 | } |
808 | } |
801 | } |
809 | } |
802 | } |
810 | } |
803 | else |
811 | else |
804 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
812 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) // ACC Neutralwerte speichern |
805 | { |
813 | { |
806 | if(++delay_neutral > 200) // nicht sofort |
814 | if(++delay_neutral > 200) // nicht sofort |
807 | { |
815 | { |
808 | MotorenEin = 0; |
816 | MotorenEin = 0; |
809 | delay_neutral = 0; |
817 | delay_neutral = 0; |
810 | modell_fliegt = 0; |
818 | modell_fliegt = 0; |
811 | SetNeutral(1); |
819 | SetNeutral(1); |
812 | CalibrationDone = 1; |
820 | CalibrationDone = 1; |
813 | Piep(GetActiveParamSet(),120); |
821 | Piep(GetActiveParamSet(),120); |
814 | } |
822 | } |
815 | } |
823 | } |
816 | else delay_neutral = 0; |
824 | else delay_neutral = 0; |
817 | } |
825 | } |
818 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
826 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
819 | // Gas ist unten |
827 | // Gas ist unten |
820 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
828 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
821 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
829 | if(PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] < 35-120) |
822 | { |
830 | { |
- | 831 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
|
- | 832 | else |
|
- | 833 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
|
- | 834 | // Motoren Starten |
|
- | 835 | if(!MotorenEin) |
|
- | 836 | { |
|
823 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] > 5) move_safety_switch = 100; |
837 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
824 | else |
- | |
825 | if(PPM_diff[EE_Parameter.MotorSafetySwitch & 127] < -5) move_safety_switch = -100; |
838 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
826 | // Motoren Starten |
- | |
827 | if(!MotorenEin) |
839 | { |
828 | { |
- | |
829 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
840 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
830 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] > -10 && move_safety_switch == 100))) |
- | |
831 | { |
- | |
832 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
833 | // Einschalten |
841 | // Einschalten |
834 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
842 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
835 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
843 | if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
836 | if(++delay_einschalten > 253) |
844 | if(++delay_einschalten > 253) |
837 | { |
845 | { |
838 | delay_einschalten = 0; |
846 | delay_einschalten = 0; |
839 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
847 | if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode) |
840 | { |
848 | { |
841 | modell_fliegt = 1; |
849 | modell_fliegt = 1; |
842 | MotorenEin = 1; |
850 | MotorenEin = 1; |
843 | sollGier = 0; |
851 | sollGier = 0; |
844 | Mess_Integral_Gier = 0; |
852 | Mess_Integral_Gier = 0; |
845 | Mess_Integral_Gier2 = 0; |
853 | Mess_Integral_Gier2 = 0; |
846 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
854 | Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick; |
847 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
855 | Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll; |
848 | Mess_IntegralNick2 = IntegralNick; |
856 | Mess_IntegralNick2 = IntegralNick; |
849 | Mess_IntegralRoll2 = IntegralRoll; |
857 | Mess_IntegralRoll2 = IntegralRoll; |
850 | SummeNick = 0; |
858 | SummeNick = 0; |
851 | SummeRoll = 0; |
859 | SummeRoll = 0; |
852 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
860 | // ControlHeading = (((int) EE_Parameter.OrientationAngle * 15 + KompassValue) % 360) / 2; |
853 | NeueKompassRichtungMerken = 100; // 2 sekunden |
861 | NeueKompassRichtungMerken = 100; // 2 sekunden |
854 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
862 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
855 | SpeakHoTT = SPEAK_STARTING; |
- | |
856 | #endif |
863 | SpeakHoTT = SPEAK_STARTING; |
857 | } |
864 | #endif |
858 | else |
865 | } |
859 | { |
- | |
860 | beeptime = 1500; // indicate missing calibration |
866 | else |
- | 867 | { |
|
- | 868 | beeptime = 1500; // indicate missing calibration |
|
861 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
869 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
862 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
870 | if(!CalibrationDone) SpeakHoTT = SPEAK_ERR_CALIBARTION; |
863 | #endif |
871 | #endif |
864 | } |
872 | } |
- | 873 | } |
|
- | 874 | } |
|
- | 875 | else delay_einschalten = 0; |
|
- | 876 | } |
|
865 | } |
877 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
866 | } |
878 | // Auschalten |
867 | else delay_einschalten = 0; |
- | |
868 | } |
- | |
869 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
879 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
870 | // Auschalten |
- | |
871 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
872 | else // only if motors are running |
880 | else // only if motors are running |
873 | { |
881 | { |
874 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
882 | // if((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && (PPM_in[EE_Parameter.MotorSafetySwitch] < -75 || EE_Parameter.MotorSafetySwitch == 0)) |
875 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
883 | if((((PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75) && ((!(EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -75) || EE_Parameter.MotorSafetySwitch == 0))) |
876 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
884 | || (((EE_Parameter.GlobalConfig3 & CFG3_MOTOR_SWITCH_MODE) && PPM_in[EE_Parameter.MotorSafetySwitch] < -50 && move_safety_switch == -100))) |
877 | { |
- | |
878 | if(++delay_ausschalten > 250) // nicht sofort |
885 | { |
879 | { |
886 | if(++delay_ausschalten > 250) // nicht sofort |
880 | MotorenEin = 0; |
- | |
881 | delay_ausschalten = 0; |
887 | { |
882 | modell_fliegt = 0; |
888 | MotorenEin = 0; |
- | 889 | delay_ausschalten = 0; |
|
- | 890 | modell_fliegt = 0; |
|
883 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
891 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
884 | SpeakHoTT = SPEAK_MK_OFF; |
892 | SpeakHoTT = SPEAK_MK_OFF; |
885 | #endif |
893 | #endif |
886 | } |
894 | } |
887 | } |
895 | } |
888 | else delay_ausschalten = 0; |
896 | else delay_ausschalten = 0; |
889 | } |
897 | } |
890 | } |
898 | } |
891 | else // gas not at minimum |
899 | else // gas not at minimum |
892 | move_safety_switch = 0; |
900 | move_safety_switch = 0; |
893 | } |
901 | } |
894 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
902 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
895 | // neue Werte von der Funke |
903 | // neue Werte von der Funke |
896 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
904 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
897 | 905 | ||
898 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
906 | if(!NewPpmData-- || (FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
899 | { |
907 | { |
900 | static int stick_nick,stick_roll; |
908 | static int stick_nick,stick_roll; |
901 | unsigned char stick_p; |
909 | unsigned char stick_p; |
902 | ParameterZuordnung(); |
910 | ParameterZuordnung(); |
903 | stick_p = EE_Parameter.Stick_P; |
911 | stick_p = EE_Parameter.Stick_P; |
904 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
912 | stick_nick = (stick_nick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * stick_p) / 4; |
- | 913 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
|
- | 914 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
|
- | 915 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
|
- | 916 | ||
- | 917 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 918 | // CareFree und freie Wahl der vorderen Richtung |
|
- | 919 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 920 | if(CareFree) |
|
- | 921 | { |
|
- | 922 | signed int nick, roll; |
|
- | 923 | nick = stick_nick / 4; |
|
- | 924 | roll = stick_roll / 4; |
|
- | 925 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
|
- | 926 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
|
- | 927 | } |
|
- | 928 | else |
|
- | 929 | { |
|
- | 930 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
|
- | 931 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
|
- | 932 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
|
- | 933 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
|
- | 934 | } |
|
- | 935 | ||
- | 936 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
|
- | 937 | if(StickGier > 4) StickGier -= 4; else |
|
- | 938 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
|
- | 939 | ||
- | 940 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
|
- | 941 | { |
|
- | 942 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
|
- | 943 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
|
- | 944 | } |
|
- | 945 | ||
- | 946 | StickNick -= GPS_Nick; |
|
- | 947 | StickRoll -= GPS_Roll; |
|
- | 948 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
|
- | 949 | ||
- | 950 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
|
- | 951 | IntegralFaktor = Parameter_Gyro_I; |
|
- | 952 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
|
- | 953 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
|
- | 954 | ||
- | 955 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 956 | //+ Analoge Steuerung per Seriell |
|
- | 957 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 958 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
|
- | 959 | { |
|
- | 960 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
|
- | 961 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
|
- | 962 | StickGier += ExternControl.Gier; |
|
- | 963 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
|
- | 964 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
|
- | 965 | } |
|
- | 966 | if(StickGas < 0) StickGas = 0; |
|
- | 967 | ||
- | 968 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
|
- | 969 | ||
- | 970 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
|
- | 971 | { |
|
- | 972 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
|
- | 973 | if(MaxStickNick > 100) MaxStickNick = 100; |
|
- | 974 | } |
|
- | 975 | else MaxStickNick--; |
|
- | 976 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
|
- | 977 | { |
|
- | 978 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
|
- | 979 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
|
- | 980 | } |
|
- | 981 | else MaxStickRoll--; |
|
- | 982 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
|
- | 983 | ||
- | 984 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 985 | // Looping? |
|
- | 986 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 987 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
|
- | 988 | else |
|
- | 989 | { |
|
- | 990 | { |
|
- | 991 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
|
- | 992 | } |
|
- | 993 | } |
|
- | 994 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
|
- | 995 | else |
|
- | 996 | { |
|
- | 997 | if(Looping_Rechts) // Hysterese |
|
- | 998 | { |
|
- | 999 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
|
- | 1000 | } |
|
- | 1001 | } |
|
- | 1002 | ||
- | 1003 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
|
- | 1004 | else |
|
- | 1005 | { |
|
- | 1006 | if(Looping_Oben) // Hysterese |
|
- | 1007 | { |
|
- | 1008 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
|
- | 1009 | } |
|
- | 1010 | } |
|
- | 1011 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
|
- | 1012 | else |
|
- | 1013 | { |
|
- | 1014 | if(Looping_Unten) // Hysterese |
|
- | 1015 | { |
|
- | 1016 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
|
905 | stick_nick += PPM_diff[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_D; |
1017 | } |
906 | stick_roll = (stick_roll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * stick_p) / 4; |
1018 | } |
907 | stick_roll += PPM_diff[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_D; |
1019 | |
908 | - | ||
909 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
910 | // CareFree und freie Wahl der vorderen Richtung |
- | |
911 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1020 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
- | 1021 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
|
912 | if(CareFree) |
1022 | } // Ende neue Funken-Werte |
- | 1023 | ||
- | 1024 | if(Looping_Roll || Looping_Nick) |
|
- | 1025 | { |
|
- | 1026 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
|
913 | { |
1027 | TrichterFlug = 1; |
914 | signed int nick, roll; |
- | |
915 | nick = stick_nick / 4; |
- | |
916 | roll = stick_roll / 4; |
- | |
917 | StickNick = ((FromNC_Rotate_C * nick) + (FromNC_Rotate_S * roll)) / (32 / 4); |
- | |
918 | StickRoll = ((FromNC_Rotate_C * roll) - (FromNC_Rotate_S * nick)) / (32 / 4); |
- | |
919 | } |
- | |
920 | else |
- | |
921 | { |
- | |
922 | FromNC_Rotate_C = sintab[EE_Parameter.OrientationAngle + 6]; |
- | |
923 | FromNC_Rotate_S = sintab[EE_Parameter.OrientationAngle]; |
- | |
924 | StickNick = ((FromNC_Rotate_C * stick_nick) + (FromNC_Rotate_S * stick_roll)) / 8; |
- | |
925 | StickRoll = ((FromNC_Rotate_C * stick_roll) - (FromNC_Rotate_S * stick_nick)) / 8; |
- | |
926 | } |
- | |
927 | - | ||
928 | StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; |
- | |
929 | if(StickGier > 4) StickGier -= 4; else |
- | |
930 | if(StickGier < -4) StickGier += 4; else StickGier = 0; |
- | |
931 | - | ||
932 | if(GPS_Aid_StickMultiplikator) // in that case the GPS controls stronger |
- | |
933 | { |
- | |
934 | StickNick = (GPS_Aid_StickMultiplikator * (StickNick / 8)) / 16; |
- | |
935 | StickRoll = (GPS_Aid_StickMultiplikator * (StickRoll / 8)) / 16; |
- | |
936 | } |
- | |
937 | - | ||
938 | StickNick -= GPS_Nick; |
- | |
939 | StickRoll -= GPS_Roll; |
- | |
940 | StickGas = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 127; |
- | |
941 | - | ||
942 | GyroFaktor = (Parameter_Gyro_P + 10.0); |
- | |
943 | IntegralFaktor = Parameter_Gyro_I; |
- | |
944 | GyroFaktorGier = (Parameter_Gyro_Gier_P + 10.0); |
- | |
945 | IntegralFaktorGier = Parameter_Gyro_Gier_I; |
- | |
946 | - | ||
947 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
948 | //+ Analoge Steuerung per Seriell |
- | |
949 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
950 | if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128) |
- | |
951 | { |
- | |
952 | StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P; |
- | |
953 | StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P; |
- | |
954 | StickGier += ExternControl.Gier; |
- | |
955 | ExternHoehenValue = (int) ExternControl.Hight * (int)EE_Parameter.Hoehe_Verstaerkung; |
- | |
956 | if(ExternControl.Gas < StickGas) StickGas = ExternControl.Gas; |
- | |
957 | } |
- | |
958 | if(StickGas < 0) StickGas = 0; |
- | |
959 | - | ||
960 | if(Parameter_GlobalConfig & CFG_HEADING_HOLD) IntegralFaktor = 0; |
- | |
961 | - | ||
962 | if(abs(StickNick/STICK_GAIN) > MaxStickNick) |
- | |
963 | { |
- | |
964 | MaxStickNick = abs(StickNick)/STICK_GAIN; |
- | |
965 | if(MaxStickNick > 100) MaxStickNick = 100; |
- | |
966 | } |
- | |
967 | else MaxStickNick--; |
- | |
968 | if(abs(StickRoll/STICK_GAIN) > MaxStickRoll) |
- | |
969 | { |
- | |
970 | MaxStickRoll = abs(StickRoll)/STICK_GAIN; |
- | |
971 | if(MaxStickRoll > 100) MaxStickRoll = 100; |
- | |
972 | } |
- | |
973 | else MaxStickRoll--; |
- | |
974 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) {MaxStickNick = 0; MaxStickRoll = 0;} |
- | |
975 | - | ||
976 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
977 | // Looping? |
- | |
978 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
979 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_LINKS) Looping_Links = 1; |
- | |
980 | else |
- | |
981 | { |
- | |
982 | { |
- | |
983 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Links = 0; |
- | |
984 | } |
- | |
985 | } |
- | |
986 | if((PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_RECHTS) Looping_Rechts = 1; |
- | |
987 | else |
- | |
988 | { |
- | |
989 | if(Looping_Rechts) // Hysterese |
- | |
990 | { |
- | |
991 | if(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Rechts = 0; |
- | |
992 | } |
- | |
993 | } |
- | |
994 | - | ||
995 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_OBEN) Looping_Oben = 1; |
- | |
996 | else |
- | |
997 | { |
- | |
998 | if(Looping_Oben) // Hysterese |
- | |
999 | { |
- | |
1000 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < (EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese))) Looping_Oben = 0; |
- | |
1001 | } |
- | |
1002 | } |
- | |
1003 | if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -EE_Parameter.LoopThreshold) && EE_Parameter.BitConfig & CFG_LOOP_UNTEN) Looping_Unten = 1; |
- | |
1004 | else |
- | |
1005 | { |
- | |
1006 | if(Looping_Unten) // Hysterese |
- | |
1007 | { |
- | |
1008 | if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -(EE_Parameter.LoopThreshold - EE_Parameter.LoopHysterese)) Looping_Unten = 0; |
- | |
1009 | } |
- | |
1010 | } |
- | |
1011 | - | ||
1012 | if(Looping_Links || Looping_Rechts) Looping_Roll = 1; else Looping_Roll = 0; |
- | |
1013 | if(Looping_Oben || Looping_Unten) { Looping_Nick = 1; Looping_Roll = 0; Looping_Links = 0; Looping_Rechts = 0;} else Looping_Nick = 0; |
- | |
1014 | } // Ende neue Funken-Werte |
- | |
1015 | - | ||
1016 | if(Looping_Roll || Looping_Nick) |
- | |
1017 | { |
- | |
1018 | if(GasMischanteil > EE_Parameter.LoopGasLimit) GasMischanteil = EE_Parameter.LoopGasLimit; |
- | |
1019 | TrichterFlug = 1; |
- | |
1020 | } |
1028 | } |
1021 | 1029 | ||
1022 | 1030 | ||
1023 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1031 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1024 | // Bei Empfangsausfall im Flug |
1032 | // Bei Empfangsausfall im Flug |
1025 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1033 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1026 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1034 | if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
1027 | { |
1035 | { |
1028 | StickNick = -GPS_Nick; |
- | |
1029 | StickRoll = -GPS_Roll; |
1036 | StickNick = -GPS_Nick; |
1030 | StickGas = StickGasHover; |
1037 | StickRoll = -GPS_Roll; |
1031 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1038 | StickGas = StickGasHover; |
1032 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1039 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1033 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1040 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1034 | Parameter_HoehenSchalter = 200; // switch on |
1041 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1035 | } |
1042 | Parameter_HoehenSchalter = 200; // switch on |
1036 | else |
1043 | } |
1037 | if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1044 | else if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING) |
1038 | { |
1045 | { |
1039 | StickGier = 0; |
1046 | StickGier = 0; |
1040 | StickNick = 0; |
- | |
1041 | StickRoll = 0; |
- | |
1042 | GyroFaktor = 90; |
- | |
1043 | IntegralFaktor = 120; |
- | |
1044 | GyroFaktorGier = 90; |
- | |
1045 | IntegralFaktorGier = 120; |
- | |
1046 | Looping_Roll = 0; |
- | |
1047 | Looping_Nick = 0; |
- | |
1048 | } |
- | |
1049 | - | ||
1050 | - | ||
1051 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1052 | // Integrale auf ACC-Signal abgleichen |
- | |
1053 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1054 | #define ABGLEICH_ANZAHL 256L |
- | |
1055 | - | ||
1056 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
- | |
1057 | MittelIntegralRoll += IntegralRoll; |
- | |
1058 | MittelIntegralNick2 += IntegralNick2; |
- | |
1059 | MittelIntegralRoll2 += IntegralRoll2; |
- | |
1060 | - | ||
1061 | if(Looping_Nick || Looping_Roll) |
- | |
1062 | { |
- | |
1063 | IntegralAccNick = 0; |
- | |
1064 | IntegralAccRoll = 0; |
- | |
1065 | MittelIntegralNick = 0; |
- | |
1066 | MittelIntegralRoll = 0; |
- | |
1067 | MittelIntegralNick2 = 0; |
- | |
1068 | MittelIntegralRoll2 = 0; |
- | |
1069 | Mess_IntegralNick2 = Mess_IntegralNick; |
- | |
1070 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
- | |
1071 | ZaehlMessungen = 0; |
- | |
1072 | LageKorrekturNick = 0; |
- | |
1073 | LageKorrekturRoll = 0; |
- | |
1074 | } |
- | |
1075 | - | ||
1076 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1077 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
- | |
1078 | { |
- | |
1079 | long tmp_long, tmp_long2; |
- | |
1080 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
- | |
1081 | { |
- | |
1082 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
- | |
1083 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
- | |
1084 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
- | |
1085 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
- | |
1086 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
- | |
1087 | { |
- | |
1088 | tmp_long /= 2; |
- | |
1089 | tmp_long2 /= 2; |
- | |
1090 | } |
- | |
1091 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
- | |
1092 | { |
- | |
1093 | tmp_long /= 3; |
- | |
1094 | tmp_long2 /= 3; |
- | |
1095 | } |
- | |
1096 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
- | |
1097 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
- | |
1098 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
- | |
1099 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
- | |
1100 | } |
- | |
1101 | else |
- | |
1102 | { |
- | |
1103 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
- | |
1104 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
- | |
1105 | tmp_long /= 16; |
- | |
1106 | tmp_long2 /= 16; |
- | |
1107 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
- | |
1108 | { |
1047 | StickNick = 0; |
1109 | tmp_long /= 3; |
- | |
1110 | tmp_long2 /= 3; |
- | |
1111 | } |
- | |
1112 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
- | |
1113 | { |
- | |
1114 | tmp_long /= 3; |
- | |
1115 | tmp_long2 /= 3; |
- | |
1116 | } |
- | |
1117 | KompassFusion = 25; |
- | |
1118 | #define AUSGLEICH 32 |
- | |
1119 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
- | |
1120 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
- | |
1121 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
- | |
1122 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
- | |
1123 | } |
- | |
1124 | - | ||
1125 | Mess_IntegralNick -= tmp_long; |
- | |
1126 | Mess_IntegralRoll -= tmp_long2; |
- | |
1127 | } |
- | |
1128 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1129 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
- | |
1130 | { |
- | |
1131 | static int cnt = 0; |
- | |
1132 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
- | |
1133 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
- | |
1134 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
- | |
1135 | { |
- | |
1136 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
- | |
1137 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
- | |
1138 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
- | |
1139 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
- | |
1140 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
- | |
1141 | #define MAX_I 0 |
- | |
1142 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1143 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
- | |
1144 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
- | |
1145 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1146 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
- | |
1147 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
- | |
1148 | - | ||
1149 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
- | |
1150 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
- | |
1151 | - | ||
1152 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
- | |
1153 | { |
- | |
1154 | LageKorrekturNick /= 2; |
- | |
1155 | LageKorrekturRoll /= 2; |
- | |
1156 | } |
- | |
1157 | - | ||
1158 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1159 | // Gyro-Drift ermitteln |
- | |
1160 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1161 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
- | |
1162 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
- | |
1163 | tmp_long = IntegralNick2 - IntegralNick; |
- | |
1164 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
- | |
1165 | - | ||
1166 | IntegralFehlerNick = tmp_long; |
- | |
1167 | IntegralFehlerRoll = tmp_long2; |
- | |
1168 | Mess_IntegralNick2 -= IntegralFehlerNick; |
- | |
1169 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
- | |
1170 | - | ||
1171 | if(EE_Parameter.Driftkomp) |
- | |
1172 | { |
- | |
1173 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
- | |
1174 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
- | |
1175 | } |
- | |
1176 | GierGyroFehler = 0; |
- | |
1177 | - | ||
1178 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
- | |
1179 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
- | |
1180 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
- | |
1181 | #define BEWEGUNGS_LIMIT 20000 |
- | |
1182 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1183 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
- | |
1184 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
- | |
1185 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
- | |
1186 | { |
- | |
1187 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
- | |
1188 | { |
- | |
1189 | if(last_n_p) |
- | |
1190 | { |
- | |
1191 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
- | |
1192 | ausgleichNick = IntegralFehlerNick / 8; |
- | |
1193 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
- | |
1194 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
- | |
1195 | } |
- | |
1196 | else last_n_p = 1; |
- | |
1197 | } else last_n_p = 0; |
- | |
1198 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
- | |
1199 | { |
- | |
1200 | if(last_n_n) |
- | |
1201 | { |
- | |
1202 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
- | |
1203 | ausgleichNick = IntegralFehlerNick / 8; |
- | |
1204 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
- | |
1205 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
- | |
1206 | } |
- | |
1207 | else last_n_n = 1; |
- | |
1208 | } else last_n_n = 0; |
- | |
1209 | } |
- | |
1210 | else |
- | |
1211 | { |
- | |
1212 | cnt = 0; |
- | |
1213 | KompassSignalSchlecht = 100; |
- | |
1214 | } |
- | |
1215 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
- | |
1216 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
- | |
1217 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
- | |
1218 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
- | |
1219 | - | ||
1220 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1221 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
- | |
1222 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
- | |
1223 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
- | |
1224 | { |
- | |
1225 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
- | |
1226 | { |
- | |
1227 | if(last_r_p) |
- | |
1228 | { |
- | |
1229 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
- | |
1230 | ausgleichRoll = IntegralFehlerRoll / 8; |
- | |
1231 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
- | |
1232 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
- | |
1233 | } |
- | |
1234 | else last_r_p = 1; |
- | |
1235 | } else last_r_p = 0; |
- | |
1236 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
- | |
1237 | { |
- | |
1238 | if(last_r_n) |
- | |
1239 | { |
- | |
1240 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
- | |
1241 | ausgleichRoll = IntegralFehlerRoll / 8; |
- | |
1242 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
- | |
1243 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
- | |
1244 | } |
- | |
1245 | else last_r_n = 1; |
- | |
1246 | } else last_r_n = 0; |
- | |
1247 | } else |
- | |
1248 | { |
- | |
1249 | cnt = 0; |
- | |
1250 | KompassSignalSchlecht = 100; |
- | |
1251 | } |
- | |
1252 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
- | |
1253 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
- | |
1254 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
- | |
1255 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
- | |
1256 | } |
- | |
1257 | else |
- | |
1258 | { |
- | |
1259 | LageKorrekturRoll = 0; |
- | |
1260 | LageKorrekturNick = 0; |
- | |
1261 | TrichterFlug = 0; |
- | |
1262 | } |
- | |
1263 | - | ||
1264 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
- | |
1265 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1266 | MittelIntegralNick_Alt = MittelIntegralNick; |
- | |
1267 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
- | |
1268 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1269 | IntegralAccNick = 0; |
- | |
Line -... | Line 1048... | ||
- | 1048 | StickRoll = 0; |
|
- | 1049 | GyroFaktor = 90; |
|
- | 1050 | IntegralFaktor = 120; |
|
- | 1051 | GyroFaktorGier = 90; |
|
- | 1052 | IntegralFaktorGier = 120; |
|
- | 1053 | Looping_Roll = 0; |
|
- | 1054 | Looping_Nick = 0; |
|
- | 1055 | } |
|
- | 1056 | ||
- | 1057 | ||
- | 1058 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1059 | // Integrale auf ACC-Signal abgleichen |
|
- | 1060 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1061 | #define ABGLEICH_ANZAHL 256L |
|
- | 1062 | ||
- | 1063 | MittelIntegralNick += IntegralNick; // Für die Mittelwertbildung aufsummieren |
|
- | 1064 | MittelIntegralRoll += IntegralRoll; |
|
- | 1065 | MittelIntegralNick2 += IntegralNick2; |
|
- | 1066 | MittelIntegralRoll2 += IntegralRoll2; |
|
- | 1067 | ||
- | 1068 | if(Looping_Nick || Looping_Roll) |
|
- | 1069 | { |
|
- | 1070 | IntegralAccNick = 0; |
|
- | 1071 | IntegralAccRoll = 0; |
|
- | 1072 | MittelIntegralNick = 0; |
|
- | 1073 | MittelIntegralRoll = 0; |
|
- | 1074 | MittelIntegralNick2 = 0; |
|
- | 1075 | MittelIntegralRoll2 = 0; |
|
- | 1076 | Mess_IntegralNick2 = Mess_IntegralNick; |
|
- | 1077 | Mess_IntegralRoll2 = Mess_IntegralRoll; |
|
- | 1078 | ZaehlMessungen = 0; |
|
- | 1079 | LageKorrekturNick = 0; |
|
- | 1080 | LageKorrekturRoll = 0; |
|
- | 1081 | } |
|
- | 1082 | ||
- | 1083 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1084 | if(!Looping_Nick && !Looping_Roll && (Aktuell_az > 512 || MotorenEin)) |
|
- | 1085 | { |
|
- | 1086 | long tmp_long, tmp_long2; |
|
- | 1087 | if(FromNaviCtrl_Value.Kalman_K > 0 /*&& !TrichterFlug*/) |
|
- | 1088 | { |
|
- | 1089 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccNick - FromNaviCtrl.AccErrorN)); |
|
- | 1090 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)(Mittelwert_AccRoll - FromNaviCtrl.AccErrorR)); |
|
- | 1091 | tmp_long = (tmp_long * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
|
- | 1092 | tmp_long2 = (tmp_long2 * FromNaviCtrl_Value.Kalman_K) / (32 * 16); |
|
- | 1093 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
|
- | 1094 | { |
|
- | 1095 | tmp_long /= 2; |
|
- | 1096 | tmp_long2 /= 2; |
|
- | 1097 | } |
|
- | 1098 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
|
- | 1099 | { |
|
- | 1100 | tmp_long /= 3; |
|
- | 1101 | tmp_long2 /= 3; |
|
- | 1102 | } |
|
- | 1103 | long kmf = FromNaviCtrl_Value.Kalman_MaxFusion; |
|
- | 1104 | if(tmp_long > (long) kmf) tmp_long = (long) kmf; |
|
- | 1105 | if(tmp_long < (long)-kmf) tmp_long = (long)-kmf; |
|
- | 1106 | if(tmp_long2 > (long) kmf) tmp_long2 = (long) kmf; |
|
- | 1107 | if(tmp_long2 < (long)-kmf) tmp_long2 = (long)-kmf; |
|
- | 1108 | } |
|
- | 1109 | else |
|
- | 1110 | { |
|
- | 1111 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
|
- | 1112 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
|
- | 1113 | tmp_long /= 16; |
|
- | 1114 | tmp_long2 /= 16; |
|
- | 1115 | if((MaxStickNick > 64) || (MaxStickRoll > 64)) |
|
- | 1116 | { |
|
- | 1117 | tmp_long /= 3; |
|
- | 1118 | tmp_long2 /= 3; |
|
- | 1119 | } |
|
- | 1120 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
|
- | 1121 | { |
|
- | 1122 | tmp_long /= 3; |
|
- | 1123 | tmp_long2 /= 3; |
|
- | 1124 | } |
|
- | 1125 | KompassFusion = 25; |
|
- | 1126 | #define AUSGLEICH 32 |
|
1270 | IntegralAccRoll = 0; |
1127 | if(tmp_long > AUSGLEICH) tmp_long = AUSGLEICH; |
- | 1128 | if(tmp_long < -AUSGLEICH) tmp_long =-AUSGLEICH; |
|
- | 1129 | if(tmp_long2 > AUSGLEICH) tmp_long2 = AUSGLEICH; |
|
- | 1130 | if(tmp_long2 <-AUSGLEICH) tmp_long2 =-AUSGLEICH; |
|
- | 1131 | } |
|
- | 1132 | ||
- | 1133 | Mess_IntegralNick -= tmp_long; |
|
- | 1134 | Mess_IntegralRoll -= tmp_long2; |
|
- | 1135 | } |
|
- | 1136 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1137 | if(ZaehlMessungen >= ABGLEICH_ANZAHL) |
|
- | 1138 | { |
|
- | 1139 | static int cnt = 0; |
|
- | 1140 | static char last_n_p,last_n_n,last_r_p,last_r_n; |
|
- | 1141 | static long MittelIntegralNick_Alt,MittelIntegralRoll_Alt; |
|
- | 1142 | if(!Looping_Nick && !Looping_Roll && !TrichterFlug && EE_Parameter.Driftkomp) |
|
- | 1143 | { |
|
- | 1144 | MittelIntegralNick /= ABGLEICH_ANZAHL; |
|
- | 1145 | MittelIntegralRoll /= ABGLEICH_ANZAHL; |
|
- | 1146 | IntegralAccNick = (EE_Parameter.GyroAccFaktor * IntegralAccNick) / ABGLEICH_ANZAHL; |
|
- | 1147 | IntegralAccRoll = (EE_Parameter.GyroAccFaktor * IntegralAccRoll) / ABGLEICH_ANZAHL; |
|
- | 1148 | IntegralAccZ = IntegralAccZ / ABGLEICH_ANZAHL; |
|
- | 1149 | #define MAX_I 0 |
|
- | 1150 | // Nick ++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1151 | IntegralFehlerNick = (long)(MittelIntegralNick - (long)IntegralAccNick); |
|
- | 1152 | ausgleichNick = IntegralFehlerNick / EE_Parameter.GyroAccAbgleich; |
|
- | 1153 | // Roll ++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1154 | IntegralFehlerRoll = (long)(MittelIntegralRoll - (long)IntegralAccRoll); |
|
- | 1155 | ausgleichRoll = IntegralFehlerRoll / EE_Parameter.GyroAccAbgleich; |
|
- | 1156 | ||
- | 1157 | LageKorrekturNick = ausgleichNick / ABGLEICH_ANZAHL; |
|
- | 1158 | LageKorrekturRoll = ausgleichRoll / ABGLEICH_ANZAHL; |
|
- | 1159 | ||
- | 1160 | if(((MaxStickNick > 64) || (MaxStickRoll > 64) || (abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)) && (FromNaviCtrl_Value.Kalman_K == -1)) |
|
- | 1161 | { |
|
- | 1162 | LageKorrekturNick /= 2; |
|
- | 1163 | LageKorrekturRoll /= 2; |
|
- | 1164 | } |
|
- | 1165 | ||
- | 1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1167 | // Gyro-Drift ermitteln |
|
- | 1168 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1169 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
|
- | 1170 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
|
- | 1171 | long tmp_long = IntegralNick2 - IntegralNick; |
|
- | 1172 | long tmp_long2 = IntegralRoll2 - IntegralRoll; |
|
- | 1173 | ||
- | 1174 | IntegralFehlerNick = tmp_long; |
|
- | 1175 | IntegralFehlerRoll = tmp_long2; |
|
- | 1176 | Mess_IntegralNick2 -= IntegralFehlerNick; |
|
- | 1177 | Mess_IntegralRoll2 -= IntegralFehlerRoll; |
|
- | 1178 | ||
- | 1179 | if(EE_Parameter.Driftkomp) |
|
- | 1180 | { |
|
- | 1181 | if(GierGyroFehler > ABGLEICH_ANZAHL/2) { AdNeutralGier++; } |
|
- | 1182 | if(GierGyroFehler <-ABGLEICH_ANZAHL/2) { AdNeutralGier--; } |
|
- | 1183 | } |
|
- | 1184 | GierGyroFehler = 0; |
|
- | 1185 | ||
- | 1186 | #define FEHLER_LIMIT (ABGLEICH_ANZAHL / 2) |
|
- | 1187 | #define FEHLER_LIMIT1 (ABGLEICH_ANZAHL * 2) //4 |
|
- | 1188 | #define FEHLER_LIMIT2 (ABGLEICH_ANZAHL * 16) //16 |
|
- | 1189 | #define BEWEGUNGS_LIMIT 20000 |
|
- | 1190 | // Nick +++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1191 | cnt = 1;// + labs(IntegralFehlerNick) / 4096; |
|
- | 1192 | if(labs(IntegralFehlerNick) > FEHLER_LIMIT1) cnt = 4; |
|
- | 1193 | if(labs(MittelIntegralNick_Alt - MittelIntegralNick) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
|
- | 1194 | { |
|
- | 1195 | if(IntegralFehlerNick > FEHLER_LIMIT2) |
|
- | 1196 | { |
|
- | 1197 | if(last_n_p) |
|
- | 1198 | { |
|
- | 1199 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
|
- | 1200 | ausgleichNick = IntegralFehlerNick / 8; |
|
- | 1201 | if(ausgleichNick > 5000) ausgleichNick = 5000; |
|
- | 1202 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
|
- | 1203 | } |
|
- | 1204 | else last_n_p = 1; |
|
- | 1205 | } else last_n_p = 0; |
|
- | 1206 | if(IntegralFehlerNick < -FEHLER_LIMIT2) |
|
- | 1207 | { |
|
- | 1208 | if(last_n_n) |
|
- | 1209 | { |
|
- | 1210 | cnt += labs(IntegralFehlerNick) / (FEHLER_LIMIT2 / 8); |
|
- | 1211 | ausgleichNick = IntegralFehlerNick / 8; |
|
- | 1212 | if(ausgleichNick < -5000) ausgleichNick = -5000; |
|
- | 1213 | LageKorrekturNick += ausgleichNick / ABGLEICH_ANZAHL; |
|
- | 1214 | } |
|
- | 1215 | else last_n_n = 1; |
|
- | 1216 | } else last_n_n = 0; |
|
- | 1217 | } |
|
- | 1218 | else |
|
- | 1219 | { |
|
- | 1220 | cnt = 0; |
|
- | 1221 | KompassSignalSchlecht = 100; |
|
- | 1222 | } |
|
- | 1223 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
|
- | 1224 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
|
- | 1225 | if(IntegralFehlerNick > FEHLER_LIMIT) AdNeutralNick += cnt; |
|
- | 1226 | if(IntegralFehlerNick < -FEHLER_LIMIT) AdNeutralNick -= cnt; |
|
- | 1227 | ||
- | 1228 | // Roll +++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1229 | cnt = 1;// + labs(IntegralFehlerRoll) / 4096; |
|
- | 1230 | if(labs(IntegralFehlerRoll) > FEHLER_LIMIT1) cnt = 4; |
|
- | 1231 | if(labs(MittelIntegralRoll_Alt - MittelIntegralRoll) < BEWEGUNGS_LIMIT || (FromNaviCtrl_Value.Kalman_MaxDrift > 3*8)) |
|
- | 1232 | { |
|
- | 1233 | if(IntegralFehlerRoll > FEHLER_LIMIT2) |
|
- | 1234 | { |
|
- | 1235 | if(last_r_p) |
|
- | 1236 | { |
|
- | 1237 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
|
- | 1238 | ausgleichRoll = IntegralFehlerRoll / 8; |
|
- | 1239 | if(ausgleichRoll > 5000) ausgleichRoll = 5000; |
|
- | 1240 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
|
- | 1241 | } |
|
- | 1242 | else last_r_p = 1; |
|
- | 1243 | } else last_r_p = 0; |
|
- | 1244 | if(IntegralFehlerRoll < -FEHLER_LIMIT2) |
|
- | 1245 | { |
|
- | 1246 | if(last_r_n) |
|
- | 1247 | { |
|
- | 1248 | cnt += labs(IntegralFehlerRoll) / (FEHLER_LIMIT2 / 8); |
|
- | 1249 | ausgleichRoll = IntegralFehlerRoll / 8; |
|
- | 1250 | if(ausgleichRoll < -5000) ausgleichRoll = -5000; |
|
- | 1251 | LageKorrekturRoll += ausgleichRoll / ABGLEICH_ANZAHL; |
|
- | 1252 | } |
|
- | 1253 | else last_r_n = 1; |
|
- | 1254 | } else last_r_n = 0; |
|
- | 1255 | } else |
|
- | 1256 | { |
|
- | 1257 | cnt = 0; |
|
- | 1258 | KompassSignalSchlecht = 100; |
|
- | 1259 | } |
|
- | 1260 | if(cnt > EE_Parameter.Driftkomp) cnt = EE_Parameter.Driftkomp; |
|
- | 1261 | if(FromNaviCtrl_Value.Kalman_MaxDrift) if(cnt > FromNaviCtrl_Value.Kalman_MaxDrift) cnt = FromNaviCtrl_Value.Kalman_MaxDrift; |
|
- | 1262 | if(IntegralFehlerRoll > FEHLER_LIMIT) AdNeutralRoll += cnt; |
|
- | 1263 | if(IntegralFehlerRoll < -FEHLER_LIMIT) AdNeutralRoll -= cnt; |
|
- | 1264 | } |
|
- | 1265 | else |
|
- | 1266 | { |
|
- | 1267 | LageKorrekturRoll = 0; |
|
- | 1268 | LageKorrekturNick = 0; |
|
- | 1269 | TrichterFlug = 0; |
|
- | 1270 | } |
|
- | 1271 | ||
- | 1272 | if(!IntegralFaktor) { LageKorrekturRoll = 0; LageKorrekturNick = 0;} // z.B. bei HH |
|
- | 1273 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1274 | MittelIntegralNick_Alt = MittelIntegralNick; |
|
- | 1275 | MittelIntegralRoll_Alt = MittelIntegralRoll; |
|
- | 1276 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1277 | IntegralAccNick = 0; |
|
- | 1278 | IntegralAccRoll = 0; |
|
1271 | IntegralAccZ = 0; |
1279 | IntegralAccZ = 0; |
1272 | MittelIntegralNick = 0; |
1280 | MittelIntegralNick = 0; |
1273 | MittelIntegralRoll = 0; |
1281 | MittelIntegralRoll = 0; |
1274 | MittelIntegralNick2 = 0; |
1282 | MittelIntegralNick2 = 0; |
1275 | MittelIntegralRoll2 = 0; |
1283 | MittelIntegralRoll2 = 0; |
1276 | ZaehlMessungen = 0; |
1284 | ZaehlMessungen = 0; |
1277 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1285 | } // ZaehlMessungen >= ABGLEICH_ANZAHL |
1278 | 1286 | ||
1279 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1287 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1280 | // Gieren |
1288 | // Gieren |
1281 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1289 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1282 | if(abs(StickGier) > 3) // war 15 |
1290 | if(abs(StickGier) > 3) // war 15 |
1283 | { |
1291 | { |
1284 | // KompassSignalSchlecht = 1000; |
1292 | // KompassSignalSchlecht = 1000; |
1285 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1293 | if(!(Parameter_GlobalConfig & CFG_KOMPASS_FIX)) |
1286 | { |
1294 | { |
1287 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
1295 | NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen |
1288 | }; |
1296 | }; |
1289 | } |
1297 | } |
1290 | tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1298 | int tmp_int = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo y = ax + bx² |
1291 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
1299 | tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4; |
1292 | tmp_int += CompassGierSetpoint; |
1300 | tmp_int += CompassGierSetpoint; |
1293 | sollGier = tmp_int; |
1301 | sollGier = tmp_int; |
1294 | Mess_Integral_Gier -= tmp_int; |
1302 | Mess_Integral_Gier -= tmp_int; |
1295 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1303 | if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000; // begrenzen |
1296 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1304 | if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000; |
1297 | 1305 | ||
1298 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1306 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1299 | // Kompass |
1307 | // Kompass |
1300 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1308 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1301 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1309 | if(KompassValue >= 0 && (Parameter_GlobalConfig & CFG_KOMPASS_AKTIV)) |
1302 | { |
1310 | { |
1303 | if(CalculateCompassTimer-- == 1) |
1311 | if(CalculateCompassTimer-- == 1) |
1304 | { |
1312 | { |
1305 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
1313 | int w,v,r,fehler,korrektur; // wird von der SPI-Routine auf 1 gesetzt |
1306 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
1314 | CalculateCompassTimer = 13; // falls keine Navi-Daten |
1307 | // max. Korrekturwert schätzen |
1315 | // max. Korrekturwert schätzen |
1308 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1316 | w = abs(IntegralNick /512); // mit zunehmender Neigung den Einfluss drosseln |
1309 | v = abs(IntegralRoll /512); |
1317 | v = abs(IntegralRoll /512); |
1310 | if(v > w) w = v; // grösste Neigung ermitteln |
1318 | if(v > w) w = v; // grösste Neigung ermitteln |
1311 | // korrektur = w / 4 + 1; |
1319 | // korrektur = w / 4 + 1; |
1312 | korrektur = w / 8 + 2; |
1320 | korrektur = w / 8 + 2; |
1313 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1321 | ErsatzKompassInGrad = ErsatzKompass/GIER_GRAD_FAKTOR; |
1314 | // Kompassfehlerwert bestimmen |
1322 | // Kompassfehlerwert bestimmen |
1315 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1323 | fehler = ((540 + KompassValue - ErsatzKompassInGrad) % 360) - 180; |
1316 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1324 | // GIER_GRAD_FAKTOR ist ca. 1200 |
1317 | // Kompasswert einloggen |
1325 | // Kompasswert einloggen |
1318 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1326 | if(KompassSignalSchlecht) KompassSignalSchlecht--; |
1319 | else |
1327 | else |
1320 | if(w < 25) |
1328 | if(w < 25) |
1321 | { |
1329 | { |
1322 | GierGyroFehler += fehler; |
1330 | GierGyroFehler += fehler; |
1323 | if(NeueKompassRichtungMerken) |
1331 | if(NeueKompassRichtungMerken) |
1324 | { |
1332 | { |
1325 | if(--NeueKompassRichtungMerken == 0) |
1333 | if(--NeueKompassRichtungMerken == 0) |
1326 | { |
1334 | { |
1327 | KompassSollWert = ErsatzKompassInGrad; |
1335 | KompassSollWert = ErsatzKompassInGrad; |
1328 | } |
1336 | } |
1329 | } |
1337 | } |
1330 | } |
1338 | } |
1331 | // Kompass fusionieren |
1339 | // Kompass fusionieren |
1332 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1340 | if(!KompassSignalSchlecht) ErsatzKompass += (fehler * KompassFusion) / korrektur; |
1333 | // MK Gieren |
1341 | // MK Gieren |
1334 | if(!NeueKompassRichtungMerken) |
1342 | if(!NeueKompassRichtungMerken) |
1335 | { |
1343 | { |
1336 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1344 | r = ((540 + (KompassSollWert - ErsatzKompassInGrad)) % 360) - 180; |
1337 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1345 | v = r * (Parameter_KompassWirkung/2); // nach Kompass ausrichten |
1338 | CompassGierSetpoint = v / 16; |
1346 | CompassGierSetpoint = v / 16; |
1339 | } |
1347 | } |
1340 | else CompassGierSetpoint = 0; |
1348 | else CompassGierSetpoint = 0; |
1341 | } // CalculateCompassTimer |
1349 | } // CalculateCompassTimer |
1342 | } |
1350 | } |
1343 | else CompassGierSetpoint = 0; |
1351 | else CompassGierSetpoint = 0; |
1344 | 1352 | ||
1345 | //DebugOut.Analog[16] = KompassFusion; |
1353 | //DebugOut.Analog[16] = KompassFusion; |
1346 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1354 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1347 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1355 | // Drehgeschwindigkeit und -winkel zu einem Istwert zusammenfassen |
1348 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1356 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1349 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1357 | if(TrichterFlug) { SummeRoll = 0; SummeNick = 0;}; |
1350 | 1358 | ||
1351 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1359 | if(!Looping_Nick) IntegralNickMalFaktor = (IntegralNick * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralNickMalFaktor = 0; |
1352 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1360 | if(!Looping_Roll) IntegralRollMalFaktor = (IntegralRoll * IntegralFaktor) / (44000 / STICK_GAIN); else IntegralRollMalFaktor = 0; |
1353 | 1361 | ||
1354 | #define TRIM_MAX 200 |
1362 | #define TRIM_MAX 200 |
1355 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1363 | if(TrimNick > TRIM_MAX) TrimNick = TRIM_MAX; else if(TrimNick <-TRIM_MAX) TrimNick =-TRIM_MAX; |
1356 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1364 | if(TrimRoll > TRIM_MAX) TrimRoll = TRIM_MAX; else if(TrimRoll <-TRIM_MAX) TrimRoll =-TRIM_MAX; |
1357 | 1365 | ||
1358 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1366 | MesswertNick = IntegralNickMalFaktor + (long)((long)MesswertNick * GyroFaktor + (long)TrimNick * 128L) / (256L / STICK_GAIN); |
1359 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1367 | MesswertRoll = IntegralRollMalFaktor + (long)((long)MesswertRoll * GyroFaktor + (long)TrimRoll * 128L) / (256L / STICK_GAIN); |
1360 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1368 | MesswertGier = (long)(MesswertGier * 2 * (long)GyroFaktorGier) / (256L / STICK_GAIN) + (long)(Integral_Gier * IntegralFaktorGier) / (2 * (44000 / STICK_GAIN)); |
1361 | 1369 | ||
1362 | // Maximalwerte abfangen |
1370 | // Maximalwerte abfangen |
1363 | #define MAX_SENSOR (4096) |
1371 | #define MAX_SENSOR (4096) |
1364 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1372 | if(MesswertNick > MAX_SENSOR) MesswertNick = MAX_SENSOR; |
1365 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1373 | if(MesswertNick < -MAX_SENSOR) MesswertNick = -MAX_SENSOR; |
1366 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1374 | if(MesswertRoll > MAX_SENSOR) MesswertRoll = MAX_SENSOR; |
1367 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1375 | if(MesswertRoll < -MAX_SENSOR) MesswertRoll = -MAX_SENSOR; |
1368 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1376 | if(MesswertGier > MAX_SENSOR) MesswertGier = MAX_SENSOR; |
1369 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
1377 | if(MesswertGier < -MAX_SENSOR) MesswertGier = -MAX_SENSOR; |
- | 1378 | ||
- | 1379 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1380 | // Höhenregelung |
|
- | 1381 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
|
- | 1382 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1383 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
|
- | 1384 | GasMischanteil *= STICK_GAIN; |
|
- | 1385 | // if height control is activated |
|
- | 1386 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
|
- | 1387 | GasMischanteil = HoehenRegelung(GasMischanteil); |
|
- | 1388 | else |
|
- | 1389 | { |
|
- | 1390 | // set undefined state to indicate vario off |
|
- | 1391 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
|
- | 1392 | } // EOF no height control |
|
- | 1393 | ||
- | 1394 | // Linits the maximum gas in case of "Out of Range emergency landing" |
|
- | 1395 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
|
- | 1396 | { |
|
- | 1397 | if(GasMischanteil/STICK_GAIN > HoverGasEmergencyPercent && HoverGas) GasMischanteil = HoverGasEmergencyPercent * STICK_GAIN; |
|
- | 1398 | SollHoehe = HoehenWert; // update setpoint to current heigth |
|
- | 1399 | beeptime = 15000; |
|
- | 1400 | BeepMuster = 0x0E00; |
|
- | 1401 | } |
|
- | 1402 | // limit gas to parameter setting |
|
- | 1403 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
|
- | 1404 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
|
- | 1405 | ||
- | 1406 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1407 | // all BL-Ctrl connected? |
|
- | 1408 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1409 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
|
- | 1410 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
|
- | 1411 | { |
|
- | 1412 | modell_fliegt = 1; |
|
- | 1413 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
|
- | 1414 | } |
|
- | 1415 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1416 | // + Mischer und PI-Regler |
|
- | 1417 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1418 | DebugOut.Analog[7] = GasMischanteil; |
|
- | 1419 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1420 | // Gier-Anteil |
|
- | 1421 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1422 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
|
- | 1423 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
|
- | 1424 | if(GasMischanteil > MIN_GIERGAS) |
|
- | 1425 | { |
|
- | 1426 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
|
- | 1427 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
|
- | 1428 | } |
|
- | 1429 | else |
|
- | 1430 | { |
|
- | 1431 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
|
- | 1432 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
|
- | 1433 | } |
|
- | 1434 | tmp_int = MAX_GAS*STICK_GAIN; |
|
- | 1435 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
|
- | 1436 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
|
- | 1437 | ||
- | 1438 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1439 | // Nick-Achse |
|
- | 1440 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1441 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
|
- | 1442 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
|
- | 1443 | else SummeNick += DiffNick; // I-Anteil bei HH |
|
- | 1444 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
|
- | 1445 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
|
- | 1446 | ||
- | 1447 | if(EE_Parameter.Gyro_Stability <= 8) |
|
- | 1448 | pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
|
- | 1449 | else |
|
- | 1450 | pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
|
- | 1451 | pd_ergebnis_nick += SummeNick / Ki; |
|
- | 1452 | ||
- | 1453 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
|
- | 1454 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
|
- | 1455 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
|
- | 1456 | ||
- | 1457 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1458 | // Roll-Achse |
|
- | 1459 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1460 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
|
- | 1461 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
|
- | 1462 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
|
- | 1463 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
|
- | 1464 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
|
- | 1465 | ||
- | 1466 | if(EE_Parameter.Gyro_Stability <= 8) |
|
- | 1467 | pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
|
- | 1468 | else |
|
- | 1469 | pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
|
- | 1470 | pd_ergebnis_roll += SummeRoll / Ki; |
|
1370 | 1471 | ||
- | 1472 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
|
- | 1473 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
|
- | 1474 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
|
- | 1475 | ||
- | 1476 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 1477 | // Universal Mixer |
|
- | 1478 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
1371 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1479 | for(i=0; i<MAX_MOTORS; i++) |
- | 1480 | { |
|
- | 1481 | signed int tmp_int; |
|
- | 1482 | if(Mixer.Motor[i][0] > 0) |
|
- | 1483 | { |
|
- | 1484 | // Gas |
|
- | 1485 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
|
1372 | // Höhenregelung |
1486 | // Nick |
- | 1487 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
|
- | 1488 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
|
- | 1489 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
|
- | 1490 | // Roll |
|
- | 1491 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
|
- | 1492 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
|
- | 1493 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
|
- | 1494 | // Gier |
|
- | 1495 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
|
- | 1496 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
|
- | 1497 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
|
- | 1498 | ||
- | 1499 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
|
- | 1500 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
|
- | 1501 | else |
|
- | 1502 | { |
|
- | 1503 | if(EE_Parameter.MotorSmooth == 0) |
|
- | 1504 | { |
|
- | 1505 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
|
- | 1506 | } |
|
- | 1507 | else // 1 means tmp_int = tmp_int; |
|
- | 1508 | if(EE_Parameter.MotorSmooth > 1) |
|
- | 1509 | { |
|
- | 1510 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
|
- | 1511 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth); |
|
- | 1512 | } |
|
- | 1513 | } |
|
- | 1514 | ||
- | 1515 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
|
- | 1516 | Motor[i].SetPoint = tmp_int / 4; |
|
- | 1517 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
|
Line -... | Line 1518... | ||
- | 1518 | tmp_motorwert[i] = tmp_int; |
|
- | 1519 | } |
|
- | 1520 | else |
|
- | 1521 | { |
|
- | 1522 | Motor[i].SetPoint = 0; |
|
1373 | // Die Höhenregelung schwächt lediglich das Gas ab, erhöht es allerdings nicht |
1523 | Motor[i].SetPointLowerBits = 0; |
1374 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1524 | } |
1375 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1525 | } |
1376 | GasMischanteil *= STICK_GAIN; |
1526 | } |
1377 | // if height control is activated |
1527 | |
1378 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
- | |
- | 1528 | static int HoehenRegelung(int GasMischanteil) |
|
1379 | { |
1529 | { |
1380 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1530 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1381 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1531 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1382 | 1532 | ||
1383 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
- | |
1384 | #define OPA_OFFSET_STEP 15 |
1533 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1385 | #else |
1534 | #define OPA_OFFSET_STEP 15 |
1386 | #define OPA_OFFSET_STEP 10 |
1535 | #else |
1387 | #endif |
1536 | #define OPA_OFFSET_STEP 10 |
1388 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
1537 | #endif |
1389 | static int HeightTrimming = 0; // rate for change of height setpoint |
1538 | |
1390 | static int FilterHCGas = 0; |
1539 | static int sHeightTrimming = 0; // rate for change of height setpoint |
1391 | static unsigned long HoverGasFilter = 0; |
1540 | static int sFilterHCGas = 0; |
1392 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
1541 | static unsigned long sHoverGasFilter = 0; |
1393 | int CosAttitude; // for projection of hoover gas |
1542 | static unsigned char sDelay = 100, sBaroAtUpperLimit = 0, sBaroAtLowerLimit = 0; |
1394 | 1543 | ||
1395 | // get the current hooverpoint |
1544 | // get the current hoverpoint |
1396 | DebugOut.Analog[21] = HoverGas; |
1545 | DebugOut.Analog[21] = HoverGas; |
1397 | 1546 | ||
1398 | // Expand the measurement |
1547 | // Expand the measurement |
1399 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1548 | // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs |
1400 | if(!BaroExpandActive) |
- | |
1401 | { |
- | |
1402 | if(MessLuftdruck > 920) |
- | |
1403 | { // increase offset |
- | |
1404 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
- | |
1405 | { |
1549 | if(!BaroExpandActive) |
1406 | ExpandBaro -= 1; |
- | |
1407 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
1550 | { |
- | 1551 | if(MessLuftdruck > 920) |
|
- | 1552 | { // increase offset |
|
- | 1553 | if(OCR0A < (255 - OPA_OFFSET_STEP)) |
|
- | 1554 | { |
|
- | 1555 | ExpandBaro -= 1; |
|
- | 1556 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down |
|
1408 | beeptime = 300; |
1557 | beeptime = 300; |
1409 | BaroExpandActive = 350; |
1558 | BaroExpandActive = 350; |
1410 | } |
1559 | } |
1411 | else |
1560 | else |
1412 | { |
1561 | { |
1413 | BaroAtLowerLimit = 1; |
1562 | sBaroAtLowerLimit = 1; |
1414 | } |
1563 | } |
1415 | } |
1564 | } |
1416 | // measurement of air pressure close to lower limit and |
1565 | // measurement of air pressure close to lower limit and |
1417 | else |
1566 | else |
1418 | if(MessLuftdruck < 100) |
1567 | if(MessLuftdruck < 100) |
1419 | { // decrease offset |
1568 | { // decrease offset |
1420 | if(OCR0A > OPA_OFFSET_STEP) |
1569 | if(OCR0A > OPA_OFFSET_STEP) |
1421 | { |
1570 | { |
1422 | ExpandBaro += 1; |
1571 | ExpandBaro += 1; |
1423 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1572 | OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up |
1424 | beeptime = 300; |
1573 | beeptime = 300; |
1425 | BaroExpandActive = 350; |
1574 | BaroExpandActive = 350; |
1426 | } |
1575 | } |
1427 | else |
1576 | else |
1428 | { |
1577 | { |
1429 | BaroAtUpperLimit = 1; |
1578 | sBaroAtUpperLimit = 1; |
1430 | } |
1579 | } |
1431 | } |
1580 | } |
1432 | else |
1581 | else |
1433 | { |
1582 | { |
1434 | BaroAtUpperLimit = 0; |
1583 | sBaroAtUpperLimit = 0; |
1435 | BaroAtLowerLimit = 0; |
1584 | sBaroAtLowerLimit = 0; |
1436 | } |
1585 | } |
1437 | } |
1586 | } |
1438 | else // delay, because of expanding the Baro-Range |
1587 | else // delay, because of expanding the Baro-Range |
1439 | { |
1588 | { |
1440 | // now clear the D-values |
1589 | // now clear the D-values |
1441 | SummenHoehe = HoehenWert * SM_FILTER; |
1590 | SummenHoehe = HoehenWert * SM_FILTER; |
1442 | VarioMeter = 0; |
1591 | VarioMeter = 0; |
1443 | BaroExpandActive--; |
1592 | BaroExpandActive--; |
1444 | } |
1593 | } |
1445 | 1594 | ||
1446 | // if height control is activated by an rc channel |
1595 | // if height control is activated by an rc channel |
1447 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1596 | if(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER) // Regler wird über Schalter gesteuert |
1448 | { // check if parameter is less than activation threshold |
1597 | { // check if parameter is less than activation threshold |
1449 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
- | |
1450 | { //height control not active |
1598 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
- | 1599 | { //height control not active |
|
1451 | if(!delay--) |
1600 | if(!sDelay--) |
1452 | { |
1601 | { |
1453 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1602 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1454 | if(HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
1603 | if(HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
1455 | #endif |
1604 | #endif |
1456 | HoehenReglerAktiv = 0; // disable height control |
1605 | HoehenReglerAktiv = 0; // disable height control |
1457 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1606 | SollHoehe = HoehenWert; // update SetPoint with current reading |
1458 | delay = 1; |
1607 | sDelay = 1; |
1459 | } |
1608 | } |
1460 | } |
1609 | } |
1461 | else |
1610 | else |
1462 | if(Parameter_HoehenSchalter > 70) |
1611 | if(Parameter_HoehenSchalter > 70) |
1463 | { //height control is activated |
1612 | { //height control is activated |
1464 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1613 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1465 | if(!HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_ON; |
1614 | if(!HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_ON; |
1466 | #endif |
1615 | #endif |
1467 | HoehenReglerAktiv = 1; // enable height control |
1616 | HoehenReglerAktiv = 1; // enable height control |
1468 | delay = 200; |
1617 | sDelay = 200; |
1469 | } |
1618 | } |
1470 | } |
1619 | } |
1471 | else // no switchable height control |
1620 | else // no switchable height control |
1472 | { |
1621 | { |
1473 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1622 | SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
1474 | HoehenReglerAktiv = 1; |
1623 | HoehenReglerAktiv = 1; |
1475 | } |
1624 | } |
1476 | 1625 | ||
1477 | // calculate cos of nick and roll angle used for projection of the vertical hoover gas |
1626 | // calculate cos of nick and roll angle used for projection of the vertical hover gas |
1478 | tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1627 | int tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
1479 | tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1628 | int tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1480 | CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1629 | int CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
1481 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1630 | LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
1482 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
1631 | CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
- | 1632 | VarioCharacter = ' '; |
|
1483 | VarioCharacter = ' '; |
1633 | AltitudeSetpointTrimming = 0; |
1484 | AltitudeSetpointTrimming = 0; |
1634 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1485 | if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1635 | { |
1486 | { |
1636 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1487 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1637 | // Holger original version |
1488 | // Holger original version |
1638 | // start of height control algorithm |
1489 | // start of height control algorithm |
1639 | // the height control is only an attenuation of the actual gas stick. |
1490 | // the height control is only an attenuation of the actual gas stick. |
1640 | // I.e. it will work only if the gas stick is higher than the hover gas |
1491 | // I.e. it will work only if the gas stick is higher than the hover gas |
1641 | // and the hover height will always be larger than height setpoint. |
1492 | // and the hover height will be allways larger than height setpoint. |
1642 | int HCGas; |
1493 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1643 | FC_StatusFlags2 |= FC_STATUS2_ALTITUDE_CONTROL; |
1494 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1644 | if((Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) || !(Parameter_GlobalConfig & CFG_HOEHEN_SCHALTER)) // Regler wird über Schalter gesteuert) |
1495 | { // old version |
1645 | { // old version |
1496 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1646 | HCGas = GasMischanteil; // take current stick gas as neutral point for the height control |
1497 | HeightTrimming = 0; |
1647 | sHeightTrimming = 0; |
1498 | AltitudeSetpointTrimming = 0; |
1648 | AltitudeSetpointTrimming = 0; |
1499 | // set both flags to indicate no vario mode |
1649 | // set both flags to indicate no vario mode |
1500 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1650 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1501 | } |
1651 | } |
1502 | else |
1652 | else |
1503 | { |
1653 | { |
1504 | // alternative height control |
1654 | // alternative height control |
1505 | // PD-Control with respect to hoover point |
1655 | // PD-Control with respect to hover point |
Line 1517... | Line 1667... | ||
1517 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1667 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1518 | // Limit the maximum Altitude |
1668 | // Limit the maximum Altitude |
1519 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0; |
1669 | if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0; |
1520 | else |
1670 | else |
1521 | { |
1671 | { |
1522 | // SollHoehe = (long) Parameter_MaximumAltitude * 100L; |
1672 | // SollHoehe = (long) Parameter_MaximumAltitude * 100L; |
1523 | // HeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1673 | // sHeightTrimming += abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1524 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1674 | AltitudeSetpointTrimming = abs(StickGas - (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD)); |
1525 | VarioCharacter = '+'; |
1675 | VarioCharacter = '+'; |
1526 | } |
1676 | } |
1527 | WaypointTrimming = 0; |
1677 | WaypointTrimming = 0; |
1528 | } // gas stick is below hoover point |
1678 | } // gas stick is below hover point |
1529 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit ) |
1679 | else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !sBaroAtLowerLimit ) |
1530 | { |
1680 | { |
1531 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) |
1681 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) |
1532 | { |
1682 | { |
1533 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1683 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1534 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1684 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1535 | } |
1685 | } |
1536 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1686 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1537 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1687 | AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1538 | // HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1688 | // sHeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD)); |
1539 | VarioCharacter = '-'; |
1689 | VarioCharacter = '-'; |
1540 | WaypointTrimming = 0; |
1690 | WaypointTrimming = 0; |
1541 | } |
1691 | } |
1542 | else // Gas Stick in Hover Range |
1692 | else // Gas Stick in Hover Range |
1543 | { |
1693 | { |
1544 | VarioCharacter = '='; |
1694 | VarioCharacter = '='; |
1545 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1695 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint > SollHoehe) // von NC gesteuert -> Steigen |
1546 | { |
1696 | { |
1547 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1697 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP; |
1548 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1698 | AltitudeSetpointTrimming = FromNC_AltitudeSpeed; |
1549 | //HeightTrimming += FromNC_AltitudeSpeed; |
1699 | //sHeightTrimming += FromNC_AltitudeSpeed; |
1550 | WaypointTrimming = 10; |
1700 | WaypointTrimming = 10; |
1551 | VarioCharacter = '^'; |
1701 | VarioCharacter = '^'; |
1552 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1702 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) // changed from sinking to rising |
1553 | { |
1703 | { |
1554 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1704 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1555 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1705 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1556 | } |
1706 | } |
1557 | } |
1707 | } |
1558 | else |
- | |
1559 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
- | |
1560 | { |
- | |
1561 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
- | |
1562 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
- | |
1563 | //HeightTrimming -= FromNC_AltitudeSpeed; |
- | |
1564 | WaypointTrimming = -10; |
- | |
1565 | VarioCharacter = 'v'; |
- | |
1566 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
- | |
1567 | { |
- | |
1568 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
- | |
1569 | SollHoehe = HoehenWert; // update setpoint to current heigth |
- | |
1570 | } |
- | |
1571 | } |
- | |
1572 | else |
1708 | else |
1573 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
- | |
1574 | { |
- | |
1575 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
1709 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1576 | else WaypointTrimming = 0; |
- | |
1577 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
- | |
1578 | HeightTrimming = 0; |
- | |
1579 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
- | |
1580 | if(!StartTrigger && HoehenWert > 50) |
- | |
1581 | { |
1710 | { |
- | 1711 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
|
- | 1712 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
|
- | 1713 | //sHeightTrimming -= FromNC_AltitudeSpeed; |
|
- | 1714 | WaypointTrimming = -10; |
|
1582 | StartTrigger = 1; |
1715 | VarioCharacter = 'v'; |
- | 1716 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
|
- | 1717 | { |
|
- | 1718 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
|
- | 1719 | SollHoehe = HoehenWert; // update setpoint to current heigth |
|
- | 1720 | } |
|
1583 | } |
1721 | } |
- | 1722 | else |
|
- | 1723 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
|
- | 1724 | { |
|
- | 1725 | if(!WaypointTrimming) |
|
- | 1726 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
|
- | 1727 | else |
|
- | 1728 | WaypointTrimming = 0; |
|
- | 1729 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
|
- | 1730 | sHeightTrimming = 0; |
|
- | 1731 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) |
|
- | 1732 | beeptime = 500; |
|
- | 1733 | if(!StartTrigger && HoehenWert > 50) |
|
- | 1734 | { |
|
- | 1735 | StartTrigger = 1; |
|
- | 1736 | } |
|
1584 | } |
1737 | } |
1585 | } |
1738 | } |
1586 | // Trim height set point |
1739 | // Trim height set point |
1587 | HeightTrimming += AltitudeSetpointTrimming; |
1740 | sHeightTrimming += AltitudeSetpointTrimming; |
1588 | if(abs(HeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
1741 | if(abs(sHeightTrimming) > 500) // bei Waypoint-Flug ist das ca. die 500Hz |
1589 | { |
1742 | { |
1590 | if(WaypointTrimming) |
1743 | if(WaypointTrimming) |
1591 | { |
1744 | { |
1592 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) SollHoehe = FromNC_AltitudeSetpoint; |
1745 | if(abs(FromNC_AltitudeSetpoint - SollHoehe) < 10) |
- | 1746 | SollHoehe = FromNC_AltitudeSetpoint; |
|
- | 1747 | else |
|
1593 | else SollHoehe += WaypointTrimming; |
1748 | SollHoehe += WaypointTrimming; |
1594 | } |
1749 | } |
1595 | else |
1750 | else |
1596 | { |
1751 | { |
1597 | if(HeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
1752 | if(sHeightTrimming > 0) SollHoehe += EE_Parameter.Hoehe_Verstaerkung / 3; |
1598 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
1753 | else SollHoehe -= EE_Parameter.Hoehe_Verstaerkung / 3; |
1599 | } |
1754 | } |
1600 | HeightTrimming = 0; |
1755 | sHeightTrimming = 0; |
1601 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1756 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1602 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1757 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1603 | //update hoover gas stick value when setpoint is shifted |
1758 | //update hover gas stick value when setpoint is shifted |
1604 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1759 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1605 | { |
1760 | { |
1606 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1761 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1607 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1762 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1608 | if(StickGasHover < 70) StickGasHover = 70; |
1763 | if(StickGasHover < 70) StickGasHover = 70; |
1609 | else if(StickGasHover > 150) StickGasHover = 150; |
1764 | else if(StickGasHover > 150) StickGasHover = 150; |
1610 | } |
1765 | } |
1611 | } |
1766 | } |
1612 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1767 | if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active |
1613 | } //if FCFlags & MKFCFLAG_FLY |
1768 | } //if FCFlags & MKFCFLAG_FLY |
1614 | else |
1769 | else |
1615 | { |
1770 | { |
1616 | SollHoehe = HoehenWert - 400; |
1771 | SollHoehe = HoehenWert - 400; |
1617 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1772 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1618 | else StickGasHover = 120; |
1773 | else StickGasHover = 120; |
1619 | HoverGas = GasMischanteil; |
1774 | HoverGas = GasMischanteil; |
1620 | VarioCharacter = '.'; |
1775 | VarioCharacter = '.'; |
1621 | } |
1776 | } |
1622 | HCGas = HoverGas; // take hover gas (neutral point) |
1777 | HCGas = HoverGas; // take hover gas (neutral point) |
1623 | } |
1778 | } |
1624 | if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1779 | if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1625 | { |
1780 | { |
1626 | // from this point the Heigth Control Algorithm is identical for both versions |
1781 | // from this point the Heigth Control Algorithm is identical for both versions |
- | 1782 | int HeightDeviation = 0, GasReduction = 0; |
|
1627 | if(BaroExpandActive) // baro range expanding active |
1783 | if(BaroExpandActive) // baro range expanding active |
1628 | { |
1784 | { |
1629 | HCGas = HoverGas; // hover while expanding baro adc range |
1785 | HCGas = HoverGas; // hover while expanding baro adc range |
1630 | HeightDeviation = 0; |
- | |
1631 | } // EOF // baro range expanding active |
1786 | } // EOF // baro range expanding active |
1632 | else // valid data from air pressure sensor |
1787 | else // valid data from air pressure sensor |
1633 | { |
1788 | { |
1634 | // ------------------------- P-Part ---------------------------- |
1789 | // ------------------------- P-Part ---------------------------- |
1635 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1790 | int32_t tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1636 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1791 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1637 | HeightDeviation = (int)(tmp_long); // positive when too high |
1792 | HeightDeviation = (int)(tmp_long); // positive when too high |
1638 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1793 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1639 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1794 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1640 | GasReduction = tmp_long; |
1795 | GasReduction = tmp_long; |
1641 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1796 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1642 | tmp_int = VarioMeter / 8; |
1797 | tmp_int = VarioMeter / 8; |
1643 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1798 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1644 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1799 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1645 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1800 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1646 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) tmp_int /= 4; // reduce d-part while trimming setpoint |
1801 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
- | 1802 | tmp_int /= 4; // reduce d-part while trimming setpoint |
|
1647 | else |
1803 | else |
1648 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1804 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) tmp_int /= 8; // reduce d-part in "Deckel" mode |
1649 | GasReduction += tmp_int; |
1805 | GasReduction += tmp_int; |
1650 | } // EOF no baro range expanding |
1806 | } // EOF no baro range expanding |
1651 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1807 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1652 | if(Parameter_Hoehe_ACC_Wirkung) |
1808 | if(Parameter_Hoehe_ACC_Wirkung) |
1653 | { |
1809 | { |
1654 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1810 | int32_t tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
1655 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1811 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1656 | GasReduction += tmp_long; |
1812 | GasReduction += tmp_long; |
1657 | } |
1813 | } |
1658 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1814 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1659 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1815 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
1660 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1816 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1661 | GasReduction += tmp_int; |
1817 | GasReduction += tmp_int; |
1662 | GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1818 | GasReduction = ((long)GasReduction * HoverGas) / 512; // scale to the gas value |
1663 | // ------------------------ ---------------------------------- |
1819 | // ------------------------ ---------------------------------- |
1664 | HCGas -= GasReduction; |
1820 | HCGas -= GasReduction; |
1665 | // limit deviation from hoover point within the target region |
1821 | // limit deviation from hover point within the target region |
1666 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero |
1822 | if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hover gas not zero |
1667 | { |
1823 | { |
1668 | unsigned int tmp; |
1824 | unsigned int tmp; |
1669 | tmp = abs(HeightDeviation); |
1825 | tmp = abs(HeightDeviation); |
1670 | if(tmp <= 60) |
1826 | if(tmp <= 60) |
1671 | { |
- | |
1672 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
- | |
1673 | } |
- | |
1674 | else |
- | |
1675 | { |
- | |
1676 | tmp = (tmp - 60) / 32; |
- | |
1677 | if(tmp > 15) tmp = 15; |
- | |
1678 | if(HeightDeviation > 0) |
- | |
1679 | { |
1827 | { |
1680 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
- | |
1681 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1828 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hover point |
1682 | } |
1829 | } |
1683 | else |
1830 | else |
1684 | { |
1831 | { |
- | 1832 | tmp = (tmp - 60) / 32; |
|
- | 1833 | if(tmp > 15) tmp = 15; |
|
- | 1834 | if(HeightDeviation > 0) |
|
- | 1835 | { |
|
- | 1836 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
|
- | 1837 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hover point |
|
- | 1838 | } |
|
- | 1839 | else |
|
- | 1840 | { |
|
1685 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1841 | tmp = (HoverGasMax * (tmp + 16)) / 16; |
1686 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hoover point |
1842 | LIMIT_MIN_MAX(HCGas, HoverGasMin, tmp); // limit gas around the hover point |
- | 1843 | } |
|
1687 | } |
1844 | } |
1688 | } |
- | |
1689 | } |
1845 | } |
1690 | // strech control output by inverse attitude projection 1/cos |
1846 | // strech control output by inverse attitude projection 1/cos |
1691 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1847 | // + 1/cos(angle) ++++++++++++++++++++++++++ |
1692 | tmp_long2 = (int32_t)HCGas; |
1848 | int32_t tmp_long2 = (int32_t)HCGas; |
1693 | tmp_long2 *= 8192L; |
1849 | tmp_long2 *= 8192L; |
1694 | tmp_long2 /= CosAttitude; |
1850 | tmp_long2 /= CosAttitude; |
1695 | HCGas = (int16_t)tmp_long2; |
1851 | HCGas = (int16_t)tmp_long2; |
1696 | // update height control gas averaging |
1852 | // update height control gas averaging |
1697 | FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1853 | sFilterHCGas = (sFilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
1698 | // limit height control gas pd-control output |
1854 | // limit height control gas pd-control output |
1699 | LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1855 | LIMIT_MIN_MAX(sFilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
1700 | // set GasMischanteil to HeightControlGasFilter |
1856 | // set GasMischanteil to HeightControlGasFilter |
1701 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1857 | if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
1702 | { // old version |
1858 | { // old version |
1703 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1859 | LIMIT_MAX(sFilterHCGas, GasMischanteil); // nicht mehr als Gas |
1704 | GasMischanteil = FilterHCGas; |
1860 | GasMischanteil = sFilterHCGas; |
1705 | } |
1861 | } |
1706 | else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1862 | else GasMischanteil = sFilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
1707 | } |
- | |
1708 | }// EOF height control active |
- | |
1709 | else // HC not active |
- | |
1710 | { |
- | |
1711 | //update hoover gas stick value when HC is not active |
- | |
1712 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
- | |
1713 | { |
- | |
1714 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
- | |
1715 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
- | |
1716 | } |
- | |
1717 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
- | |
1718 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
- | |
1719 | FilterHCGas = GasMischanteil; |
- | |
1720 | // set both flags to indicate no vario mode |
- | |
1721 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
- | |
1722 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
- | |
1723 | } |
1863 | } |
1724 | // Hover gas estimation by averaging gas control output on small z-velocities |
- | |
1725 | // this is done only if height contol option is selected in global config and aircraft is flying |
- | |
1726 | if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
- | |
1727 | { |
- | |
1728 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
- | |
1729 | if(StartTrigger == 1) StartTrigger = 2; |
- | |
1730 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
- | |
1731 | tmp_long2 *= CosAttitude; // apply attitude projection |
- | |
1732 | tmp_long2 /= 8192; |
- | |
1733 | // average vertical projected thrust |
1864 | }// EOF height control active |
1734 | if(modell_fliegt < 4000) // the first 8 seconds |
- | |
1735 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
- | |
1736 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
- | |
1737 | HoverGasFilter += 16L * tmp_long2; |
- | |
1738 | } |
- | |
1739 | if(modell_fliegt < 8000) // the first 16 seconds |
- | |
1740 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
- | |
1741 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
- | |
1742 | HoverGasFilter += 4L * tmp_long2; |
- | |
1743 | } |
- | |
1744 | else //later |
- | |
1745 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
- | |
1746 | { |
- | |
1747 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
- | |
1748 | HoverGasFilter += tmp_long2; |
- | |
1749 | } |
- | |
1750 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
- | |
1751 | if(EE_Parameter.Hoehe_HoverBand) |
- | |
1752 | { |
- | |
1753 | int16_t band; |
- | |
1754 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
- | |
1755 | HoverGasMin = HoverGas - band; |
- | |
1756 | HoverGasMax = HoverGas + band; |
- | |
1757 | } |
- | |
1758 | else |
- | |
1759 | { // no limit |
1865 | else // HC not active |
1760 | HoverGasMin = 0; |
- | |
1761 | HoverGasMax = 1023; |
- | |
1762 | } |
- | |
1763 | } |
- | |
1764 | else |
- | |
1765 | { |
- | |
1766 | StartTrigger = 0; |
- | |
1767 | HoverGasFilter = 0; |
- | |
1768 | HoverGas = 0; |
- | |
1769 | } |
- | |
1770 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
- | |
1771 | else |
- | |
1772 | { |
1866 | { |
- | 1867 | //update hover gas stick value when HC is not active |
|
- | 1868 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
|
- | 1869 | { |
|
- | 1870 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
|
- | 1871 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
|
- | 1872 | } |
|
- | 1873 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
|
- | 1874 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
|
- | 1875 | sFilterHCGas = GasMischanteil; |
|
1773 | // set undefined state to indicate vario off |
1876 | // set both flags to indicate no vario mode |
1774 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1877 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1775 | } // EOF no height control |
- | |
1776 | - | ||
1777 | // Linits the maximum gas in case of "Out of Range emergency landing" |
- | |
1778 | if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING) |
1878 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1779 | { |
- | |
1780 | if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN; |
- | |
1781 | SollHoehe = HoehenWert; // update setpoint to current heigth |
- | |
1782 | beeptime = 15000; |
- | |
1783 | BeepMuster = 0x0E00; |
- | |
1784 | } |
1879 | } |
1785 | // limit gas to parameter setting |
- | |
1786 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
- | |
1787 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
- | |
1788 | 1880 | ||
1789 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1790 | // all BL-Ctrl connected? |
- | |
1791 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1792 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
1881 | // Hover gas estimation by averaging gas control output on small z-velocities |
1793 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
1882 | // this is done only if height contol option is selected in global config and aircraft is flying |
1794 | { |
- | |
1795 | modell_fliegt = 1; |
- | |
1796 | GasMischanteil = (MIN_GAS + 10) * STICK_GAIN; |
- | |
1797 | } |
- | |
1798 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1799 | // + Mischer und PI-Regler |
- | |
1800 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1801 | DebugOut.Analog[7] = GasMischanteil; |
1883 | if((FC_StatusFlags & FC_STATUS_FLY)) { |
1802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1803 | // Gier-Anteil |
- | |
1804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1805 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
1884 | if(sHoverGasFilter == 0 || StartTrigger == 1) sHoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1806 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
- | |
1807 | if(GasMischanteil > MIN_GIERGAS) |
1885 | if(StartTrigger == 1) StartTrigger = 2; |
1808 | { |
- | |
1809 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
1886 | int32_t tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1810 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
- | |
1811 | } |
- | |
1812 | else |
- | |
1813 | { |
- | |
1814 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
1887 | tmp_long2 *= CosAttitude; // apply attitude projection |
1815 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
- | |
1816 | } |
- | |
1817 | tmp_int = MAX_GAS*STICK_GAIN; |
1888 | tmp_long2 /= 8192; |
1818 | if(GierMischanteil > ((tmp_int - GasMischanteil))) GierMischanteil = ((tmp_int - GasMischanteil)); |
- | |
1819 | if(GierMischanteil < -((tmp_int - GasMischanteil))) GierMischanteil = -((tmp_int - GasMischanteil)); |
- | |
1820 | - | ||
1821 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1822 | // Nick-Achse |
1889 | // average vertical projected thrust |
1823 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1824 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
1890 | if(modell_fliegt < 4000) // the first 8 seconds |
1825 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
1891 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1826 | else SummeNick += DiffNick; // I-Anteil bei HH |
- | |
1827 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
1892 | sHoverGasFilter -= sHoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1828 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
1893 | sHoverGasFilter += 16L * tmp_long2; |
1829 | 1894 | } |
|
1830 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_nick = (EE_Parameter.Gyro_Stability * DiffNick) / 8; // PI-Regler für Nick |
- | |
1831 | else pd_ergebnis_nick = ((EE_Parameter.Gyro_Stability / 2) * DiffNick) / 4; // Überlauf verhindern |
- | |
1832 | pd_ergebnis_nick += SummeNick / Ki; |
1895 | if(modell_fliegt < 8000) // the first 16 seconds |
1833 | - | ||
1834 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
1896 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1835 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
1897 | sHoverGasFilter -= sHoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1836 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
1898 | sHoverGasFilter += 4L * tmp_long2; |
1837 | 1899 | } |
|
1838 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1839 | // Roll-Achse |
1900 | else //later |
1840 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1841 | DiffRoll = MesswertRoll - StickRoll; // Differenz bestimmen |
- | |
1842 | if(IntegralFaktor) SummeRoll += IntegralRollMalFaktor - StickRoll;// I-Anteil bei Winkelregelung |
- | |
1843 | else SummeRoll += DiffRoll; // I-Anteil bei HH |
- | |
1844 | if(SummeRoll > (STICK_GAIN * 16000L)) SummeRoll = (STICK_GAIN * 16000L); |
- | |
1845 | if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN); |
- | |
1846 | - | ||
1847 | if(EE_Parameter.Gyro_Stability <= 8) pd_ergebnis_roll = (EE_Parameter.Gyro_Stability * DiffRoll) / 8; // PI-Regler für Roll |
1901 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1848 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
- | |
1849 | pd_ergebnis_roll += SummeRoll / Ki; |
- | |
1850 | 1902 | { |
|
1851 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
- | |
1852 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
- | |
1853 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
1903 | sHoverGasFilter -= sHoverGasFilter/HOVER_GAS_AVERAGE; |
1854 | - | ||
1855 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1856 | // Universal Mixer |
- | |
1857 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1858 | for(i=0; i<MAX_MOTORS; i++) |
1904 | sHoverGasFilter += tmp_long2; |
1859 | { |
1905 | } |
1860 | signed int tmp_int; |
1906 | HoverGas = (int16_t)(sHoverGasFilter/HOVER_GAS_AVERAGE); |
1861 | if(Mixer.Motor[i][0] > 0) |
1907 | if(EE_Parameter.Hoehe_HoverBand) |
1862 | { |
1908 | { |
1863 | // Gas |
1909 | int16_t band; |
1864 | if(Mixer.Motor[i][0] == 64) tmp_int = GasMischanteil; else tmp_int = ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L; |
- | |
1865 | // Nick |
- | |
1866 | if(Mixer.Motor[i][1] == 64) tmp_int += pd_ergebnis_nick; |
- | |
1867 | else if(Mixer.Motor[i][1] == -64) tmp_int -= pd_ergebnis_nick; |
- | |
1868 | else tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L; |
- | |
1869 | // Roll |
- | |
1870 | if(Mixer.Motor[i][2] == 64) tmp_int += pd_ergebnis_roll; |
- | |
1871 | else if(Mixer.Motor[i][2] == -64) tmp_int -= pd_ergebnis_roll; |
- | |
1872 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
- | |
1873 | // Gier |
- | |
1874 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
- | |
1875 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
- | |
1876 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
- | |
1877 | - | ||
1878 | if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // MotorSmoothing |
1910 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1879 | // else tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
- | |
1880 | else |
- | |
1881 | { |
- | |
1882 | if(EE_Parameter.MotorSmooth == 0) |
- | |
1883 | { |
- | |
1884 | tmp_int = 2 * tmp_int - tmp_motorwert[i]; // original MotorSmoothing |
- | |
1885 | } |
- | |
1886 | else // 1 means tmp_int = tmp_int; |
- | |
1887 | if(EE_Parameter.MotorSmooth > 1) |
- | |
1888 | { |
- | |
1889 | // If >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value. |
- | |
1890 | tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/EE_Parameter.MotorSmooth); |
- | |
1891 | } |
- | |
1892 | } |
- | |
1893 | - | ||
1894 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
- | |
1895 | Motor[i].SetPoint = tmp_int / 4; |
1911 | HoverGasMin = HoverGas - band; |
1896 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
- | |
1897 | tmp_motorwert[i] = tmp_int; |
1912 | HoverGasMax = HoverGas + band; |
1898 | } |
1913 | } |
1899 | else |
1914 | else |
1900 | { |
1915 | { // no limit |
1901 | Motor[i].SetPoint = 0; |
1916 | HoverGasMin = 0; |
1902 | Motor[i].SetPointLowerBits = 0; |
1917 | HoverGasMax = 1023; |
1903 | } |
1918 | } |
1904 | } |
1919 | } |
- | 1920 | else |
|
- | 1921 | { |
|
- | 1922 | // not flying |
|
- | 1923 | StartTrigger = 0; |
|
- | 1924 | sHoverGasFilter = 0; |
|
- | 1925 | HoverGas = 0; |
|
- | 1926 | } |
|
- | 1927 | ||
- | 1928 | return GasMischanteil; |
|
1905 | } |
1929 | } |
1906 | //DebugOut.Analog[16] |
- |