Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 10, 2026

User description

  • Increase fw_tpa_time_constant default from 1500 to 2000ms
  • Raise airspeed TPA factor upper limit from 1.5 to 2.0

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

flowchart LR
  A["TPA Parameters"] --> B["fw_tpa_time_constant"]
  A --> C["Airspeed TPA Factor"]
  B --> D["1500ms → 2000ms"]
  C --> E["1.5 → 2.0 upper limit"]
Loading

File Walkthrough

Relevant files
Enhancement
pid.c
Increase airspeed TPA factor upper limit                                 

src/main/flight/pid.c

  • Updated calculateFixedWingAirspeedTPAFactor() function
  • Changed airspeed TPA factor upper constraint from 1.5f to 2.0f
  • Allows higher TPA factor values for improved throttle response scaling
+1/-1     
Configuration changes
settings.yaml
Increase TPA time constant default value                                 

src/main/fc/settings.yaml

  • Updated fw_tpa_time_constant default value from 1500 to 2000
  • Increases TPA smoothing and delay time constant for fixed-wing
    aircraft
  • Reflects slower non-instant speed/throttle response characteristics
+1/-1     

- Increase fw_tpa_time_constant default from 1500 to 2000ms
- Raise airspeed TPA factor upper limit from 1.5 to 2.0
@sensei-hacker sensei-hacker merged commit 0633460 into iNavFlight:implement-pitot-sensor-validation Jan 10, 2026
20 of 21 checks passed
@qodo-code-review
Copy link
Contributor

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);
Copy link
Contributor

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]

Suggested change
tpaFactor= constrainf(tpaFactor, 0.3f, 2.0f);
float factor = tpaFactor;
if (!isfinite(factor)) {
factor = 1.0f;
}
tpaFactor = constrainf(factor, 0.3f, 2.0f);

Comment on lines 446 to 451
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;
}
Copy link
Contributor

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;
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant