Subversion Repositories FlightCtrl

Rev

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

Rev 1454 Rev 1465
Line 160... Line 160...
160
signed int tmp_motorwert[MAX_MOTORS];
160
signed int tmp_motorwert[MAX_MOTORS];
161
unsigned char LoadHandler = 0;
161
unsigned char LoadHandler = 0;
162
#define LIMIT_MIN(value, min) {if(value < min) value = min;}
162
#define LIMIT_MIN(value, min) {if(value < min) value = min;}
163
#define LIMIT_MAX(value, max) {if(value > max) value = max;}
163
#define LIMIT_MAX(value, max) {if(value > max) value = max;}
164
#define LIMIT_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;}
164
#define LIMIT_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;}
165
uint8_t servoValues[6] = { 127, 127, 127, 127, 127 , 127 };
-
 
166
 
-
 
167
uint8_t MakeByte(int16_t i) {
-
 
168
        if (i < 0) return 0;
-
 
169
        if (i > 255) return 255;
-
 
170
        return i;
-
 
171
}
-
 
Line 172... Line 165...
172
 
165
 
173
int MotorSmoothing(int neu, int alt)
166
int MotorSmoothing(int neu, int alt)
174
{
167
{
175
 int motor;
168
 int motor;
Line 476... Line 469...
476
void SendMotorData(void)
469
void SendMotorData(void)
477
//############################################################################
470
//############################################################################
478
{
471
{
479
 unsigned char i;
472
 unsigned char i;
480
    if(!MotorenEin)
473
    if(!MotorenEin)
-
 
474
        {
481
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
475
         MikroKopterFlags &= ~(FLAG_MOTOR_RUN | FLAG_FLY);
-
 
476
                 for(i=0;i<MAX_MOTORS;i++)
-
 
477
                  {
-
 
478
                   if(!PC_MotortestActive)  MotorTest[i] = 0;
-
 
479
                   Motor[i] = MotorTest[i];
482
        else
480
                  }
-
 
481
          if(PC_MotortestActive) PC_MotortestActive--;
-
 
482
        }
483
                MikroKopterFlags |= FLAG_MOTOR_RUN;
483
        else MikroKopterFlags |= FLAG_MOTOR_RUN;
Line -... Line 484...
-
 
484
 
-
 
485
/*    DebugOut.Analog[12] = Motor[0];
-
 
486
    DebugOut.Analog[13] = Motor[1];
-
 
487
    DebugOut.Analog[14] = Motor[3];
Line 484... Line 488...
484
 
488
    DebugOut.Analog[15] = Motor[2];*/
485
 
489
 
486
    //Start I2C Interrupt Mode
490
    //Start I2C Interrupt Mode
487
    twi_state = 0;
491
    twi_state = 0;
Line 532... Line 536...
532
 Ki = 10300 / (Parameter_I_Faktor + 1);
536
 Ki = 10300 / (Parameter_I_Faktor + 1);
533
 MAX_GAS = EE_Parameter.Gas_Max;
537
 MAX_GAS = EE_Parameter.Gas_Max;
534
 MIN_GAS = EE_Parameter.Gas_Min;
538
 MIN_GAS = EE_Parameter.Gas_Min;
535
}
539
}
Line -... Line 540...
-
 
540
 
536
 
541
 
537
//############################################################################
542
//############################################################################
538
//
543
//
539
void MotorRegler(void)
544
void MotorRegler(void)
540
//############################################################################
545
//############################################################################
Line 590... Line 595...
590
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
595
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
591
// Emfang gut
596
// Emfang gut
592
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
597
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
593
        if(SenderOkay > 140)
598
        if(SenderOkay > 140)
594
            {
599
            {
595
 
-
 
596
                        MikroKopterFlags &= ~FLAG_NOTLANDUNG;
600
                        MikroKopterFlags &= ~FLAG_NOTLANDUNG;
597
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
601
            RcLostTimer = EE_Parameter.NotGasZeit * 50;
598
            if(GasMischanteil > 40 && MotorenEin)
602
            if(GasMischanteil > 40 && MotorenEin)
599
                {
603
                {
600
                if(modell_fliegt < 0xffff) modell_fliegt++;
604
                if(modell_fliegt < 0xffff) modell_fliegt++;
Line 1162... Line 1166...
1162
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1166
    DebugOut.Analog[1] = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
1163
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1167
    DebugOut.Analog[2] = Mittelwert_AccNick / 4;
1164
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1168
    DebugOut.Analog[3] = Mittelwert_AccRoll / 4;
1165
    DebugOut.Analog[4] = MesswertGier;
1169
    DebugOut.Analog[4] = MesswertGier;
1166
    DebugOut.Analog[5] = HoehenWert/5;
1170
    DebugOut.Analog[5] = HoehenWert/5;
1167
    //DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1171
    DebugOut.Analog[6] = Aktuell_az;//(Mess_Integral_Hoch / 512);//Aktuell_az;
1168
    DebugOut.Analog[8] = KompassValue;
1172
    DebugOut.Analog[8] = KompassValue;
1169
    DebugOut.Analog[9] = UBat;
1173
    DebugOut.Analog[9] = UBat;
1170
    DebugOut.Analog[10] = SenderOkay;
1174
    DebugOut.Analog[10] = SenderOkay;
1171
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1175
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
1172
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
1176
    //DebugOut.Analog[16] = Mittelwert_AccHoch;
Line 1523... Line 1527...
1523
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1527
  if(modell_fliegt > 1 && modell_fliegt < 50 && GasMischanteil > 0)
1524
   {
1528
   {
1525
    modell_fliegt = 1;
1529
    modell_fliegt = 1;
1526
        GasMischanteil = MIN_GAS;
1530
        GasMischanteil = MIN_GAS;
1527
   }
1531
   }
1528
/*// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1529
// + Mischer und PI-Regler
1533
// + Mischer und PI-Regler
1530
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1534
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1531
  DebugOut.Analog[7] = GasMischanteil;
1535
  DebugOut.Analog[7] = GasMischanteil;
1532
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1536
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1533
// Gier-Anteil
1537
// Gier-Anteil
Line 1571... Line 1575...
1571
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1575
    if(SummeRoll >  (STICK_GAIN * 16000L)) SummeRoll =  (STICK_GAIN * 16000L);
1572
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1576
    if(SummeRoll < -(16000L * STICK_GAIN)) SummeRoll = -(16000L * STICK_GAIN);
1573
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1577
    pd_ergebnis_roll = DiffRoll + SummeRoll / Ki;       // PI-Regler für Roll
1574
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1578
    tmp_int = (long)((long)Parameter_DynamicStability * (long)(GasMischanteil + abs(GierMischanteil)/2)) / 64;
1575
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1579
    if(pd_ergebnis_roll >  tmp_int) pd_ergebnis_roll =  tmp_int;
1576
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;*/
1580
    if(pd_ergebnis_roll < -tmp_int) pd_ergebnis_roll = -tmp_int;
Line 1577... Line 1581...
1577
 
1581
 
1578
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1582
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1579
// Servo Mixer
1583
// Universal Mixer
1580
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1584
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1581
        {
-
 
1582
                int16_t nick, roll, tmp, pitch, throttle;
-
 
Line 1583... Line -...
1583
                int16_t servo[6];
-
 
1584
 
-
 
1585
        // throttle
-
 
1586
        throttle = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + Mixer.Motor[2][0];
-
 
1587
        if (throttle < 0) throttle = 0;
-
 
1588
 
-
 
1589
        tmp = throttle / Mixer.Motor[3][0];
-
 
1590
        if (tmp > Mixer.Motor[3][1] * 2) tmp = Mixer.Motor[3][1] * 2;
-
 
1591
                DebugOut.Analog[7] = tmp;
-
 
1592
                if (MotorenEin == 0 || MikroKopterFlags & FLAG_NOTLANDUNG) {
-
 
1593
                        tmp = 0;
-
 
1594
            }
-
 
1595
        servo[4] = tmp;
-
 
1596
 
-
 
1597
                // pitch
-
 
1598
        pitch = throttle / Mixer.Motor[4][0] + Mixer.Motor[4][2];
-
 
1599
        if (pitch > Mixer.Motor[4][1]) pitch = Mixer.Motor[4][1];
-
 
1600
 
-
 
1601
                servo[0] = -pitch;
-
 
1602
                servo[1] = pitch;
-
 
1603
                servo[2] = pitch;
-
 
1604
 
-
 
1605
 
-
 
1606
        nick = IntegralNick / (EE_Parameter.GyroAccFaktor * 4);
-
 
1607
        roll = IntegralRoll / (EE_Parameter.GyroAccFaktor * 4);
-
 
1608
 
-
 
1609
                // nick
-
 
1610
        nick /= Mixer.Motor[0][1];
-
 
1611
        nick -= PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] / Mixer.Motor[5][0];
-
 
1612
        servo[0] += 127 + Mixer.Motor[0][0] - nick;
-
 
1613
        servo[1] += 127 + Mixer.Motor[0][0] + nick;
-
 
1614
        servo[2] += 127 + Mixer.Motor[0][0] - nick;
-
 
1615
 
-
 
1616
                // roll
-
 
1617
        roll /= Mixer.Motor[0][2];
-
 
1618
        roll -= PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] / Mixer.Motor[6][0];
-
 
1619
        servo[0] += roll;
-
 
1620
        servo[1] += roll;
-
 
1621
 
-
 
1622
        // gier
-
 
1623
        tmp = MesswertGier / Mixer.Motor[0][3];
-
 
1624
        servo[3] = 127 + Mixer.Motor[1][1] + tmp + (PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] / Mixer.Motor[7][0]);
-
 
1625
 
-
 
1626
        // not used
-
 
1627
        servo[5] = 127;
-
 
1628
 
-
 
1629
        for(tmp = 0; tmp < 6; tmp++) {
-
 
1630
                servoValues[tmp] = MakeByte(servo[tmp]);
-
 
1631
        }
-
 
1632
 
-
 
1633
                DebugOut.Analog[12] = servo[0];
-
 
1634
                DebugOut.Analog[13] = servo[1];
-
 
1635
                DebugOut.Analog[14] = servo[2];
1585
#if 1
Line -... Line 1586...
-
 
1586
 
-
 
1587
        #include "helimixer.inc";
-
 
1588
 
-
 
1589
#else
-
 
1590
 
-
 
1591
 for(i=0; i<MAX_MOTORS; i++)
-
 
1592
 {
-
 
1593
  signed int tmp_int;
-
 
1594
  if(Mixer.Motor[i][0] > 0)
-
 
1595
   {
-
 
1596
    tmp_int =  ((long)GasMischanteil * Mixer.Motor[i][0]) / 64L;
-
 
1597
    tmp_int += ((long)pd_ergebnis_nick * Mixer.Motor[i][1]) / 64L;
-
 
1598
    tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
-
 
1599
    tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
-
 
1600
    tmp_motorwert[i] = MotorSmoothing(tmp_int,tmp_motorwert[i]);  // Filter
-
 
1601
        tmp_int = tmp_motorwert[i] / STICK_GAIN;
-
 
1602
        CHECK_MIN_MAX(tmp_int,MIN_GAS,MAX_GAS);
1636
                DebugOut.Analog[15] = servo[3];
1603
    Motor[i] = tmp_int;
-
 
1604
   }
-
 
1605
   else Motor[i] = 0;
-
 
1606
 }
-
 
1607
/*
-
 
1608
if(Poti1 > 20)  Motor1 = 0;
-
 
1609
if(Poti1 > 90)  Motor6 = 0;
-
 
1610
if(Poti1 > 140) Motor2 = 0;
Line 1637... Line 1611...
1637
                DebugOut.Analog[6] = pitch;
1611
//if(Poti1 > 200) Motor7 = 0;