-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adjust TPA parameters for fixed-wing aircraft #11237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust TPA parameters for fixed-wing aircraft #11237
Conversation
- Increase fw_tpa_time_constant default from 1500 to 2000ms - Raise airspeed TPA factor upper limit from 1.5 to 2.0
0633460
into
iNavFlight:implement-pitot-sensor-validation
PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
| const float referenceAirspeed = pidProfile()->fixedWingReferenceAirspeed; // in cm/s | ||
| float tpaFactor= powf(referenceAirspeed/airspeed, currentControlProfile->throttle.apa_pow/100.0f); | ||
| tpaFactor= constrainf(tpaFactor, 0.3f, 1.5f); | ||
| tpaFactor= constrainf(tpaFactor, 0.3f, 2.0f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add a check to ensure tpaFactor is a finite number before the constrainf call to prevent potential propagation of NaN or inf values. [possible issue, importance: 7]
| tpaFactor= constrainf(tpaFactor, 0.3f, 2.0f); | |
| float factor = tpaFactor; | |
| if (!isfinite(factor)) { | |
| factor = 1.0f; | |
| } | |
| tpaFactor = constrainf(factor, 0.3f, 2.0f); |
| const float airspeed = constrainf(getAirspeedEstimate(), 100.0f, 20000.0f); // cm/s, clamped to 3.6-720 km/h | ||
| const float referenceAirspeed = pidProfile()->fixedWingReferenceAirspeed; // in cm/s | ||
| float tpaFactor= powf(referenceAirspeed/airspeed, currentControlProfile->throttle.apa_pow/100.0f); | ||
| tpaFactor= constrainf(tpaFactor, 0.3f, 1.5f); | ||
| tpaFactor= constrainf(tpaFactor, 0.3f, 2.0f); | ||
| return tpaFactor; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Add a defensive fallback when fixedWingReferenceAirspeed (or the exponent inputs) are invalid/uninitialized to avoid returning extreme/NaN values from powf(). Default to a neutral factor (e.g., 1.0f) when configuration is non-positive or non-finite. [Learned best practice, importance: 6]
New proposed code:
static float calculateFixedWingAirspeedTPAFactor(void){
const float airspeed = constrainf(getAirspeedEstimate(), 100.0f, 20000.0f); // cm/s, clamped to 3.6-720 km/h
const float referenceAirspeed = pidProfile()->fixedWingReferenceAirspeed; // in cm/s
- float tpaFactor= powf(referenceAirspeed/airspeed, currentControlProfile->throttle.apa_pow/100.0f);
- tpaFactor= constrainf(tpaFactor, 0.3f, 2.0f);
+ const float exponent = currentControlProfile->throttle.apa_pow / 100.0f;
+
+ if (!(referenceAirspeed > 0.0f) || !isfinite(referenceAirspeed) || !isfinite(exponent)) {
+ return 1.0f;
+ }
+
+ float tpaFactor = powf(referenceAirspeed / airspeed, exponent);
+ tpaFactor = constrainf(tpaFactor, 0.3f, 2.0f);
return tpaFactor;
}
User description
PR Type
Enhancement
Description
Increase fw_tpa_time_constant default from 1500ms to 2000ms
Raise airspeed TPA factor upper limit from 1.5 to 2.0
Adjusts throttle PID attenuation parameters for fixed-wing aircraft
Diagram Walkthrough
File Walkthrough
pid.c
Increase airspeed TPA factor upper limitsrc/main/flight/pid.c
calculateFixedWingAirspeedTPAFactor()functionsettings.yaml
Increase TPA time constant default valuesrc/main/fc/settings.yaml
fw_tpa_time_constantdefault value from 1500 to 2000aircraft