Subversion Repositories FlightCtrl

Rev

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

Rev 2366 Rev 2367
Line 181... Line 181...
181
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
181
unsigned int GasIsZeroCnt = 0; // to detect that the gas-stick is down for a while
182
signed int Variance = 0;
182
signed int Variance = 0;
183
signed int CosAttitude; // for projection of hoover gas
183
signed int CosAttitude; // for projection of hoover gas
184
unsigned char ACC_AltitudeControl = 0;
184
unsigned char ACC_AltitudeControl = 0;
Line -... Line 185...
-
 
185
 
-
 
186
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
187
#define OPA_OFFSET_STEP 5
-
 
188
#else
-
 
189
#define OPA_OFFSET_STEP 10
-
 
190
#endif
185
 
191
 
186
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
192
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187
//  Debugwerte zuordnen
193
//  Debugwerte zuordnen
188
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
194
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
189
void CopyDebugValues(void)
195
void CopyDebugValues(void)
190
{
196
{
191
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
197
    DebugOut.Analog[0] = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
192
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
198
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
193
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
199
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
194
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
200
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
195
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
201
    DebugOut.Analog[4] = (signed int) AdNeutralGier - AdWertGier;
196
    DebugOut.Analog[5] = HoehenWert/10;
202
        DebugOut.Analog[5] = HoehenWert/10;
197
    DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512);
203
    DebugOut.Analog[6] = Aktuell_az;//AdWertAccHoch;//(Mess_Integral_Hoch / 512);
198
    DebugOut.Analog[8] = KompassValue;
204
    DebugOut.Analog[8] = KompassValue;
199
    DebugOut.Analog[9] = UBat;
205
    DebugOut.Analog[9] = UBat;
200
    DebugOut.Analog[10] = SenderOkay;
206
    DebugOut.Analog[10] = SenderOkay;
Line 277... Line 283...
277
//  Parameter: 2 -> calibrate and store ACC
283
//  Parameter: 2 -> calibrate and store ACC
278
unsigned char SetNeutral(unsigned char AdjustmentMode)  // retuns: "sucess"
284
unsigned char SetNeutral(unsigned char AdjustmentMode)  // retuns: "sucess"
279
//############################################################################
285
//############################################################################
280
{
286
{
281
        unsigned char i, sucess = 1;
287
        unsigned char i, sucess = 1;
282
        unsigned int gier_neutral = 0, nick_neutral = 0, roll_neutral = 0, acc_z_neutral = 0;
288
        unsigned int gier_neutral = 0, nick_neutral = 0, roll_neutral = 0, acc_z_neutral = 0, barotest;
283
    VersionInfo.HardwareError[0] = 0;
289
    VersionInfo.HardwareError[0] = 0;
284
//    HEF4017Reset_ON;
290
//    HEF4017Reset_ON;
285
        NeutralAccX = 0;
291
        NeutralAccX = 0;
286
        NeutralAccY = 0;
292
        NeutralAccY = 0;
287
        NeutralAccZ = 0;
293
        NeutralAccZ = 0;
Line 301... Line 307...
301
 
307
 
Line 302... Line 308...
302
        CalibrierMittelwert();
308
        CalibrierMittelwert();
303
 
309
 
304
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
310
    if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
305
     {
311
     {
-
 
312
      if((MessLuftdruck > 950) || (MessLuftdruck < 750) || ExpandBaro) SucheLuftruckOffset();
-
 
313
     }
306
      if((MessLuftdruck > 950) || (MessLuftdruck < 750)) SucheLuftruckOffset();
314
   
-
 
315
        barotest = MessLuftdruck;
-
 
316
#define NEUTRAL_FILTER 32
307
     }
317
        OCR0A += OPA_OFFSET_STEP;
308
#define NEUTRAL_FILTER 32
318
        OCR0B = 255 - OCR0A;
309
    for(i=0; i<NEUTRAL_FILTER; i++)
319
    for(i=0; i<NEUTRAL_FILTER; i++)
310
         {
320
         {
311
          Delay_ms_Mess(10);
321
          Delay_ms_Mess(10);
312
          gier_neutral += AdWertGier;
322
          gier_neutral += AdWertGier;
313
          nick_neutral += AdWertNick;
323
          nick_neutral += AdWertNick;
314
          roll_neutral += AdWertRoll;
324
          roll_neutral += AdWertRoll;
-
 
325
          acc_z_neutral += Aktuell_az;
-
 
326
         }
-
 
327
        if(MessLuftdruck < 1010 && MessLuftdruck > 20) BaroStep = barotest - MessLuftdruck;
315
          acc_z_neutral += Aktuell_az;
328
        OCR0A -= OPA_OFFSET_STEP;
316
         }
329
        OCR0B = 255 - OCR0A;
317
     AdNeutralNick = (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
330
     AdNeutralNick = (nick_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
318
         AdNeutralRoll = (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
331
         AdNeutralRoll = (roll_neutral+NEUTRAL_FILTER/2) / (NEUTRAL_FILTER / 8);
Line 347... Line 360...
347
    }
360
    }
348
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
361
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
349
        MesswertNick = 0;
362
        MesswertNick = 0;
350
    MesswertRoll = 0;
363
    MesswertRoll = 0;
351
    MesswertGier = 0;
364
    MesswertGier = 0;
352
    Delay_ms_Mess(100);
365
    Delay_ms_Mess(200);
353
    Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
366
    Mittelwert_AccNick = ACC_AMPLIFY * AdWertAccNick;
354
    Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
367
    Mittelwert_AccRoll = ACC_AMPLIFY * AdWertAccRoll;
355
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
368
    IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
356
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
369
    IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
357
    Mess_IntegralNick = IntegralNick;
370
    Mess_IntegralNick = IntegralNick;
358
    Mess_IntegralRoll = IntegralRoll;
371
    Mess_IntegralRoll = IntegralRoll;
359
    Mess_Integral_Gier = 0;
372
    Mess_Integral_Gier = 0;
360
    StartLuftdruck = Luftdruck;
-
 
361
    VarioMeter = 0;
-
 
362
        SummenHoehe = 0;    Mess_Integral_Hoch = 0;
-
 
363
    KompassSollWert = KompassValue;
373
    KompassSollWert = KompassValue;
364
        KompassSignalSchlecht = 100;
374
        KompassSignalSchlecht = 100;
365
    beeptime = 50;
375
    beeptime = 50;
366
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
376
        Umschlag180Nick = ((long) EE_Parameter.WinkelUmschlagNick * 2500L) + 15000L;
367
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
377
        Umschlag180Roll = ((long) EE_Parameter.WinkelUmschlagRoll * 2500L) + 15000L;
Line 412... Line 422...
412
    carefree_old = 70;
422
    carefree_old = 70;
413
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
423
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
414
        LIBFC_HoTT_Clear();
424
        LIBFC_HoTT_Clear();
415
        ACC_AltitudeFusion(2); // initalisation
425
        ACC_AltitudeFusion(2); // initalisation
416
#endif
426
#endif
-
 
427
    StartLuftdruck = Luftdruck;
-
 
428
    VarioMeter = 0;
-
 
429
        SummenHoehe = 0;    Mess_Integral_Hoch = 0;
-
 
430
        CalcExpandBaroStep();
417
 return(sucess);
431
 return(sucess);
418
}
432
}
Line 419... Line 433...
419
 
433
 
Line 990... Line 1004...
990
                                                {
1004
                                                {
991
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1005
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
992
// Einschalten
1006
// Einschalten
993
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1007
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
994
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
1008
                                                        if(CalibrationDone) FC_StatusFlags |= FC_STATUS_START;
-
 
1009
 
995
                                                        StartLuftdruck = Luftdruck;
1010
                                                        StartLuftdruck = Luftdruck;
996
                                                        HoehenWertF = 0;
1011
                                                        HoehenWertF = 0;
997
                                                        HoehenWert = 0;
1012
                                                        HoehenWert = 0;
998
                                                        SummenHoehe = 0;
1013
                                                        SummenHoehe = 0;
999
if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) delay_einschalten = 0;
1014
                                                        if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -100 || abs(PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]) < 100) && EE_Parameter.MotorSafetySwitch == 0) delay_einschalten = 0;
1000
                                                        if(++delay_einschalten > 253)
1015
                                                        if(++delay_einschalten > 253)
1001
                                                        {
1016
                                                        {
-
 
1017
if((abs(MesswertGier) > 32 || abs(MesswertNick) > 20) || abs(MesswertRoll) > 20)  CalibrationDone = 0; // dann ist der Gyro defekt, schlecht kalibriert oder der MK dreht sich
1002
                                                                delay_einschalten = 0;
1018
                                                                delay_einschalten = 0;
1003
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
1019
                                                                if(!VersionInfo.HardwareError[0] && CalibrationDone && !NC_ErrorCode)
1004
                                                                {
1020
                                                                {
1005
                                                                        modell_fliegt = 1;
1021
                                                                        modell_fliegt = 1;
1006
                                                                        MotorenEin = 1;
1022
                                                                        MotorenEin = 1;
Line 1565... Line 1581...
1565
 if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F))  // Höhenregelung
1581
 if((Parameter_GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick) && !(VersionInfo.HardwareError[0] & 0x7F))  // Höhenregelung
1566
        {
1582
        {
1567
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1583
                #define HOVER_GAS_AVERAGE 16384L                // 16384 * 2ms = 32s averaging
1568
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
1584
                #define HC_GAS_AVERAGE 4                        // 4 * 2ms= 8ms averaging
Line 1569... Line -...
1569
 
-
 
1570
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
1571
#define OPA_OFFSET_STEP 15
-
 
1572
#else
-
 
1573
#define OPA_OFFSET_STEP 10
-
 
1574
#endif
1585
 
1575
                int HCGas, GasReduction = 0;
1586
                int HCGas, GasReduction = 0;
1576
                static int HeightTrimming = 0;  // rate for change of height setpoint
1587
                static int HeightTrimming = 0;  // rate for change of height setpoint
1577
                static int HeightDeviation = 0, FilterHCGas = 0;
1588
                static int HeightDeviation = 0, FilterHCGas = 0;
1578
                static unsigned long HoverGasFilter = 0;
1589
                static unsigned long HoverGasFilter = 0;
1579
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
-
 
1580
 
-
 
1581
 
1590
                static unsigned char delay = 100, BaroAtUpperLimit = 0, BaroAtLowerLimit = 0;
1582
        // Expand the measurement
1591
        // Expand the measurement
1583
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1592
                // measurement of air pressure close to upper limit and no overflow in correction of the new OCR0A value occurs
1584
          if(!BaroExpandActive)
1593
          if(!BaroExpandActive)
1585
                   {
1594
                   {
1586
                        if(MessLuftdruck > 920)
1595
                        if(MessLuftdruck > 920)
1587
                        {   // increase offset
1596
                        {   // increase offset
1588
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1597
             if(OCR0A < (255 - OPA_OFFSET_STEP))
1589
                           {
1598
                           {
1590
                                ExpandBaro -= 1;
1599
                                ExpandBaro -= 1;
-
 
1600
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1591
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // increase offset to shift ADC down
1601
                                OCR0B = 255 - OCR0A;
1592
                                beeptime = 300;
1602
                                beeptime = 300;
-
 
1603
                                BaroExpandActive = 350;
1593
                                BaroExpandActive = 350;
1604
                                CalcExpandBaroStep();
1594
                           }
1605
                           }
1595
                           else
1606
                           else
1596
                           {
1607
                           {
1597
                            BaroAtLowerLimit = 1;
1608
                            BaroAtLowerLimit = 1;
Line 1603... Line 1614...
1603
                        {   // decrease offset
1614
                        {   // decrease offset
1604
                          if(OCR0A > OPA_OFFSET_STEP)
1615
                          if(OCR0A > OPA_OFFSET_STEP)
1605
                           {
1616
                           {
1606
                                ExpandBaro += 1;
1617
                                ExpandBaro += 1;
1607
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
1618
                                OCR0A = DruckOffsetSetting - OPA_OFFSET_STEP * ExpandBaro; // decrease offset to shift ADC up
-
 
1619
                                OCR0B = 255 - OCR0A;
1608
                                beeptime = 300;
1620
                                beeptime = 300;
1609
                                BaroExpandActive = 350;
1621
                                BaroExpandActive = 350;
-
 
1622
                                CalcExpandBaroStep();
1610
                           }
1623
                           }
1611
                           else
1624
                           else
1612
                           {
1625
                           {
1613
                            BaroAtUpperLimit = 1;
1626
                            BaroAtUpperLimit = 1;
1614
               }
1627
               }