Rev 1697 | Rev 1701 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1697 | Rev 1698 | ||
---|---|---|---|
Line 93... | Line 93... | ||
93 | int DiffNick,DiffRoll; |
93 | int DiffNick,DiffRoll; |
94 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
94 | //int Poti1 = 0, Poti2 = 0, Poti3 = 0, Poti4 = 0, Poti5 = 0, Poti6 = 0, Poti7 = 0, Poti8 = 0; |
95 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
95 | unsigned char Poti[9] = {0,0,0,0,0,0,0,0}; |
96 | volatile unsigned char SenderOkay = 0; |
96 | volatile unsigned char SenderOkay = 0; |
97 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
97 | int StickNick = 0,StickRoll = 0,StickGier = 0,StickGas = 0; |
98 | char MotorenEin = 0; |
98 | char MotorenEin = 0,StartTrigger = 0; |
99 | long HoehenWert = 0; |
99 | long HoehenWert = 0; |
100 | long SollHoehe = 0; |
100 | long SollHoehe = 0; |
101 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
101 | int LageKorrekturRoll = 0,LageKorrekturNick = 0, HoverGas = 0; |
102 | //float Ki = FAKTOR_I; |
102 | //float Ki = FAKTOR_I; |
103 | int Ki = 10300 / 33; |
103 | int Ki = 10300 / 33; |
Line 1283... | Line 1283... | ||
1283 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1283 | if(UBat > BattLowVoltageWarning) GasMischanteil = ((unsigned int)GasMischanteil * BattLowVoltageWarning) / UBat; // Gas auf das aktuelle Spannungvieveau beziehen |
1284 | GasMischanteil *= STICK_GAIN; |
1284 | GasMischanteil *= STICK_GAIN; |
1285 | // if height control is activated |
1285 | // if height control is activated |
1286 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1286 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && !(Looping_Roll || Looping_Nick)) // Höhenregelung |
1287 | { |
1287 | { |
1288 | #define HOVER_GAS_AVERAGE 16384L // 4096 * 2ms = 8.2s averaging |
1288 | #define HOVER_GAS_AVERAGE 16384L // 16384 * 2ms = 32s averaging |
1289 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
1289 | #define HC_GAS_AVERAGE 4 // 4 * 2ms= 8ms averaging |
Line 1290... | Line 1290... | ||
1290 | 1290 | ||
1291 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1291 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
1292 | #define OPA_OFFSET_STEP 15 |
1292 | #define OPA_OFFSET_STEP 15 |
Line 1436... | Line 1436... | ||
1436 | { |
1436 | { |
1437 | HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN); |
1437 | HeightTrimmingFlag &= ~(HEIGHT_TRIM_UP | HEIGHT_TRIM_DOWN); |
1438 | HeightTrimming = 0; |
1438 | HeightTrimming = 0; |
1439 | SollHoehe = HoehenWert; // update setpoint to current height |
1439 | SollHoehe = HoehenWert; // update setpoint to current height |
1440 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
1440 | if(EE_Parameter.ExtraConfig & CFG2_VARIO_BEEP) beeptime = 500; |
- | 1441 | if(!StartTrigger && HoehenWert > 50) |
|
- | 1442 | { |
|
- | 1443 | StartTrigger = 1; |
|
- | 1444 | } |
|
1441 | } |
1445 | } |
1442 | VarioCharacter = '='; |
1446 | VarioCharacter = '='; |
1443 | } |
1447 | } |
1444 | // Trim height set point |
1448 | // Trim height set point |
1445 | if(abs(HeightTrimming) > 512) |
1449 | if(abs(HeightTrimming) > 512) |
Line 1462... | Line 1466... | ||
1462 | else |
1466 | else |
1463 | { |
1467 | { |
1464 | SollHoehe = HoehenWert - 400; |
1468 | SollHoehe = HoehenWert - 400; |
1465 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1469 | if(EE_Parameter.Hoehe_StickNeutralPoint) StickGasHover = EE_Parameter.Hoehe_StickNeutralPoint; |
1466 | else StickGasHover = 120; |
1470 | else StickGasHover = 120; |
- | 1471 | HoverGas = GasMischanteil; |
|
1467 | } |
1472 | } |
1468 | HCGas = HoverGas; // take hover gas (neutral point) |
1473 | HCGas = HoverGas; // take hover gas (neutral point) |
1469 | } |
1474 | } |
1470 | if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1475 | if(HoehenWert > SollHoehe || !(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT)) |
1471 | { |
1476 | { |
Line 1480... | Line 1485... | ||
1480 | // ------------------------- P-Part ---------------------------- |
1485 | // ------------------------- P-Part ---------------------------- |
1481 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1486 | tmp_long = (HoehenWert - SollHoehe); // positive when too high |
1482 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1487 | LIMIT_MIN_MAX(tmp_long, -32767L, 32767L); // avoid overflov when casting to int16_t |
1483 | HeightDeviation = (int)(tmp_long); // positive when too high |
1488 | HeightDeviation = (int)(tmp_long); // positive when too high |
1484 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1489 | tmp_long = (tmp_long * (long)Parameter_Hoehe_P) / 32L; // p-part |
1485 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 255 * STICK_GAIN); // more than the full range makes no sense |
1490 | LIMIT_MIN_MAX(tmp_long, -127 * STICK_GAIN, 256 * STICK_GAIN); // more than the full range makes no sense |
1486 | // HCGas -= tmp_long; |
- | |
1487 | DebugOut.Analog[25] = tmp_long; |
1491 | DebugOut.Analog[25] = tmp_long; |
1488 | GasReduction = tmp_long; |
1492 | GasReduction = tmp_long; |
1489 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1493 | // ------------------------- D-Part 1: Vario Meter ---------------------------- |
1490 | tmp_int = VarioMeter / 8; |
1494 | tmp_int = VarioMeter / 8; |
1491 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1495 | LIMIT_MIN_MAX(tmp_int, -127, 128); |
1492 | DebugOut.Analog[18] = tmp_int; |
1496 | DebugOut.Analog[18] = tmp_int; |
1493 | // tmp_int2 = tmp_int/4; |
1497 | // tmp_int2 = tmp_int/4; |
1494 | // LIMIT_MAX(tmp_int2, 64); |
1498 | // LIMIT_MAX(tmp_int2, 64); |
1495 | // if(tmp_int > 0) tmp_int = tmp_int + (tmp_int2 * tmp_int2); |
1499 | // if(tmp_int > 0) tmp_int = tmp_int + (tmp_int2 * tmp_int2); |
1496 | // else tmp_int = tmp_int - (tmp_int2 * tmp_int2); |
1500 | // else tmp_int = tmp_int - (tmp_int2 * tmp_int2); |
Line -... | Line 1501... | ||
- | 1501 | ||
- | 1502 | if(!HeightTrimmingFlag) |
|
1497 | 1503 | { |
|
1498 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1504 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 4L; // scale to d-gain parameter |
1499 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
1505 | LIMIT_MIN_MAX(tmp_int,-64 * STICK_GAIN, 64 * STICK_GAIN); |
- | 1506 | } |
|
1500 | // HCGas -= tmp_int; |
1507 | |
- | 1508 | else { |
|
1501 | DebugOut.Analog[19] = tmp_int; |
1509 | tmp_int = (tmp_int * (long)Parameter_Luftdruck_D) / 16L; // weniger D zum Höhe ändern |
- | 1510 | LIMIT_MIN_MAX(tmp_int,-16 * STICK_GAIN, 16 * STICK_GAIN); |
|
Line -... | Line 1511... | ||
- | 1511 | } |
|
- | 1512 | ||
1502 | GasReduction += tmp_int; |
1513 | DebugOut.Analog[19] = tmp_int; |
1503 | 1514 | GasReduction += tmp_int; |
|
- | 1515 | } // EOF no baro range expanding |
|
- | 1516 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
|
1504 | } // EOF no baro range expanding |
1517 | if(Parameter_Hoehe_ACC_Wirkung) |
1505 | // ------------------------ D-Part 2: ACC-Z Integral ------------------------ |
1518 | { |
1506 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
- | |
1507 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1519 | tmp_long = ((Mess_Integral_Hoch / 128L) * (int32_t) Parameter_Hoehe_ACC_Wirkung) / (128L / STICK_GAIN); |
- | 1520 | LIMIT_MIN_MAX(tmp_long, -32 * STICK_GAIN, 64 * STICK_GAIN); |
|
1508 | // HCGas -= tmp_long; |
1521 | GasReduction += tmp_long; |
1509 | GasReduction += tmp_long; |
1522 | } |
1510 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1523 | // ------------------------ D-Part 3: GpsZ ---------------------------------- |
1511 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
- | |
1512 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1524 | tmp_int = (Parameter_Hoehe_GPS_Z * (int)FromNaviCtrl_Value.GpsZ)/128L; |
Line 1513... | Line 1525... | ||
1513 | // HCGas -= tmp_int; |
1525 | LIMIT_MIN_MAX(tmp_int, -32 * STICK_GAIN, 64 * STICK_GAIN); |
1514 | GasReduction += tmp_int; |
1526 | GasReduction += tmp_int; |
1515 | 1527 | ||
1516 | //DebugOut.Analog[16] = GasReduction; |
1528 | //DebugOut.Analog[16] = GasReduction; |
Line 1557... | Line 1569... | ||
1557 | // set GasMischanteil to HeightControlGasFilter |
1569 | // set GasMischanteil to HeightControlGasFilter |
1558 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) |
1570 | if(EE_Parameter.ExtraConfig & CFG2_HEIGHT_LIMIT) |
1559 | { // old version |
1571 | { // old version |
1560 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1572 | LIMIT_MAX(FilterHCGas, GasMischanteil); // nicht mehr als Gas |
1561 | } |
1573 | } |
1562 | GasMischanteil = FilterHCGas; |
1574 | GasMischanteil = FilterHCGas + (GasMischanteil - HoverGas) / 4; |
1563 | } |
1575 | } |
1564 | }// EOF height control active |
1576 | }// EOF height control active |
1565 | else // HC not active |
1577 | else // HC not active |
1566 | { |
1578 | { |
1567 | //update hoover gas stick value when HC is not active |
1579 | //update hoover gas stick value when HC is not active |
Line 1575... | Line 1587... | ||
1575 | FilterHCGas = GasMischanteil; |
1587 | FilterHCGas = GasMischanteil; |
1576 | } |
1588 | } |
Line 1577... | Line 1589... | ||
1577 | 1589 | ||
1578 | // Hover gas estimation by averaging gas control output on small z-velocities |
1590 | // Hover gas estimation by averaging gas control output on small z-velocities |
1579 | // this is done only if height contol option is selected in global config and aircraft is flying |
1591 | // this is done only if height contol option is selected in global config and aircraft is flying |
1580 | if((FCFlags & FCFLAG_FLY) && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1592 | if((FCFlags & FCFLAG_FLY))// && !(FCFlags & FCFLAG_NOTLANDUNG)) |
1581 | { |
1593 | { |
1582 | if(HoverGasFilter == 0) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1594 | if(HoverGasFilter == 0 || StartTrigger == 1) HoverGasFilter = HOVER_GAS_AVERAGE * (unsigned long)(GasMischanteil); // init estimation |
1583 | if(abs(VarioMeter) < 100) // only on small vertical speed |
- | |
1584 | { |
1595 | if(StartTrigger == 1) StartTrigger = 2; |
1585 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1596 | tmp_long2 = (int32_t)GasMischanteil; // take current thrust |
1586 | tmp_long2 *= CosAttitude; // apply attitude projection |
1597 | tmp_long2 *= CosAttitude; // apply attitude projection |
1587 | tmp_long2 /= 8192; |
- | |
1588 | 1598 | tmp_long2 /= 8192; |
|
1589 | // average vertical projected thrust |
- | |
1590 | if(modell_fliegt < 2000) // the first 4 seconds |
- | |
1591 | { // reduce the time constant of averaging by factor of 8 to get much faster a stable value |
- | |
1592 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/8L); |
- | |
1593 | HoverGasFilter += 8L * tmp_long2; |
- | |
1594 | } |
1599 | // average vertical projected thrust |
1595 | else if(modell_fliegt < 4000) // the first 8 seconds |
1600 | if(modell_fliegt < 4000) // the first 8 seconds |
1596 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1601 | { // reduce the time constant of averaging by factor of 4 to get much faster a stable value |
1597 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1602 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/16L); |
1598 | HoverGasFilter += 4L * tmp_long2; |
1603 | HoverGasFilter += 16L * tmp_long2; |
1599 | } |
1604 | } |
1600 | else if(modell_fliegt < 8000) // the first 16 seconds |
1605 | if(modell_fliegt < 8000) // the first 16 seconds |
1601 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1606 | { // reduce the time constant of averaging by factor of 2 to get much faster a stable value |
1602 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/2L); |
1607 | HoverGasFilter -= HoverGasFilter/(HOVER_GAS_AVERAGE/4L); |
1603 | HoverGasFilter += 2L * tmp_long2; |
1608 | HoverGasFilter += 4L * tmp_long2; |
1604 | } |
1609 | } |
- | 1610 | else //later |
|
1605 | else //later |
1611 | if(abs(VarioMeter) < 100) // only on small vertical speed |
1606 | { |
1612 | { |
1607 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1613 | HoverGasFilter -= HoverGasFilter/HOVER_GAS_AVERAGE; |
1608 | HoverGasFilter += tmp_long2; |
1614 | HoverGasFilter += tmp_long2; |
1609 | } |
1615 | } |
Line 1618... | Line 1624... | ||
1618 | else |
1624 | else |
1619 | { // no limit |
1625 | { // no limit |
1620 | HoverGasMin = 0; |
1626 | HoverGasMin = 0; |
1621 | HoverGasMax = 1023; |
1627 | HoverGasMax = 1023; |
1622 | } |
1628 | } |
1623 | } |
1629 | } |
- | 1630 | else |
|
- | 1631 | { |
|
- | 1632 | StartTrigger = 0; |
|
- | 1633 | HoverGasFilter = 0; |
|
- | 1634 | HoverGas = 0; |
|
1624 | } |
1635 | } |
1625 | }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL |
1636 | }// EOF ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL |
1626 | - | ||
- | 1637 | DebugOut.Analog[16] = StartTrigger; |
|
1627 | // limit gas to parameter setting |
1638 | // limit gas to parameter setting |
1628 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1639 | LIMIT_MIN(GasMischanteil, (MIN_GAS + 10) * STICK_GAIN); |
1629 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
1640 | if(GasMischanteil > (MAX_GAS - 20) * STICK_GAIN) GasMischanteil = (MAX_GAS - 20) * STICK_GAIN; |
Line 1630... | Line 1641... | ||
1630 | 1641 |