Rev 2426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2426 | Rev 2427 | ||
---|---|---|---|
Line 93... | Line 93... | ||
93 | int ErsatzKompassInGrad; // Kompasswert in Grad |
93 | int ErsatzKompassInGrad; // Kompasswert in Grad |
94 | int GierGyroFehler = 0; |
94 | int GierGyroFehler = 0; |
95 | char GyroFaktor,GyroFaktorGier; |
95 | char GyroFaktor,GyroFaktorGier; |
96 | char IntegralFaktor,IntegralFaktorGier; |
96 | char IntegralFaktor,IntegralFaktorGier; |
97 | int DiffNick,DiffRoll; |
97 | int DiffNick,DiffRoll; |
- | 98 | unsigned int StickGasHover = 127; |
|
98 | int StickGasHover = 127, HoverGasMin = 0, HoverGasMax = 1023; |
99 | int HoverGasMin = 0, HoverGasMax = 1023; |
99 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
100 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
100 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
101 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
101 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
102 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
102 | volatile unsigned char SenderOkay = 0; |
103 | volatile unsigned char SenderOkay = 0; |
103 | char MotorenEin = 0,StartTrigger = 0; |
104 | char MotorenEin = 0,StartTrigger = 0; |
Line 410... | Line 411... | ||
410 | tilt2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
411 | tilt2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
411 | tilt1 = (int16_t)ihypot(tilt1,tilt2); // tilt angle over all |
412 | tilt1 = (int16_t)ihypot(tilt1,tilt2); // tilt angle over all |
412 | CosAttitude = c_cos_8192(tilt1); |
413 | CosAttitude = c_cos_8192(tilt1); |
413 | NeutralAccZ = (long)((long) (NeutralAccZ - 512) * 8192 + 4096) / CosAttitude + 512; |
414 | NeutralAccZ = (long)((long) (NeutralAccZ - 512) * 8192 + 4096) / CosAttitude + 512; |
414 | if(tilt1 > 20) sucess = 0; // calibration must be within 20° Tilt angle |
415 | if(tilt1 > 20) sucess = 0; // calibration must be within 20° Tilt angle |
415 | if(AdjustmentMode != 0 && ACC_AltitudeControl) if((NeutralAccZ < 682 - 25) || (NeutralAccZ > 682 + 35)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; sucess = 0;}; |
416 | if(AdjustmentMode != 0 && ACC_AltitudeControl) if((NeutralAccZ < 682 - 30) || (NeutralAccZ > 682 + 35)) { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; sucess = 0;}; |
416 | #else |
417 | #else |
417 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
418 | NeutralAccZ = (int16_t)GetParamWord(PID_ACC_TOP); |
418 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
419 | EEAR = EE_DUMMY; // Set the EEPROM Address pointer to an unused space |
419 | #endif |
420 | #endif |
420 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
421 | if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
Line 613... | Line 614... | ||
613 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
614 | else FC_StatusFlags |= FC_STATUS_MOTOR_RUN; |
Line 614... | Line 615... | ||
614 | 615 | ||
Line 615... | Line 616... | ||
615 | // ++++++++++++++++++++++++++++++++++++++++++ |
616 | // ++++++++++++++++++++++++++++++++++++++++++ |
616 | 617 | ||
617 | // ++++++++++++++++++++++++++++++++++++++++++ |
618 | // ++++++++++++++++++++++++++++++++++++++++++ |
618 | #ifdef REDUNDANT_FC |
619 | #ifdef REDUNDANT_FC_SLAVE |
619 | I2CTimeout = 100; |
620 | I2CTimeout = 100; |
620 | return; |
621 | return; |
- | 622 | #endif |
|
621 | #else |
623 | |
622 | /* |
624 | #ifdef REDUNDANT_FC_MASTER |
623 | if(Parameter_UserParam7 < 100 && RedundanceBlOperation) |
625 | if(Parameter_UserParam7 > 150) |
624 | { |
626 | { |
625 | I2CTimeout = 100; |
627 | // Make noise |
626 | if((BeepMuster == 0xffff)) |
628 | if((BeepMuster == 0xffff)) { beeptime = 25000; BeepMuster = 0x0080; } |
627 | { |
- | |
- | 629 | // Do not send I2C-Data |
|
628 | beeptime = 25000; |
630 | if(RedundanceBlOperation) |
629 | BeepMuster = 0x0080; |
631 | { |
- | 632 | I2CTimeout = 100; |
|
630 | } |
633 | return; |
631 | return; |
- | |
632 | } |
634 | } |
Line 633... | Line 635... | ||
633 | */ |
635 | } |
634 | #endif |
636 | #endif |
635 | 637 | ||
Line 761... | Line 763... | ||
761 | CareFree = 0; |
763 | CareFree = 0; |
762 | } |
764 | } |
763 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; /*if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;*/} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
765 | if(CareFree) { FC_StatusFlags2 |= FC_STATUS2_CAREFREE; /*if(Parameter_AchsKopplung1 < 210) Parameter_AchsKopplung1 += 30;*/} else FC_StatusFlags2 &= ~FC_STATUS2_CAREFREE; |
764 | } |
766 | } |
Line -... | Line 767... | ||
- | 767 | ||
- | 768 | void CalcStickGasHover(void) |
|
- | 769 | { |
|
- | 770 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
|
- | 771 | { |
|
- | 772 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
|
- | 773 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
|
- | 774 | } |
|
- | 775 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
|
- | 776 | LIMIT_MIN_MAX(StickGasHover, 70, 175); // reserve some range for trim up and down |
|
- | 777 | } |
|
- | 778 | ||
765 | 779 | ||
766 | //############################################################################ |
780 | //############################################################################ |
767 | // |
781 | // |
768 | void MotorRegler(void) |
782 | void MotorRegler(void) |
769 | //############################################################################ |
783 | //############################################################################ |
Line 1621... | Line 1635... | ||
1621 | GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1635 | GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1622 | } |
1636 | } |
1623 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1637 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1624 | // Auto-Landing |
1638 | // Auto-Landing |
1625 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1639 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1626 | //#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
- | |
1627 | static unsigned char slower; |
1640 | static unsigned char slower; |
1628 | if(!slower--) |
1641 | if(!slower--) |
1629 | { |
1642 | { |
1630 | static unsigned int u_filter = 0; |
1643 | static unsigned int u_filter = 0; |
1631 | if(!u_filter) u_filter = UBat; |
1644 | if(!u_filter) u_filter = UBat; |
Line 1647... | Line 1660... | ||
1647 | if(LowVoltageLandingActive && FromNC_AltitudeSetpoint >= 0) |
1660 | if(LowVoltageLandingActive && FromNC_AltitudeSetpoint >= 0) |
1648 | { |
1661 | { |
1649 | FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed; |
1662 | FromNC_AltitudeSpeed = EE_Parameter.LandingSpeed; |
1650 | FromNC_AltitudeSetpoint = -20000; |
1663 | FromNC_AltitudeSetpoint = -20000; |
1651 | } |
1664 | } |
1652 | //#endif |
- | |
- | 1665 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
1653 | //DebugOut.Analog[16] = StickGasMiddle; |
1666 | // send SPI pending bytes |
1654 | if(BytegapSPI == 0) SPI_TransmitByte(); |
1667 | if(BytegapSPI == 0) SPI_TransmitByte(); |
1655 | - | ||
1656 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1668 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1657 | // Höhenregelung |
1669 | // Höhenregelung |
1658 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1670 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1659 | GasMischanteil *= STICK_GAIN; |
1671 | GasMischanteil *= STICK_GAIN; |
1660 | if(BytegapSPI == 0) SPI_TransmitByte(); |
- | |
1661 | // if height control is activated |
1672 | // if height control is activated |
1662 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F)) // Höhenregelung |
1673 | if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F)) // Höhenregelung |
1663 | { |
1674 | { |
1664 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1675 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1665 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1676 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
Line 1885... | Line 1896... | ||
1885 | } |
1896 | } |
1886 | HeightTrimming = 0; |
1897 | HeightTrimming = 0; |
1887 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1898 | LIMIT_MIN_MAX(SollHoehe, (HoehenWert-1024), (HoehenWert+1024)); // max. 10m Unterschied |
1888 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1899 | if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 100; |
1889 | //update hoover gas stick value when setpoint is shifted |
1900 | //update hoover gas stick value when setpoint is shifted |
- | 1901 | if(FromNC_AltitudeSpeed == 0) CalcStickGasHover(); |
|
- | 1902 | /* |
|
1890 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1903 | if(!EE_Parameter.Hoehe_StickNeutralPoint && FromNC_AltitudeSpeed == 0) |
1891 | { |
1904 | { |
1892 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1905 | StickGasHover = HoverGas/STICK_GAIN; //rescale back to stick value |
1893 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
1906 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
1894 | if(StickGasHover < 70) StickGasHover = 70; |
1907 | if(StickGasHover < 70) StickGasHover = 70; |
1895 | else if(StickGasHover > 150) StickGasHover = 150; |
1908 | else if(StickGasHover > 175) StickGasHover = 175; |
1896 | } |
1909 | } |
- | 1910 | */ |
|
1897 | } |
1911 | } |
1898 | if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active |
1912 | if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active |
1899 | } //if FCFlags & MKFCFLAG_FLY |
1913 | } //if FCFlags & MKFCFLAG_FLY |
1900 | else |
1914 | else |
1901 | { |
1915 | { |
1902 | SollHoehe = HoehenWert - 400; |
1916 | SollHoehe = HoehenWert - 400; |
1903 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1917 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1904 | else StickGasHover = 120; |
1918 | else StickGasHover = 127; |
1905 | HoverGas = GasMischanteil; |
1919 | HoverGas = GasMischanteil; |
1906 | VarioCharacter = '.'; |
1920 | VarioCharacter = '.'; |
1907 | } |
1921 | } |
1908 | HCGas = HoverGas; // take hover gas (neutral point) |
1922 | HCGas = HoverGas; // take hover gas (neutral point) |
1909 | } |
1923 | } |
Line 2049... | Line 2063... | ||
2049 | } |
2063 | } |
2050 | }// EOF height control active |
2064 | }// EOF height control active |
2051 | else // HC not active |
2065 | else // HC not active |
2052 | { |
2066 | { |
2053 | //update hoover gas stick value when HC is not active |
2067 | //update hoover gas stick value when HC is not active |
- | 2068 | CalcStickGasHover(); |
|
2054 | if(!EE_Parameter.Hoehe_StickNeutralPoint) |
2069 | /* if(!EE_Parameter.Hoehe_StickNeutralPoint) |
2055 | { |
2070 | { |
2056 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
2071 | StickGasHover = HoverGas/STICK_GAIN; // rescale back to stick value |
2057 | StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning; |
2072 | StickGasHover = (unsigned int)((unsigned int) StickGasHover * UBat) / BattLowVoltageWarning; |
2058 | } |
2073 | } |
2059 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
2074 | else StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
2060 | LIMIT_MIN_MAX(StickGasHover, 70, 150); // reserve some range for trim up and down |
2075 | LIMIT_MIN_MAX(StickGasHover, 70, 175); // reserve some range for trim up and down |
- | 2076 | */ |
|
2061 | FilterHCGas = GasMischanteil; |
2077 | FilterHCGas = GasMischanteil; |
2062 | // set both flags to indicate no vario mode |
2078 | // set both flags to indicate no vario mode |
2063 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
2079 | FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN); |
2064 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
2080 | FC_StatusFlags2 &= ~FC_STATUS2_ALTITUDE_CONTROL; |
2065 | } |
2081 | } |
Line 2140... | Line 2156... | ||
2140 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2156 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
2141 | if(Capacity.MinOfMaxPWM < 40) SpeakHoTT = SPEAK_ERR_MOTOR; |
2157 | if(Capacity.MinOfMaxPWM < 40) SpeakHoTT = SPEAK_ERR_MOTOR; |
2142 | #endif |
2158 | #endif |
2143 | } |
2159 | } |
Line -... | Line 2160... | ||
- | 2160 | ||
- | 2161 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
2144 | 2162 | // send SPI pending bytes |
|
2145 | if(BytegapSPI == 0) SPI_TransmitByte(); |
2163 | if(BytegapSPI == 0) SPI_TransmitByte(); |
2146 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2164 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2147 | // + Mischer und PI-Regler |
2165 | // + Mischer und PI-Regler |
2148 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2166 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 2198... | Line 2216... | ||
2198 | 2216 | ||
2199 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
2217 | tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64; |
2200 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
2218 | if(pd_ergebnis_roll > tmp_int) pd_ergebnis_roll = tmp_int; |
Line -... | Line 2219... | ||
- | 2219 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
|
- | 2220 | ||
2201 | if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int; |
2221 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2202 | - | ||
2203 | if(BytegapSPI == 0) SPI_TransmitByte(); |
2222 | // send SPI pending bytes |
2204 | 2223 | if(BytegapSPI == 0) SPI_TransmitByte(); |
|
2205 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2224 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2206 | // Universal Mixer |
2225 | // Universal Mixer |
2207 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2226 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 2222... | Line 2241... | ||
2222 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
2241 | else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L; |
2223 | // Gier |
2242 | // Gier |
2224 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
2243 | if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil; |
2225 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
2244 | else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil; |
2226 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
2245 | else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L; |
2227 | #ifdef REDUNDANT_FC |
2246 | #ifdef REDUNDANT_FC_SLAVE |
2228 | tmp_int = (tmp_motorwert[i] + tmp_int) / 2; |
2247 | tmp_int = (tmp_motorwert[i] + tmp_int) / 2; |
2229 | #else |
2248 | #else |
2230 | if(Motor[i].Version & MOTOR_STATE_FAST_MODE || tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // Beschleunigen |
2249 | if(Motor[i].Version & MOTOR_STATE_FAST_MODE || tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2; // Beschleunigen |
2231 | else |
2250 | else |
2232 | { // BL-Ctrl 1.0 or 2.0 |
2251 | { // BL-Ctrl 1.0 or 2.0 |
Line 2251... | Line 2270... | ||
2251 | { |
2270 | { |
2252 | Motor[i].SetPoint = 0; |
2271 | Motor[i].SetPoint = 0; |
2253 | Motor[i].SetPointLowerBits = 0; |
2272 | Motor[i].SetPointLowerBits = 0; |
2254 | } |
2273 | } |
2255 | } |
2274 | } |
- | 2275 | #ifdef REDUNDANT_FC_MASTER |
|
2256 | //if(Parameter_UserParam6 > 200) Motor[0].SetPoint = 0; |
2276 | if(Parameter_UserParam6 > 200 && RedundanceBlOperation) Motor[0].SetPoint = 0; |
- | 2277 | #endif |
|
2257 | } |
2278 | } |
2258 | //DebugOut.Analog[16] |
2279 | //DebugOut.Analog[16] |