60,7 → 60,6 |
|
unsigned char h,m,s; |
unsigned int BaroExpandActive = 0; |
signed int ACC_AMPLIFY = 6; |
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll; |
int TrimNick, TrimRoll; |
int AdNeutralNick = 0,AdNeutralRoll = 0,AdNeutralGier = 0,StartNeutralRoll = 0,StartNeutralNick = 0; |
118,7 → 117,7 |
unsigned char Looping_Links = 0, Looping_Rechts = 0, Looping_Unten = 0, Looping_Oben = 0; |
|
unsigned char Parameter_Luftdruck_D = 48; // Wert : 0-250 |
unsigned char Parameter_HoehenSchalter = 251; // Wert : 0-250 |
unsigned char Parameter_HoehenSchalter = 251; // Wert : 0-250 |
unsigned char Parameter_Hoehe_P = 16; // Wert : 0-32 |
unsigned char Parameter_Hoehe_ACC_Wirkung = 58; // Wert : 0-250 |
unsigned char Parameter_KompassWirkung = 64; // Wert : 0-250 |
140,6 → 139,8 |
unsigned char Parameter_UserParam8 = 0; |
unsigned char Parameter_ServoNickControl = 100; |
unsigned char Parameter_ServoRollControl = 100; |
unsigned char Parameter_ServoNickComp = 50; |
unsigned char Parameter_ServoRollComp = 85; |
unsigned char Parameter_LoopGasLimit = 70; |
unsigned char Parameter_AchsKopplung1 = 90; |
unsigned char Parameter_AchsKopplung2 = 65; |
165,7 → 166,6 |
unsigned char Parameter_MaximumAltitude; |
unsigned char Parameter_Servo3,Parameter_Servo4,Parameter_Servo5; |
unsigned char CareFree = 0; |
//signed char AccShorter = 0; |
const signed char sintab[31] = { 0, 2, 4, 6, 7, 8, 8, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -8, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 8}; // 15° steps |
|
signed int ExternStickNick = 0,ExternStickRoll = 0,ExternStickGier = 0, ExternHoehenValue = -20; |
178,8 → 178,9 |
char VarioCharacter = ' '; |
unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing |
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while |
int Variance = 0; |
int CosAttitude; // for projection of hoover gas |
signed int Variance = 0; |
signed int CosAttitude; // for projection of hoover gas |
unsigned char ACC_AltitudeControl = 0; |
|
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Debugwerte zuordnen |
191,9 → 192,9 |
DebugOut.Analog[2] = Mittelwert_AccNick / 4; |
DebugOut.Analog[3] = Mittelwert_AccRoll / 4; |
DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier; |
DebugOut.Analog[5] = HoehenWert;///5; |
DebugOut.Analog[5] = HoehenWert/10; |
DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512); |
DebugOut.Analog[8] = AdWertAccHoch;//KompassValue; |
DebugOut.Analog[8] = KompassValue; |
DebugOut.Analog[9] = UBat; |
DebugOut.Analog[10] = SenderOkay; |
DebugOut.Analog[11] = ErsatzKompassInGrad; |
201,26 → 202,25 |
DebugOut.Analog[13] = Motor[1].SetPoint; |
DebugOut.Analog[14] = Motor[2].SetPoint; |
DebugOut.Analog[15] = Motor[3].SetPoint; |
DebugOut.Analog[16] = Variance; |
DebugOut.Analog[17] = vv; |
DebugOut.Analog[18] = HoehenWertF; |
DebugOut.Analog[20] = ServoNickValue; |
DebugOut.Analog[22] = Capacity.ActualCurrent; |
DebugOut.Analog[23] = Capacity.UsedCapacity; |
DebugOut.Analog[24] = SollHoehe; |
DebugOut.Analog[25] = Parameter_Hoehe_P; |
DebugOut.Analog[26] = Parameter_Luftdruck_D; |
// DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ; |
// DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay; |
DebugOut.Analog[24] = SollHoehe/10; |
DebugOut.Analog[27] = KompassSollWert; |
DebugOut.Analog[29] = Capacity.MinOfMaxPWM; |
DebugOut.Analog[30] = GPS_Nick; |
DebugOut.Analog[31] = GPS_Roll; |
if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe; |
|
DebugOut.Analog[16] = Variance; |
DebugOut.Analog[17] = VerticalVelocity; |
DebugOut.Analog[18] = HoehenWertF; |
DebugOut.Analog[25] = Parameter_Hoehe_P; |
DebugOut.Analog[26] = Parameter_Luftdruck_D; |
|
} |
|
|
|
void Piep(unsigned char Anzahl, unsigned int dauer) |
{ |
unsigned int wait = 0; |
356,9 → 356,8 |
Mess_Integral_Gier = 0; |
StartLuftdruck = Luftdruck; |
VarioMeter = 0; |
vvSum = 0; |
SummenHoehe = 0; |
Mess_Integral_Hoch = 0; |
VerticalVelocitySum = 0; |
SummenHoehe = 0; Mess_Integral_Hoch = 0; |
KompassSollWert = KompassValue; |
KompassSignalSchlecht = 100; |
beeptime = 50; |
372,7 → 371,6 |
FromNaviCtrl_Value.Kalman_K = -1; |
FromNaviCtrl_Value.Kalman_MaxDrift = 0; |
FromNaviCtrl_Value.Kalman_MaxFusion = 32; |
|
for(i=0;i<8;i++) |
{ |
Poti[i] = PPM_in[EE_Parameter.Kanalbelegung[K_POTI1 + i]] + 127; |
388,7 → 386,7 |
// else |
NickServoValue = ((128 - 60) * 4 * 16); // neutral position = lower 1/4 |
} |
|
|
if((AdNeutralNick < 150 * 16) || (AdNeutralNick > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; }; |
if((AdNeutralRoll < 150 * 16) || (AdNeutralRoll > 850 * 16)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; }; |
if((AdNeutralGier < 150 * 2) || (AdNeutralGier > 850 * 2)) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; }; |
559,6 → 557,7 |
if(!MotorenEin) |
{ |
FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY); |
FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF; |
for(i=0;i<MAX_MOTORS;i++) |
{ |
if(!PC_MotortestActive) MotorTest[i] = 0; |
642,6 → 641,8 |
CHK_POTI(Parameter_UserParam8,EE_Parameter.UserParam8); |
CHK_POTI(Parameter_ServoNickControl,EE_Parameter.ServoNickControl); |
CHK_POTI(Parameter_ServoRollControl,EE_Parameter.ServoRollControl); |
CHK_POTI(Parameter_ServoNickComp,EE_Parameter.ServoNickComp); |
CHK_POTI(Parameter_ServoRollComp,EE_Parameter.ServoRollComp); |
CHK_POTI(Parameter_LoopGasLimit,EE_Parameter.LoopGasLimit); |
CHK_POTI(Parameter_AchsKopplung1,EE_Parameter.AchsKopplung1); |
CHK_POTI(Parameter_AchsKopplung2,EE_Parameter.AchsKopplung2); |
779,21 → 780,26 |
SummeRoll = 0; |
sollGier = 0; |
Mess_Integral_Gier = 0; |
FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF; |
} |
else |
{ |
FC_StatusFlags |= FC_STATUS_FLY; |
if(!(FC_StatusFlags2 & FC_STATUS2_TAKEOFF)) |
if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) |
{ |
if(HoehenWert > 150) |
if(abs(HoehenWert) > 150 || !(Parameter_GlobalConfig & CFG_HOEHENREGELUNG)) |
{ |
FC_StatusFlags2 |= FC_STATUS2_TAKEOFF; |
FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF; |
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
SpeakHoTT = SPEAK_RISING; |
#endif |
beeptime = 5000; |
} |
} |
SummeNick = 0; |
SummeRoll = 0; |
Mess_Integral_Gier = 0; |
if(modell_fliegt < 256) sollGier = 0; |
// sollGier = 0; |
if(modell_fliegt > 1000) modell_fliegt = 1000; // for the Hooverpoint-Estimation |
} |
} |
if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0) |
855,7 → 861,7 |
SetNeutral(1); |
CalibrationDone = 1; |
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
SpeakHoTT = SPEAK_CALIBRATE; |
SpeakHoTT = SPEAK_CALIBRATE; |
#endif |
Piep(GetActiveParamSet(),120); |
} |
880,6 → 886,10 |
// Einschalten |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START; |
StartLuftdruck = Luftdruck; |
HoehenWertF = 0; |
HoehenWert = 0; |
SummenHoehe = 0; |
if(++delay_einschalten > 253) |
{ |
delay_einschalten = 0; |
1085,9 → 1095,6 |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// Bei Empfangsausfall im Flug |
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
//DebugOut.Analog[16] = GasIsZeroCnt; |
//DebugOut.Analog[17] = VarioMeter; |
|
if(FC_StatusFlags2 & FC_STATUS2_RC_FAILSAVE_ACTIVE) |
{ |
StickNick = -GPS_Nick; |
1152,13 → 1159,6 |
tmp_long /= 2; |
tmp_long2 /= 2; |
} |
/* |
if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25) |
{ |
tmp_long /= 3; |
tmp_long2 /= 3; |
} |
*/ |
if(tmp_long > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
if(tmp_long < (long)-FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long = (long)-FromNaviCtrl_Value.Kalman_MaxFusion; |
if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion) tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion; |
1456,7 → 1456,6 |
static int HeightDeviation = 0, FilterHCGas = 0; |
static unsigned long HoverGasFilter = 0; |
static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0; |
// int CosAttitude; // for projection of hoover gas |
|
// get the current hooverpoint |
DebugOut.Analog[21] = HoverGas; |
1504,8 → 1503,14 |
else // delay, because of expanding the Baro-Range |
{ |
// now clear the D-values |
SummenHoehe = HoehenWert * SM_FILTER; |
vvSum = 0; |
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
if(ACC_AltitudeControl) SummenHoehe = HoehenWert * SA_FILTER; |
else SummenHoehe = HoehenWert * SM_FILTER; |
#else |
SummenHoehe = HoehenWert * SM_FILTER; |
#endif |
|
VerticalVelocitySum = 0; |
VarioMeter = 0; |
BaroExpandActive--; |
} |
1518,10 → 1523,10 |
if(!delay--) |
{ |
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
if(HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
if(!SpeakHoTT && HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_OFF; |
#endif |
HoehenReglerAktiv = 0; // disable height control |
SollHoehe = HoehenWertF; // update SetPoint with current reading |
SollHoehe = HoehenWert; // update SetPoint with current reading |
delay = 1; |
} |
} |
1529,10 → 1534,10 |
if(Parameter_HoehenSchalter > 70) |
{ //height control is activated |
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
if(!HoehenReglerAktiv && !SpeakHoTT) SpeakHoTT = SPEAK_ALTITUDE_ON; |
if(!SpeakHoTT && !HoehenReglerAktiv) SpeakHoTT = SPEAK_ALTITUDE_ON; |
#endif |
delay = 200; |
HoehenReglerAktiv = 1; // enable height control |
delay = 200; |
} |
} |
else // no switchable height control |
1540,7 → 1545,6 |
SollHoehe = ((int16_t) ExternHoehenValue + (int16_t) Parameter_HoehenSchalter) * (int)EE_Parameter.Hoehe_Verstaerkung; |
HoehenReglerAktiv = 1; |
} |
|
// calculate cos of nick and roll angle used for projection of the vertical hoover gas |
tmp_int = (int)(IntegralNick/GIER_GRAD_FAKTOR); // nick angle in deg |
tmp_int2 = (int)(IntegralRoll/GIER_GRAD_FAKTOR); // roll angle in deg |
1547,8 → 1551,6 |
CosAttitude = (int16_t)ihypot(tmp_int, tmp_int2); // phytagoras gives effective attitude angle in deg |
LIMIT_MAX(CosAttitude, 60); // limit effective attitude angle |
CosAttitude = c_cos_8192(CosAttitude); // cos of actual attitude |
//AccShorter = CosAttitude / 32 - 256; |
//AccShorter = (CosAttitude - 8192) / 40; |
VarioCharacter = ' '; |
AltitudeSetpointTrimming = 0; |
if(HoehenReglerAktiv && !(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
1578,7 → 1580,7 |
{ // gas stick is above hoover point |
if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit) |
{ |
if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth |
if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth |
if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN) |
{ |
FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN; |
1693,6 → 1695,8 |
} |
if(HoehenWertF > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)) |
{ |
if(!ACC_AltitudeControl) |
{ |
// from this point the Heigth Control Algorithm is identical for both versions |
if(BaroExpandActive) // baro range expanding active |
{ |
1706,25 → 1710,8 |
LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
HeightDeviation = (int)(tmp_long); // positive when too high |
tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense |
LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
GasReduction = tmp_long; |
// ------------------------- D-Part ---------------------------- Qopter: neu |
tmp_long = vv + AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung/256; |
if(WaypointTrimming) { |
Variance = AltitudeSetpointTrimming*8; |
} else { |
Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32; |
} |
tmp_long -= (long)Variance; |
tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter |
LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN); |
GasReduction += tmp_long; |
} // EOF no baro range expanding |
|
HCGas -= GasReduction; |
LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point |
|
/* Qopter: deaktiviert |
// ------------------------- D-Part 1: Vario Meter ---------------------------- |
tmp_int = VarioMeter / 8; |
LIMIT_MIN_MAX(tmp_int, -127, 128); |
1775,7 → 1762,6 |
} |
} |
} |
*/ |
// strech control output by inverse attitude projection 1/cos |
// + 1/cos(angle) ++++++++++++++++++++++++++ |
tmp_long2 = (int32_t)HCGas; |
1792,8 → 1778,59 |
LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
GasMischanteil = FilterHCGas; |
} |
// else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode |
} |
else |
{ |
// from this point the Heigth Control Algorithm is identical for both versions |
if(BaroExpandActive) // baro range expanding active |
{ |
HCGas = HoverGas; // hover while expanding baro adc range |
HeightDeviation = 0; |
} // EOF // baro range expanding active |
else // valid data from air pressure sensor |
{ |
// ------------------------- P-Part ---------------------------- |
tmp_long = (HoehenWertF - SollHoehe); // positive when too high |
LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
HeightDeviation = (int)(tmp_long); // positive when too high |
tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense |
GasReduction = tmp_long; |
// ------------------------ D-Part: ACC-Z Integral ------------------------ |
tmp_long = VerticalVelocity + AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung/256; |
// ------------------------- D-Part: Vario Meter ---------------------------- |
if(WaypointTrimming) { |
Variance = AltitudeSetpointTrimming * 8; |
} else { |
Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32; |
} |
tmp_long -= (long)Variance; |
tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter |
LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN); |
GasReduction += tmp_long; |
} // EOF no baro range expanding |
DebugOut.Analog[19] = -GasReduction; |
HCGas -= GasReduction; |
LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point |
// strech control output by inverse attitude projection 1/cos |
// + 1/cos(angle) ++++++++++++++++++++++++++ |
tmp_long2 = (int32_t)HCGas; |
tmp_long2 *= 8192L; |
tmp_long2 /= CosAttitude; |
HCGas = (int16_t)tmp_long2; |
// update height control gas averaging |
FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE; |
// limit height control gas pd-control output |
LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN); |
// set GasMischanteil to HeightControlGasFilter |
if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT) |
{ // old version |
LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
GasMischanteil = FilterHCGas; |
} |
else GasMischanteil = FilterHCGas;// + (GasMischanteil - HoverGas) / 4; // Qopter: geändert |
} |
} |
}// EOF height control active |
else // HC not active |
1815,8 → 1852,8 |
// this is done only if height contol option is selected in global config and aircraft is flying |
if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING)) |
{ |
// if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // Qopter: geändert |
//if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // Qopter: geändert |
if(StartTrigger == 1) StartTrigger = 2; |
tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
tmp_long2 *= CosAttitude; // apply attitude projection |
1833,8 → 1870,8 |
HoverGasFilter += 4L * tmp_long2; |
} |
else //later |
// if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
if(abs(vv) < 50 && abs(HoehenWertF - SollHoehe) < 256) // Qopter: geändert, Anpassung nötig? |
//if(abs(VerticalVelocity) < 50 && abs(HoehenWertF - SollHoehe) < 256) // Qopter: geändert, Anpassung nötig? |
if(abs(VarioMeter) < 100 && abs(HoehenWert - SollHoehe) < 256) // only on small vertical speed & difference is small (only descending) |
{ |
HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
HoverGasFilter += tmp_long2; |