mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-22 15:55:40 +03:00
Added baseThrottleCorrection calculated from moving average pitch
This commit is contained in:
parent
517fcd0bf6
commit
d6d6127310
1 changed files with 19 additions and 16 deletions
|
@ -463,17 +463,20 @@ int16_t applyFixedWingMinSpeedController(timeUs_t currentTimeUs)
|
||||||
|
|
||||||
int16_t fixedWingPitchToThrottleCorrection(int16_t pitch)
|
int16_t fixedWingPitchToThrottleCorrection(int16_t pitch)
|
||||||
{
|
{
|
||||||
if (pitch > navConfig()->fw.pitch_to_throttle_thresh) {
|
// Calculate base throttle correction from pitch moving average
|
||||||
// Positive pitch above threshold
|
const int16_t movingAverageCycles = 128; //Number of main loop cycles for average calculation
|
||||||
return DECIDEGREES_TO_DEGREES(pitch - navConfig()->fw.pitch_to_throttle_thresh) * navConfig()->fw.pitch_to_throttle;
|
static int16_t averagePitch = (averagePitch * movingAverageCycles + pitch - averagePitch) / movingAverageCycles;
|
||||||
|
const int16_t baseThrottleCorrection = DECIDEGREES_TO_DEGREES(averagePitch) * navConfig()->fw.pitch_to_throttle;
|
||||||
|
|
||||||
|
// Calculate final throttle correction
|
||||||
|
if (pitch > (averagePitch + navConfig()->fw.pitch_to_throttle_thresh)) {
|
||||||
|
return baseThrottleCorrection + DECIDEGREES_TO_DEGREES(pitch - averagePitch - navConfig()->fw.pitch_to_throttle_thresh) * navConfig()->fw.pitch_to_throttle;
|
||||||
}
|
}
|
||||||
else if (pitch < -navConfig()->fw.pitch_to_throttle_thresh) {
|
else if (pitch < (averagePitch - navConfig()->fw.pitch_to_throttle_thresh)) {
|
||||||
// Negative pitch below threshold
|
return baseThrottleCorrection + DECIDEGREES_TO_DEGREES(pitch - averagePitch + navConfig()->fw.pitch_to_throttle_thresh) * navConfig()->fw.pitch_to_throttle;
|
||||||
return DECIDEGREES_TO_DEGREES(pitch + navConfig()->fw.pitch_to_throttle_thresh) * navConfig()->fw.pitch_to_throttle;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Inside pitch_to_throttle_thresh deadband. Make no throttle correction.
|
return baseThrottleCorrection;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue