Subversion Repositories FlightCtrl

Rev

Rev 2296 | Rev 2316 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2296 Rev 2309
Line 176... Line 176...
176
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
176
signed int KopplungsteilNickRoll,KopplungsteilRollNick;
177
signed int tmp_motorwert[MAX_MOTORS];
177
signed int tmp_motorwert[MAX_MOTORS];
178
char VarioCharacter = ' ';
178
char VarioCharacter = ' ';
179
unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing
179
unsigned int HooverGasEmergencyPercent = 0; // The gas value for Emergency landing
180
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
180
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
-
 
181
signed int Variance = 0;
-
 
182
signed int CosAttitude; // for projection of hoover gas
-
 
183
unsigned char ACC_AltitudeControl = 0;
Line 181... Line 184...
181
 
184
 
182
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
183
//  Debugwerte zuordnen
186
//  Debugwerte zuordnen
184
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 187... Line 190...
187
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
190
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
188
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
191
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
189
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
192
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
190
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
193
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
191
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
194
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
192
    DebugOut.Analog[5] = HoehenWert/5;
195
    DebugOut.Analog[5] = HoehenWert/10;
193
    DebugOut.Analog[6] = AdWertAccHoch;//(Mess_Integral_Hoch / 512);// Aktuell_az;
196
    DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512);
194
    DebugOut.Analog[8] = KompassValue;
197
    DebugOut.Analog[8] = KompassValue;
195
    DebugOut.Analog[9] = UBat;
198
    DebugOut.Analog[9] = UBat;
196
    DebugOut.Analog[10] = SenderOkay;
199
    DebugOut.Analog[10] = SenderOkay;
197
    DebugOut.Analog[11] = ErsatzKompassInGrad;
200
    DebugOut.Analog[11] = ErsatzKompassInGrad;
198
    DebugOut.Analog[12] = Motor[0].SetPoint;
201
    DebugOut.Analog[12] = Motor[0].SetPoint;
Line 200... Line 203...
200
    DebugOut.Analog[14] = Motor[2].SetPoint;
203
    DebugOut.Analog[14] = Motor[2].SetPoint;
201
    DebugOut.Analog[15] = Motor[3].SetPoint;
204
    DebugOut.Analog[15] = Motor[3].SetPoint;
202
    DebugOut.Analog[20] = ServoNickValue;
205
    DebugOut.Analog[20] = ServoNickValue;
203
    DebugOut.Analog[22] = Capacity.ActualCurrent;
206
    DebugOut.Analog[22] = Capacity.ActualCurrent;
204
    DebugOut.Analog[23] = Capacity.UsedCapacity;
207
    DebugOut.Analog[23] = Capacity.UsedCapacity;
205
        DebugOut.Analog[24] = SollHoehe/5;     
208
        DebugOut.Analog[24] = SollHoehe/10;    
206
//    DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
-
 
207
//    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
-
 
208
    DebugOut.Analog[27] = KompassSollWert;
209
    DebugOut.Analog[27] = KompassSollWert;
209
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
210
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
210
    DebugOut.Analog[30] = GPS_Nick;
211
    DebugOut.Analog[30] = GPS_Nick;
211
    DebugOut.Analog[31] = GPS_Roll;
212
    DebugOut.Analog[31] = GPS_Roll;
212
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
213
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
213
}
-
 
Line -... Line 214...
-
 
214
 
-
 
215
DebugOut.Analog[16] = Variance;
-
 
216
DebugOut.Analog[17] = VerticalVelocity;        
-
 
217
DebugOut.Analog[18] = HoehenWertF;             
-
 
218
DebugOut.Analog[25] = Parameter_Hoehe_P;
-
 
219
DebugOut.Analog[26] = Parameter_Luftdruck_D;
-
 
220
 
Line 214... Line 221...
214
 
221
}
215
 
222
 
216
 
223
 
Line 347... Line 354...
347
    Mess_IntegralNick = IntegralNick;
354
    Mess_IntegralNick = IntegralNick;
348
    Mess_IntegralRoll = IntegralRoll;
355
    Mess_IntegralRoll = IntegralRoll;
349
    Mess_Integral_Gier = 0;
356
    Mess_Integral_Gier = 0;
350
    StartLuftdruck = Luftdruck;
357
    StartLuftdruck = Luftdruck;
351
    VarioMeter = 0;
358
    VarioMeter = 0;
-
 
359
        VerticalVelocitySum = 0;
352
    Mess_Integral_Hoch = 0;
360
        SummenHoehe = 0;    Mess_Integral_Hoch = 0;
353
    KompassSollWert = KompassValue;
361
    KompassSollWert = KompassValue;
354
        KompassSignalSchlecht = 100;
362
        KompassSignalSchlecht = 100;
355
    beeptime = 50;
363
    beeptime = 50;
356
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
364
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
357
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
365
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
Line 547... Line 555...
547
{
555
{
548
 unsigned char i;
556
 unsigned char i;
549
    if(!MotorenEin)
557
    if(!MotorenEin)
550
        {
558
        {
551
         FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY);
559
         FC_StatusFlags &= ~(FC_STATUS_MOTOR_RUN | FC_STATUS_FLY);
-
 
560
                 FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF;
552
                 for(i=0;i<MAX_MOTORS;i++)
561
                 for(i=0;i<MAX_MOTORS;i++)
553
                  {
562
                  {
554
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
563
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
555
                   Motor[i].SetPoint = MotorTest[i];
564
                   Motor[i].SetPoint = MotorTest[i];
556
                   Motor[i].SetPointLowerBits = 0;
565
                   Motor[i].SetPointLowerBits = 0;
Line 764... Line 773...
764
            if(GasMischanteil > 40 && MotorenEin)
773
            if(GasMischanteil > 40 && MotorenEin)
765
                {
774
                {
766
                if(modell_fliegt < 0xffff) modell_fliegt++;
775
                if(modell_fliegt < 0xffff) modell_fliegt++;
767
                }
776
                }
768
            if((modell_fliegt < 256))
777
            if((modell_fliegt < 256))
769
                {
778
             {
770
                SummeNick = 0;
779
                SummeNick = 0;
771
                SummeRoll = 0;
780
                SummeRoll = 0;
772
                sollGier = 0;
781
                sollGier = 0;
773
                Mess_Integral_Gier = 0;
782
                Mess_Integral_Gier = 0;
-
 
783
                                FC_StatusFlags2 |= FC_STATUS2_WAIT_FOR_TAKEOFF;
-
 
784
             }
-
 
785
                        else
-
 
786
                         {
774
                } else FC_StatusFlags |= FC_STATUS_FLY;
787
               FC_StatusFlags |= FC_STATUS_FLY;
-
 
788
                           if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF)
-
 
789
                           {
-
 
790
/*
-
 
791
if(Parameter_UserParam3 > 50)
-
 
792
 {
-
 
793
   FromNC_AltitudeSpeed = 15;
-
 
794
   FromNC_AltitudeSetpoint = 500;
-
 
795
 }
-
 
796
*/
-
 
797
                            if(HoehenWert > 150 || HoehenWert < -350 || !(Parameter_GlobalConfig & CFG_HOEHENREGELUNG))
-
 
798
                                 {
-
 
799
                                  FC_StatusFlags2 &= ~FC_STATUS2_WAIT_FOR_TAKEOFF;
-
 
800
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
801
SpeakHoTT = SPEAK_RISING;
-
 
802
//SollHoehe = 250;
-
 
803
#endif
-
 
804
                                  beeptime = 5000;
-
 
805
                                 }
-
 
806
                SummeNick = 0;
-
 
807
                SummeRoll = 0;
-
 
808
                Mess_Integral_Gier = 0;
-
 
809
//                              sollGier = 0;
-
 
810
                                if(modell_fliegt > 1000) modell_fliegt = 1000;  // for the Hooverpoint-Estimation
-
 
811
                           }
-
 
812
/*
-
 
813
else
-
 
814
if(Parameter_UserParam3 > 150)
-
 
815
 {
-
 
816
if(HoehenWert > 2500) FromNC_AltitudeSpeed = 30;
-
 
817
else
-
 
818
if(HoehenWert > 1500) FromNC_AltitudeSpeed = 30;
-
 
819
else
-
 
820
 {
-
 
821
  FromNC_AltitudeSpeed = 10;
-
 
822
  SummeNick -= SummeNick / 4;
-
 
823
  SummeRoll -= SummeRoll / 4;
-
 
824
 }
-
 
825
 FromNC_AltitudeSetpoint = -300;
-
 
826
 }
775
 
827
*/
-
 
828
                         }  
776
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
829
            if((PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] > 80) && MotorenEin == 0)
777
                {
830
                {
778
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
831
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
779
// auf Nullwerte kalibrieren
832
// auf Nullwerte kalibrieren
780
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
833
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 813... Line 866...
813
                           SetNeutral(0);
866
                           SetNeutral(0);
814
                           CalibrationDone = 1;
867
                           CalibrationDone = 1;
815
                                                   ServoActive = 1;
868
                                                   ServoActive = 1;
816
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
869
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
817
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
870
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
871
                                                   if(abs(Aktuell_az - NeutralAccZ) > 5 && ACC_AltitudeControl)  { VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP; };
-
 
872
                                                   if(VersionInfo.HardwareError[0]) SpeakHoTT = SPEAK_ERR_SENSOR;
818
                                                   SpeakHoTT = SPEAK_CALIBRATE;
873
                                                   else SpeakHoTT = SPEAK_CALIBRATE;
819
#endif
874
#endif
820
                           Piep(GetActiveParamSet(),120);
875
                           Piep(GetActiveParamSet(),120);
821
                         }
876
                         }
822
                        }
877
                        }
823
                    }
878
                    }
Line 855... Line 910...
855
                                                {
910
                                                {
856
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
911
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
857
// Einschalten
912
// Einschalten
858
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
913
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
859
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
914
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
-
 
915
                                                        StartLuftdruck = Luftdruck;
-
 
916
                                                        HoehenWertF = 0;
-
 
917
                                                        HoehenWert = 0;
-
 
918
                                                        SummenHoehe = 0;
860
                                                        if(++delay_einschalten > 253)
919
                                                        if(++delay_einschalten > 253)
861
                                                        {
920
                                                        {
862
                                                                delay_einschalten = 0;
921
                                                                delay_einschalten = 0;
863
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
922
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
864
                                                                {
923
                                                                {
Line 1124... Line 1183...
1124
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1183
                if((MaxStickNick > 64) || (MaxStickRoll > 64))
1125
                {
1184
                {
1126
                tmp_long  /= 2;
1185
                tmp_long  /= 2;
1127
                tmp_long2 /= 2;
1186
                tmp_long2 /= 2;
1128
                }
1187
                }
1129
/*              if(abs(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]) > 25)
-
 
1130
                {
-
 
1131
                tmp_long  /= 3;
-
 
1132
                tmp_long2 /= 3;
-
 
1133
                }
-
 
1134
*/              if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1188
                if(tmp_long >  (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1135
                if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1189
                if(tmp_long <  (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long  = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1136
                if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1190
                if(tmp_long2 > (long) FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long) FromNaviCtrl_Value.Kalman_MaxFusion;
1137
                if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1191
                if(tmp_long2 < (long)-FromNaviCtrl_Value.Kalman_MaxFusion)  tmp_long2 = (long)-FromNaviCtrl_Value.Kalman_MaxFusion;
1138
     }
1192
     }
1139
     else
1193
     else
Line 1325... Line 1379...
1325
         NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen
1379
         NeueKompassRichtungMerken = 50; // eine Sekunde zum Einloggen
1326
        };
1380
        };
1327
     }
1381
     }
1328
    tmp_int  = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1382
    tmp_int  = (long) EE_Parameter.StickGier_P * ((long)StickGier * abs(StickGier)) / 512L; // expo  y = ax + bx²
1329
    tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4;
1383
    tmp_int += (EE_Parameter.StickGier_P * StickGier) / 4;
-
 
1384
        if(GasIsZeroCnt > 512) tmp_int = 0; // disable Yawing when Gas-Stick is to Zero
1330
        tmp_int += CompassGierSetpoint;
1385
        tmp_int += CompassGierSetpoint;
1331
    sollGier = tmp_int;
1386
    sollGier = tmp_int;
1332
    Mess_Integral_Gier -= tmp_int;
1387
    Mess_Integral_Gier -= tmp_int;
1333
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1388
    if(Mess_Integral_Gier > 50000) Mess_Integral_Gier = 50000;  // begrenzen
1334
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
1389
    if(Mess_Integral_Gier <-50000) Mess_Integral_Gier =-50000;
Line 1421... Line 1476...
1421
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1476
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1422
#define OPA_OFFSET_STEP 15
1477
#define OPA_OFFSET_STEP 15
1423
#else
1478
#else
1424
#define OPA_OFFSET_STEP 10
1479
#define OPA_OFFSET_STEP 10
1425
#endif
1480
#endif
1426
                int HCGas, HeightDeviation = 0,GasReduction = 0;
1481
                int HCGas, GasReduction = 0;
1427
                static int HeightTrimming = 0;  // rate for change of height setpoint
1482
                static int HeightTrimming = 0;  // rate for change of height setpoint
1428
                static int FilterHCGas = 0;
1483
                static int HeightDeviation = 0, FilterHCGas = 0;
1429
                static unsigned long HoverGasFilter = 0;
1484
                static unsigned long HoverGasFilter = 0;
1430
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1485
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1431
            int CosAttitude;    // for projection of hoover gas
-
 
Line 1432... Line 1486...
1432
 
1486
 
1433
                // get the current hooverpoint
1487
                // get the current hooverpoint
Line 1434... Line 1488...
1434
                DebugOut.Analog[21] = HoverGas;
1488
                DebugOut.Analog[21] = HoverGas;
Line 1474... Line 1528...
1474
                        }
1528
                        }
1475
                   }
1529
                   }
1476
                   else // delay, because of expanding the Baro-Range
1530
                   else // delay, because of expanding the Baro-Range
1477
                   {
1531
                   {
1478
                    // now clear the D-values
1532
                    // now clear the D-values
-
 
1533
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
1534
                          if(ACC_AltitudeControl) SummenHoehe = HoehenWert * SA_FILTER;
1479
                          SummenHoehe = HoehenWert * SM_FILTER;
1535
                          else SummenHoehe = HoehenWert * SM_FILTER;
-
 
1536
#else 
-
 
1537
              SummenHoehe = HoehenWert * SM_FILTER;
-
 
1538
#endif
-
 
1539
 
-
 
1540
                          VerticalVelocitySum = 0;
1480
                          VarioMeter = 0;
1541
                          VarioMeter = 0;
1481
                          BaroExpandActive--;
1542
                          BaroExpandActive--;
1482
                   }
1543
                   }
Line 1483... Line 1544...
1483
 
1544
 
Line 1544... Line 1605...
1544
                // the setpoint will be fine adjusted with the gas stick position
1605
                // the setpoint will be fine adjusted with the gas stick position
1545
                        if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying
1606
                        if(FC_StatusFlags & FC_STATUS_FLY) // trim setpoint only when flying
1546
                        {   // gas stick is above hoover point
1607
                        {   // gas stick is above hoover point
1547
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1608
                                if(StickGas > (StickGasHover + HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtUpperLimit)
1548
                                {
1609
                                {
-
 
1610
if(HeightDeviation > 20) SollHoehe = HoehenWertF; // update setpoint to current heigth 
1549
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)
1611
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)
1550
                                        {
1612
                                        {
1551
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1613
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1552
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1614
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1553
                                        }
1615
                                        }
1554
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1616
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_UP;
1555
                                        // Limit the maximum Altitude
1617
                                        // Limit the maximum Altitude
1556
                                        if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0;
1618
                                        if(Parameter_MaximumAltitude && (SollHoehe/100 > Parameter_MaximumAltitude)) AltitudeSetpointTrimming = 0;
1557
                                        else
1619
                                        else
Line 1566... Line 1628...
1566
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1628
                                else if(StickGas < (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD) && !BaroAtLowerLimit )
1567
                                {
1629
                                {
1568
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP)
1630
                                        if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP)
1569
                                        {
1631
                                        {
1570
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1632
                                                FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1571
                                                SollHoehe = HoehenWert; // update setpoint to current heigth
1633
                                                SollHoehe = HoehenWertF; // update setpoint to current heigth
1572
                                        }
1634
                                        }
1573
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1635
                                        FC_StatusFlags |= FC_STATUS_VARIO_TRIM_DOWN;
1574
                                        AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1636
                                        AltitudeSetpointTrimming = -abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1575
//                                      HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1637
//                                      HeightTrimming -= abs(StickGas - (StickGasHover - HEIGHT_CONTROL_STICKTHRESHOLD));
1576
                                        VarioCharacter = '-';
1638
                                        VarioCharacter = '-';
Line 1587... Line 1649...
1587
                                                WaypointTrimming = 10;
1649
                                                WaypointTrimming = 10;
1588
                                                VarioCharacter = '^';
1650
                                                VarioCharacter = '^';
1589
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)  // changed from sinking to rising
1651
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_DOWN)  // changed from sinking to rising
1590
                                                {
1652
                                                {
1591
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1653
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_DOWN;
1592
                                                        SollHoehe = HoehenWert; // update setpoint to current heigth
1654
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1593
                                                }
1655
                                                }
1594
                                         }
1656
                                         }
1595
                                         else
1657
                                         else
1596
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken
1658
                    if(FromNC_AltitudeSpeed && FromNC_AltitudeSetpoint < SollHoehe) // von NC gesteuert -> sinken
1597
                                         {
1659
                                         {
Line 1601... Line 1663...
1601
                                                WaypointTrimming = -10;
1663
                                                WaypointTrimming = -10;
1602
                                                VarioCharacter = 'v';
1664
                                                VarioCharacter = 'v';
1603
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking
1665
                                                if(FC_StatusFlags & FC_STATUS_VARIO_TRIM_UP) // changed from rising to sinking
1604
                                                {
1666
                                                {
1605
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1667
                                                        FC_StatusFlags &= ~FC_STATUS_VARIO_TRIM_UP;
1606
                                                        SollHoehe = HoehenWert; // update setpoint to current heigth
1668
                                                        SollHoehe = HoehenWertF; // update setpoint to current heigth
1607
                                                }
1669
                                                }
1608
                                         }
1670
                                         }
1609
                                        else
1671
                                        else
1610
                                        if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN))
1672
                                        if(FC_StatusFlags & (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN))
1611
                                        {
1673
                                        {
1612
                                                if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWert-128), (HoehenWert+128)) // max. 1m Unterschied
1674
                                                if(!WaypointTrimming) LIMIT_MIN_MAX(SollHoehe, (HoehenWertF-200), (HoehenWertF+200)) // max. 2m Unterschied
1613
                                                else                                    WaypointTrimming = 0;
1675
                                                else                                    WaypointTrimming = 0;
1614
                                                FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1676
                                                FC_StatusFlags &= ~(FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1615
                                                HeightTrimming = 0;
1677
                                                HeightTrimming = 0;
1616
                                                if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1678
                                                if(Parameter_ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500;
1617
                                                if(!StartTrigger && HoehenWert > 50)
1679
                                                if(!StartTrigger && HoehenWert > 50)
Line 1644... Line 1706...
1644
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1706
                           StickGasHover = (StickGasHover * UBat) / BattLowVoltageWarning;
1645
                           if(StickGasHover < 70) StickGasHover = 70;
1707
                           if(StickGasHover < 70) StickGasHover = 70;
1646
                           else if(StickGasHover > 150) StickGasHover = 150;
1708
                           else if(StickGasHover > 150) StickGasHover = 150;
1647
                       }
1709
                       }
1648
                                }
1710
                                }
1649
              if(BaroExpandActive) SollHoehe = HoehenWert; // update setpoint to current altitude if Expanding is active
1711
              if(BaroExpandActive) SollHoehe = HoehenWertF; // update setpoint to current altitude if Expanding is active
1650
                        } //if FCFlags & MKFCFLAG_FLY
1712
                        } //if FCFlags & MKFCFLAG_FLY
1651
                        else
1713
                        else
1652
                        {
1714
                        {
1653
                         SollHoehe = HoehenWert - 400;
1715
                         SollHoehe = HoehenWert - 400;
1654
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
1716
                         if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint;
Line 1656... Line 1718...
1656
                         HoverGas = GasMischanteil;
1718
                         HoverGas = GasMischanteil;
1657
                         VarioCharacter = '.';
1719
                         VarioCharacter = '.';
1658
                         }
1720
                         }
1659
                        HCGas = HoverGas;      // take hover gas (neutral point)
1721
                        HCGas = HoverGas;      // take hover gas (neutral point)
1660
                   }
1722
                   }
1661
         if(HoehenWert > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT))
1723
         if(HoehenWertF > SollHoehe || !(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT))
1662
                 {
1724
                 {
-
 
1725
 if(!ACC_AltitudeControl)
-
 
1726
  {
1663
                        // from this point the Heigth Control Algorithm is identical for both versions
1727
                        // from this point the Heigth Control Algorithm is identical for both versions
1664
                        if(BaroExpandActive) // baro range expanding active
1728
                        if(BaroExpandActive) // baro range expanding active
1665
                        {
1729
                        {
1666
                                HCGas = HoverGas; // hover while expanding baro adc range
1730
                                HCGas = HoverGas; // hover while expanding baro adc range
1667
                                HeightDeviation = 0;
1731
                                HeightDeviation = 0;
1668
                        } // EOF // baro range expanding active
1732
                        } // EOF // baro range expanding active
1669
                        else // valid data from air pressure sensor
1733
                        else // valid data from air pressure sensor
1670
                        {
1734
                        {
1671
                                // ------------------------- P-Part ----------------------------
1735
                                // ------------------------- P-Part ----------------------------
1672
                                tmp_long = (HoehenWert - SollHoehe); // positive when too high
1736
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
1673
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1737
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
1674
                                HeightDeviation = (int)(tmp_long); // positive when too high
1738
                                HeightDeviation = (int)(tmp_long); // positive when too high
1675
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1739
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
1676
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1740
                                LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense
1677
                                GasReduction = tmp_long;
1741
                                GasReduction = tmp_long;
Line 1695... Line 1759...
1695
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1759
                        // ------------------------ D-Part 3: GpsZ  ----------------------------------
1696
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1760
                        tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L;
1697
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1761
            LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN);
1698
                        GasReduction += tmp_int;
1762
                        GasReduction += tmp_int;
1699
            GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value
1763
            GasReduction = (long)((long)GasReduction * HoverGas) / 512; // scale to the gas value
-
 
1764
 
1700
                        // ------------------------                  ----------------------------------
1765
                        // ------------------------                  ----------------------------------
1701
                        HCGas -= GasReduction;
1766
                        HCGas -= GasReduction;
1702
                        // limit deviation from hoover point within the target region
1767
                        // limit deviation from hoover point within the target region
1703
                        if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1768
                        if(!AltitudeSetpointTrimming && HoverGas > 0) // height setpoint is not changed and hoover gas not zero
1704
                        {
1769
                        {
Line 1739... Line 1804...
1739
                        {  // old version
1804
                        {  // old version
1740
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1805
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
1741
                                GasMischanteil = FilterHCGas;
1806
                                GasMischanteil = FilterHCGas;
1742
                        }
1807
                        }
1743
                        else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode
1808
                        else GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; // only in Vario-Mode
-
 
1809
 }
-
 
1810
 else
-
 
1811
 {
-
 
1812
                        // from this point the Heigth Control Algorithm is identical for both versions
-
 
1813
                        if(BaroExpandActive) // baro range expanding active
-
 
1814
                        {
-
 
1815
                                HCGas = HoverGas; // hover while expanding baro adc range
-
 
1816
                                HeightDeviation = 0;
-
 
1817
                        } // EOF // baro range expanding active
-
 
1818
                        else // valid data from air pressure sensor
-
 
1819
                        {
-
 
1820
                                // ------------------------- P-Part ----------------------------
-
 
1821
                                tmp_long = (HoehenWertF - SollHoehe); // positive when too high
-
 
1822
                                LIMIT_MIN_MAX(tmp_long, -32767L, 32767L);       // avoid overflov when casting to int16_t
-
 
1823
                                HeightDeviation = (int)(tmp_long); // positive when too high
-
 
1824
                                tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part
-
 
1825
                                LIMIT_MIN_MAX(tmp_long, -511 * STICK_GAIN, 512 * STICK_GAIN); // more than full range makes sense
-
 
1826
                                GasReduction = tmp_long;
-
 
1827
                                // ------------------------ D-Part: ACC-Z Integral  ------------------------
-
 
1828
                                tmp_long = VerticalVelocity + AdWertAccHoch * Parameter_Hoehe_ACC_Wirkung/256;
-
 
1829
                                // ------------------------- D-Part: Vario Meter ----------------------------
-
 
1830
                                if(WaypointTrimming) {
-
 
1831
                                        Variance = AltitudeSetpointTrimming * 8;       
-
 
1832
                                } else {
-
 
1833
                                        Variance = AltitudeSetpointTrimming * EE_Parameter.Hoehe_Verstaerkung*9/32;
-
 
1834
                                }
-
 
1835
                                tmp_long -= (long)Variance;
-
 
1836
                                tmp_long = (tmp_long * (long)Parameter_Luftdruck_D) / 32; // scale to d-gain parameter
-
 
1837
                                LIMIT_MIN_MAX(tmp_long,-511 * STICK_GAIN, 512 * STICK_GAIN);
-
 
1838
                                GasReduction += tmp_long;
-
 
1839
                        } // EOF no baro range expanding
-
 
1840
DebugOut.Analog[19] = -GasReduction;
-
 
1841
                        HCGas -= GasReduction;
-
 
1842
                        LIMIT_MIN_MAX(HCGas, HoverGasMin, HoverGasMax); // limits gas around hover point
-
 
1843
                        // strech control output by inverse attitude projection 1/cos
-
 
1844
            // + 1/cos(angle)  ++++++++++++++++++++++++++
-
 
1845
                        tmp_long2 = (int32_t)HCGas;
-
 
1846
                        tmp_long2 *= 8192L;
-
 
1847
                        tmp_long2 /= CosAttitude;
-
 
1848
                        HCGas = (int16_t)tmp_long2;
-
 
1849
                        // update height control gas averaging
-
 
1850
                        FilterHCGas = (FilterHCGas * (HC_GAS_AVERAGE - 1) + HCGas) / HC_GAS_AVERAGE;
-
 
1851
                        // limit height control gas pd-control output
-
 
1852
                        LIMIT_MIN_MAX(FilterHCGas, EE_Parameter.Hoehe_MinGas * STICK_GAIN, (MAX_GAS - 20) * STICK_GAIN);
-
 
1853
                        // set GasMischanteil to HeightControlGasFilter
-
 
1854
            if(Parameter_ExtraConfig & CFG2_HEIGHT_LIMIT)
-
 
1855
                        {  // old version
-
 
1856
                                LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas
-
 
1857
                                GasMischanteil = FilterHCGas;
-
 
1858
                        }
-
 
1859
                        else GasMischanteil = FilterHCGas;// + (GasMischanteil - HoverGas) / 4; // Qopter: geändert
-
 
1860
 }
1744
                  }
1861
                  }
1745
                }// EOF height control active
1862
                }// EOF height control active
1746
                else // HC not active
1863
                else // HC not active
1747
                {
1864
                {
1748
                        //update hoover gas stick value when HC is not active
1865
                        //update hoover gas stick value when HC is not active
Line 1760... Line 1877...
1760
                }
1877
                }
1761
                // Hover gas estimation by averaging gas control output on small z-velocities
1878
                // Hover gas estimation by averaging gas control output on small z-velocities
1762
                // this is done only if height contol option is selected in global config and aircraft is flying
1879
                // this is done only if height contol option is selected in global config and aircraft is flying
1763
                if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING))
1880
                if((FC_StatusFlags & FC_STATUS_FLY))// && !(FC_SatusFlags & FC_STATUS_EMERGENCY_LANDING))
1764
                {
1881
                {
1765
                        if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
1882
//if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation
-
 
1883
if(HoverGasFilter == 0 || StartTrigger == 1)  HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(HoverGas); // Qopter: geändert
1766
                        if(StartTrigger == 1) StartTrigger = 2;
1884
                        if(StartTrigger == 1) StartTrigger = 2;
1767
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1885
                                tmp_long2 = (int32_t)GasMischanteil; // take current thrust
1768
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1886
                                tmp_long2 *= CosAttitude;            // apply attitude projection
1769
                                tmp_long2 /= 8192;
1887
                                tmp_long2 /= 8192;
1770
                                // average vertical projected thrust
1888
                                // average vertical projected thrust
Line 1777... Line 1895...
1777
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1895
                                {   // reduce the time constant of averaging by factor of 2 to get much faster a stable value
1778
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1896
                                        HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L);
1779
                                        HoverGasFilter += 4L * tmp_long2;
1897
                                        HoverGasFilter += 4L * tmp_long2;
1780
                                }
1898
                                }
1781
                          else //later
1899
                          else //later
-
 
1900
//if(abs(VerticalVelocity) < 50 && abs(HoehenWertF - SollHoehe) < 256) // Qopter: geändert, Anpassung nötig?
1782
                          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)
1783
                                {
1902
                                {
1784
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1903
                                        HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE;
1785
                                        HoverGasFilter += tmp_long2;
1904
                                        HoverGasFilter += tmp_long2;
1786
                                }
1905
                                }
Line 1809... Line 1928...
1809
        {
1928
        {
1810
                // set undefined state to indicate vario off
1929
                // set undefined state to indicate vario off
1811
                FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1930
                FC_StatusFlags |= (FC_STATUS_VARIO_TRIM_UP|FC_STATUS_VARIO_TRIM_DOWN);
1812
        } // EOF no height control
1931
        } // EOF no height control
Line 1813... Line 1932...
1813
 
1932
 
1814
   // Linits the maximum gas in case of "Out of Range emergency landing"
1933
   // Limits the maximum gas in case of "Out of Range emergency landing"
1815
   if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING)
1934
   if(NC_To_FC_Flags & NC_TO_FC_EMERGENCY_LANDING)
1816
        {
1935
        {
1817
         if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN;
1936
         if(GasMischanteil/STICK_GAIN > HooverGasEmergencyPercent && HoverGas) GasMischanteil = HooverGasEmergencyPercent * STICK_GAIN;
1818
         SollHoehe = HoehenWert; // update setpoint to current heigth
1937
         SollHoehe = HoehenWertF; // update setpoint to current heigth
1819
          beeptime = 15000;
1938
          beeptime = 15000;
1820
          BeepMuster = 0x0E00;
1939
          BeepMuster = 0x0E00;
1821
        }
1940
        }
1822
    // limit gas to parameter setting
1941
    // limit gas to parameter setting