Rev 2167 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2167 | Rev 2172 | ||
---|---|---|---|
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 643... | Line 645... | ||
643 | if(carefree_old != CareFree) |
645 | if(carefree_old != CareFree) |
644 | { |
646 | { |
645 | if(carefree_old < 3) |
647 | if(carefree_old < 3) |
646 | { |
648 | { |
647 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
649 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
- | 650 | if(CareFree) |
|
648 | if(CareFree) { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
651 | { beeptime = 1500; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_ON; } |
- | 652 | else |
|
649 | else { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
653 | { beeptime = 200; if(!SpeakHoTT) SpeakHoTT = SPEAK_CF_OFF; } |
650 | #else |
654 | #else |
- | 655 | if(CareFree) |
|
651 | if(CareFree) beeptime = 1500; |
656 | beeptime = 1500; |
- | 657 | else |
|
652 | else beeptime = 200; |
658 | beeptime = 200; |
653 | #endif |
659 | #endif |
654 | NeueKompassRichtungMerken = 5; |
660 | NeueKompassRichtungMerken = 5; |
655 | carefree_old = CareFree; |
661 | carefree_old = CareFree; |
656 | } else carefree_old--; |
662 | } else carefree_old--; |
657 | } |
663 | } |
Line 675... | Line 681... | ||
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; |
Line 695... | Line 701... | ||
695 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
701 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
696 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
702 | if(EE_Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE) |
697 | { |
703 | { |
698 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
704 | if(HoverGas && HoverGas < 150 * STICK_GAIN) |
699 | { |
705 | { |
700 | HooverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
706 | HoverGasEmergencyPercent = (HoverGas/(STICK_GAIN) * EE_Parameter.NotGas) / 100; // i.e. 80% of Hovergas |
701 | } |
707 | } |
702 | else HooverGasEmergencyPercent = 45; // default if the Hoovergas was could not calculated yet |
708 | else HoverGasEmergencyPercent = 45; // default if the Hovergas was could not calculated yet |
703 | } else HooverGasEmergencyPercent = EE_Parameter.NotGas; |
709 | } else HoverGasEmergencyPercent = EE_Parameter.NotGas; |
Line 704... | Line 710... | ||
704 | 710 | ||
705 | GasMischanteil = StickGas; |
711 | GasMischanteil = StickGas; |
- | 712 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
|
- | 713 | ||
- | 714 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
|
706 | if(GasMischanteil < MIN_GAS + 10) GasMischanteil = MIN_GAS + 10; |
715 | { |
707 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
716 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
708 | // Empfang schlecht |
717 | // Empfang schlecht |
709 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
710 | if(SenderOkay < 100 && !(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE)) |
- | |
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; |
Line 748... | Line 755... | ||
748 | { |
755 | { |
749 | SummeNick = 0; |
756 | SummeNick = 0; |
750 | SummeRoll = 0; |
757 | SummeRoll = 0; |
751 | sollGier = 0; |
758 | sollGier = 0; |
752 | Mess_Integral_Gier = 0; |
759 | Mess_Integral_Gier = 0; |
- | 760 | } else |
|
753 | } else FC_StatusFlags |= FC_STATUS_FLY; |
761 | FC_StatusFlags |= FC_STATUS_FLY; |
Line 754... | Line 762... | ||
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 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 1031... | Line 1039... | ||
1031 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1039 | Parameter_GlobalConfig &= ~(CFG_HEADING_HOLD | CFG_DREHRATEN_BEGRENZER); |
1032 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1040 | Parameter_GlobalConfig |= CFG_HOEHENREGELUNG | CFG_ACHSENKOPPLUNG_AKTIV | CFG_KOMPASS_AKTIV | CFG_GPS_AKTIV | CFG_HOEHEN_SCHALTER | CFG_GPS_AKTIV; |
1033 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1041 | Parameter_ExtraConfig &= ~(CFG2_HEIGHT_LIMIT | CFG_LEARNABLE_CAREFREE | CFG2_VARIO_BEEP); |
1034 | Parameter_HoehenSchalter = 200; // switch on |
1042 | Parameter_HoehenSchalter = 200; // switch on |
1035 | } |
1043 | } |
1036 | else |
- | |
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; |
1047 | StickNick = 0; |
1041 | StickRoll = 0; |
1048 | StickRoll = 0; |
1042 | GyroFaktor = 90; |
1049 | GyroFaktor = 90; |
Line 1091... | Line 1098... | ||
1091 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1098 | if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
1092 | { |
1099 | { |
1093 | tmp_long /= 3; |
1100 | tmp_long /= 3; |
1094 | tmp_long2 /= 3; |
1101 | tmp_long2 /= 3; |
1095 | } |
1102 | } |
- | 1103 | long kmf = FromNaviCtrl_Value.Kalman_MaxFusion; |
|
1096 | if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1104 | if(tmp_long > (long) kmf) tmp_long = (long) kmf; |
1097 | if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1105 | if(tmp_long < (long)-kmf) tmp_long = (long)-kmf; |
1098 | if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1106 | if(tmp_long2 > (long) kmf) tmp_long2 = (long) kmf; |
1099 | if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
1107 | if(tmp_long2 < (long)-kmf) tmp_long2 = (long)-kmf; |
1100 | } |
1108 | } |
1101 | else |
1109 | else |
1102 | { |
1110 | { |
1103 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1111 | tmp_long = (long)(IntegralNick / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccNick); |
1104 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
1112 | tmp_long2 = (long)(IntegralRoll / EE_Parameter.GyroAccFaktor - (long)Mittelwert_AccRoll); |
Line 1158... | Line 1166... | ||
1158 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1159 | // Gyro-Drift ermitteln |
1167 | // Gyro-Drift ermitteln |
1160 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1168 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1161 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1169 | MittelIntegralNick2 /= ABGLEICH_ANZAHL; |
1162 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1170 | MittelIntegralRoll2 /= ABGLEICH_ANZAHL; |
1163 | tmp_long = IntegralNick2 - IntegralNick; |
1171 | long tmp_long = IntegralNick2 - IntegralNick; |
1164 | tmp_long2 = IntegralRoll2 - IntegralRoll; |
1172 | long tmp_long2 = IntegralRoll2 - IntegralRoll; |
Line 1165... | Line 1173... | ||
1165 | 1173 | ||
1166 | IntegralFehlerNick = tmp_long; |
1174 | IntegralFehlerNick = tmp_long; |
1167 | IntegralFehlerRoll = tmp_long2; |
1175 | IntegralFehlerRoll = tmp_long2; |
1168 | Mess_IntegralNick2 -= IntegralFehlerNick; |
1176 | Mess_IntegralNick2 -= IntegralFehlerNick; |
Line 1285... | Line 1293... | ||
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 |
Line 1374... | Line 1382... | ||
1374 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1382 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1375 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1383 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1376 | GasMischanteil *= STICK_GAIN; |
1384 | GasMischanteil *= STICK_GAIN; |
1377 | // if height control is activated |
1385 | // if height control is activated |
1378 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
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; |
|
- | 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 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
- | 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; |
|
- | 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) |
|
- | 1518 | tmp_motorwert[i] = tmp_int; |
|
- | 1519 | } |
|
- | 1520 | else |
|
- | 1521 | { |
|
- | 1522 | Motor[i].SetPoint = 0; |
|
- | 1523 | Motor[i].SetPointLowerBits = 0; |
|
- | 1524 | } |
|
- | 1525 | } |
|
- | 1526 | } |
|
- | 1527 | ||
- | 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 |
Line 1382... | Line 1532... | ||
1382 | 1532 | ||
1383 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1533 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1384 | #define OPA_OFFSET_STEP 15 |
1534 | #define OPA_OFFSET_STEP 15 |
1385 | #else |
1535 | #else |
1386 | #define OPA_OFFSET_STEP 10 |
1536 | #define OPA_OFFSET_STEP 10 |
1387 | #endif |
- | |
1388 | int HCGas, HeightDeviation = 0,GasReduction = 0; |
- | |
1389 | static int HeightTrimming = 0; // rate for change of height setpoint |
- | |
1390 | static int FilterHCGas = 0; |
- | |
1391 | static unsigned long HoverGasFilter = 0; |
- | |
1392 | static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
- | |
Line -... | Line 1537... | ||
- | 1537 | #endif |
|
- | 1538 | ||
- | 1539 | static int sHeightTrimming = 0; // rate for change of height setpoint |
|
- | 1540 | static int sFilterHCGas = 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 | ||
Line 1395... | Line 1544... | ||
1395 | // get the current hooverpoint |
1544 | // get the current hoverpoint |
1396 | DebugOut.Analog[21] = HoverGas; |
1545 | DebugOut.Analog[21] = HoverGas; |
1397 | 1546 | ||
Line 1408... | Line 1557... | ||
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) |
Line 1424... | Line 1573... | ||
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 |
Line 1446... | Line 1595... | ||
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 |
1598 | if(Parameter_HoehenSchalter < 50) // for 3 or 2-state switch height control is disabled in lowest position |
1450 | { //height control not active |
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 | } |
Line 1476... | Line 1625... | ||
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 |
1483 | VarioCharacter = ' '; |
1632 | VarioCharacter = ' '; |
1484 | AltitudeSetpointTrimming = 0; |
1633 | AltitudeSetpointTrimming = 0; |
Line 1487... | Line 1636... | ||
1487 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1636 | #define HEIGHT_CONTROL_STICKTHRESHOLD 15 |
1488 | // Holger original version |
1637 | // Holger original version |
1489 | // start of height control algorithm |
1638 | // start of height control algorithm |
1490 | // the height control is only an attenuation of the actual gas stick. |
1639 | // the height control is only an attenuation of the actual gas stick. |
1491 | // I.e. it will work only if the gas stick is higher than the hover gas |
1640 | // I.e. it will work only if the gas stick is higher than the hover gas |
1492 | // and the hover height will be allways larger than height setpoint. |
1641 | // and the hover height will always be 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 |
1506 | // the thrust loss out of horizontal attitude is compensated |
1656 | // the thrust loss out of horizontal attitude is compensated |
1507 | // the setpoint will be fine adjusted with the gas stick position |
1657 | // the setpoint will be fine adjusted with the gas stick position |
1508 | if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1658 | if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying |
1509 | { // gas stick is above hoover point |
1659 | { // gas stick is above hover point |
1510 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
1660 | if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !sBaroAtUpperLimit) |
1511 | { |
1661 | { |
1512 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1662 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
1513 | { |
1663 | { |
1514 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1664 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1515 | SollHoehe = HoehenWert; // update setpoint to current heigth |
1665 | SollHoehe = HoehenWert; // update setpoint to current heigth |
Line 1518... | Line 1668... | ||
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; |
Line 1558... | Line 1708... | ||
1558 | else |
1708 | else |
1559 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1709 | if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken |
1560 | { |
1710 | { |
1561 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1711 | FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN; |
1562 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1712 | AltitudeSetpointTrimming = -FromNC_AltitudeSpeed; |
1563 | //HeightTrimming -= FromNC_AltitudeSpeed; |
1713 | //sHeightTrimming -= FromNC_AltitudeSpeed; |
1564 | WaypointTrimming = -10; |
1714 | WaypointTrimming = -10; |
1565 | VarioCharacter = 'v'; |
1715 | VarioCharacter = 'v'; |
1566 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1716 | if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking |
1567 | { |
1717 | { |
1568 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
1718 | FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP; |
Line 1570... | Line 1720... | ||
1570 | } |
1720 | } |
1571 | } |
1721 | } |
1572 | else |
1722 | else |
1573 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1723 | if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN)) |
1574 | { |
1724 | { |
- | 1725 | if(!WaypointTrimming) |
|
1575 | if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
1726 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied |
- | 1727 | else |
|
1576 | else WaypointTrimming = 0; |
1728 | WaypointTrimming = 0; |
1577 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1729 | FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
1578 | HeightTrimming = 0; |
1730 | sHeightTrimming = 0; |
1579 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1731 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) |
- | 1732 | beeptime = 500; |
|
1580 | if(!StartTrigger && HoehenWert > 50) |
1733 | if(!StartTrigger && HoehenWert > 50) |
1581 | { |
1734 | { |
1582 | StartTrigger = 1; |
1735 | StartTrigger = 1; |
1583 | } |
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; |
Line 1622... | Line 1777... | ||
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 | { |
1827 | { |
1672 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hoover point |
1828 | LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limit gas around the hover point |
1673 | } |
1829 | } |
1674 | else |
1830 | else |
1675 | { |
1831 | { |
1676 | tmp = (tmp - 60) / 32; |
1832 | tmp = (tmp - 60) / 32; |
1677 | if(tmp > 15) tmp = 15; |
1833 | if(tmp > 15) tmp = 15; |
1678 | if(HeightDeviation > 0) |
1834 | if(HeightDeviation > 0) |
1679 | { |
1835 | { |
1680 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1836 | tmp = (HoverGasMin * (16 - tmp)) / 16; |
1681 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hoover point |
1837 | LIMIT_MIN_MAX(HCGas, tmp, HoverGasMax); // limit gas around the hover point |
1682 | } |
1838 | } |
1683 | else |
1839 | else |
1684 | { |
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 |
1687 | } |
1843 | } |
1688 | } |
1844 | } |
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 | } |
1863 | } |
1708 | }// EOF height control active |
1864 | }// EOF height control active |
1709 | else // HC not active |
1865 | else // HC not active |
1710 | { |
1866 | { |
1711 | //update hoover gas stick value when HC is not active |
1867 | //update hover gas stick value when HC is not active |
1712 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1868 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
1713 | { |
1869 | { |
1714 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1870 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
1715 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1871 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1716 | } |
1872 | } |
1717 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1873 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1718 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1874 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
1719 | FilterHCGas = GasMischanteil; |
1875 | sFilterHCGas = GasMischanteil; |
1720 | // set both flags to indicate no vario mode |
1876 | // set both flags to indicate no vario mode |
1721 | 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); |
1722 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1878 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
1723 | } |
1879 | } |
- | 1880 | ||
1724 | // Hover gas estimation by averaging gas control output on small z-velocities |
1881 | // 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 |
1882 | // 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)) |
1883 | if((FC_StatusFlags & FC_STATUS_FLY)) { |
1727 | { |
- | |
1728 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1884 | if(sHoverGasFilter == 0 || StartTrigger == 1) sHoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1729 | if(StartTrigger == 1) StartTrigger = 2; |
1885 | if(StartTrigger == 1) StartTrigger = 2; |
1730 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1886 | int32_t tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1731 | tmp_long2 *= CosAttitude; // apply attitude projection |
1887 | tmp_long2 *= CosAttitude; // apply attitude projection |
1732 | tmp_long2 /= 8192; |
1888 | tmp_long2 /= 8192; |
1733 | // average vertical projected thrust |
1889 | // average vertical projected thrust |
1734 | if(modell_fliegt < 4000) // the first 8 seconds |
1890 | 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 |
1891 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1736 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1892 | sHoverGasFilter -= sHoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1737 | HoverGasFilter += 16L * tmp_long2; |
1893 | sHoverGasFilter += 16L * tmp_long2; |
1738 | } |
1894 | } |
1739 | if(modell_fliegt < 8000) // the first 16 seconds |
1895 | 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 |
1896 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1741 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1897 | sHoverGasFilter -= sHoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1742 | HoverGasFilter += 4L * tmp_long2; |
1898 | sHoverGasFilter += 4L * tmp_long2; |
1743 | } |
1899 | } |
1744 | else //later |
1900 | else //later |
1745 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1901 | if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
1746 | { |
1902 | { |
1747 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1903 | sHoverGasFilter -= sHoverGasFilter/HOVER_GAS_AVERAGE; |
1748 | HoverGasFilter += tmp_long2; |
1904 | sHoverGasFilter += tmp_long2; |
1749 | } |
1905 | } |
1750 | HoverGas = (int16_t)(HoverGasFilter/HOVER_GAS_AVERAGE); |
1906 | HoverGas = (int16_t)(sHoverGasFilter/HOVER_GAS_AVERAGE); |
1751 | if(EE_Parameter.Hoehe_HoverBand) |
1907 | if(EE_Parameter.Hoehe_HoverBand) |
1752 | { |
1908 | { |
1753 | int16_t band; |
1909 | int16_t band; |
1754 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1910 | band = HoverGas / EE_Parameter.Hoehe_HoverBand; // the higher the parameter the smaller the range |
1755 | HoverGasMin = HoverGas - band; |
1911 | HoverGasMin = HoverGas - band; |
Line 1761... | Line 1917... | ||
1761 | HoverGasMax = 1023; |
1917 | HoverGasMax = 1023; |
1762 | } |
1918 | } |
1763 | } |
1919 | } |
1764 | else |
1920 | else |
1765 | { |
1921 | { |
- | 1922 | // not flying |
|
1766 | StartTrigger = 0; |
1923 | StartTrigger = 0; |
1767 | HoverGasFilter = 0; |
1924 | sHoverGasFilter = 0; |
1768 | HoverGas = 0; |
1925 | HoverGas = 0; |
1769 | } |
1926 | } |
1770 | }// EOF Parameter_GlobalConfig & CFG_HEIGHT_CONTROL |
- | |
1771 | else |
- | |
1772 | { |
- | |
1773 | // set undefined state to indicate vario off |
- | |
1774 | 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) |
- | |
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 | } |
- | |
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 | - | ||
1789 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1790 | // all BL-Ctrl connected? |
- | |
1791 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1792 | if(MissingMotor || Capacity.MinOfMaxPWM != 255 || NC_ErrorCode) // wait until all BL-Ctrls started and no Errors |
- | |
1793 | if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0) // only during start-phase |
- | |
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; |
- | |
1802 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1803 | // Gier-Anteil |
- | |
1804 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1805 | GierMischanteil = MesswertGier - sollGier * STICK_GAIN; // Regler für Gier |
- | |
1806 | #define MIN_GIERGAS (40*STICK_GAIN) // unter diesem Gaswert trotzdem Gieren |
- | |
1807 | if(GasMischanteil > MIN_GIERGAS) |
- | |
1808 | { |
- | |
1809 | if(GierMischanteil > (GasMischanteil / 2)) GierMischanteil = GasMischanteil / 2; |
- | |
1810 | if(GierMischanteil < -(GasMischanteil / 2)) GierMischanteil = -(GasMischanteil / 2); |
- | |
1811 | } |
- | |
1812 | else |
- | |
1813 | { |
- | |
1814 | if(GierMischanteil > (MIN_GIERGAS / 2)) GierMischanteil = MIN_GIERGAS / 2; |
- | |
1815 | if(GierMischanteil < -(MIN_GIERGAS / 2)) GierMischanteil = -(MIN_GIERGAS / 2); |
- | |
1816 | } |
- | |
1817 | tmp_int = MAX_GAS*STICK_GAIN; |
- | |
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 |
- | |
1823 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1824 | DiffNick = MesswertNick - StickNick; // Differenz bestimmen |
- | |
1825 | if(IntegralFaktor) SummeNick += IntegralNickMalFaktor - StickNick; // I-Anteil bei Winkelregelung |
- | |
1826 | else SummeNick += DiffNick; // I-Anteil bei HH |
- | |
1827 | if(SummeNick > (STICK_GAIN * 16000L)) SummeNick = (STICK_GAIN * 16000L); |
- | |
1828 | if(SummeNick < -(16000L * STICK_GAIN)) SummeNick = -(16000L * STICK_GAIN); |
- | |
1829 | - | ||
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; |
- | |
1833 | - | ||
1834 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
- | |
1835 | if(pd_ergebnis_nick > tmp_int) pd_ergebnis_nick = tmp_int; |
- | |
1836 | if(pd_ergebnis_nick < -tmp_int) pd_ergebnis_nick = -tmp_int; |
- | |
1837 | - | ||
1838 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1839 | // Roll-Achse |
- | |
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 |
- | |
1848 | else pd_ergebnis_roll = ((EE_Parameter.Gyro_Stability / 2) * DiffRoll) / 4; // Überlauf verhindern |
- | |
1849 | pd_ergebnis_roll += SummeRoll / Ki; |
- | |
1850 | - | ||
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; |
- | |
1854 | - | ||
1855 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1856 | // Universal Mixer |
- | |
1857 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | |
1858 | for(i=0; i<MAX_MOTORS; i++) |
- | |
1859 | { |
- | |
1860 | signed int tmp_int; |
- | |
1861 | if(Mixer.Motor[i][0] > 0) |
- | |
1862 | { |
- | |
1863 | // Gas |
- | |
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 |
- | |
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 | } |
- | |
Line 1893... | Line -... | ||
1893 | - | ||
1894 | LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4); |
- | |
1895 | Motor[i].SetPoint = tmp_int / 4; |
- | |
1896 | Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total) |
- | |
1897 | tmp_motorwert[i] = tmp_int; |
- | |
1898 | } |
- | |
1899 | else |
- | |
1900 | { |
1927 | |
1901 | Motor[i].SetPoint = 0; |
- | |
1902 | Motor[i].SetPointLowerBits = 0; |
- | |
1903 | } |
- | |
1904 | } |
1928 | return GasMischanteil; |
1905 | } |
- |