Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/main/flight/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,17 @@ static void imuCalculateTurnRateacceleration(fpVector3_t *vEstcentrifugalAccelBF
//fixed wing only
static float lastspeed = -1.0f;
float currentspeed = 0;
#ifdef USE_PITOT
if (pitotGetValidForAirspeed())
{
// first choice is airspeed
currentspeed = getAirspeedEstimate();
*acc_ignore_slope_multipiler = 4.0f;
}
else
#endif
if (isGPSTrustworthy()) {
//first speed choice is gps
// second choice is gps
static bool lastGPSHeartbeat;
static pt1Filter_t GPS3DspeedFilter;
static float GPS3DspeedFiltered = 0.0f;
Expand All @@ -742,13 +751,6 @@ static void imuCalculateTurnRateacceleration(fpVector3_t *vEstcentrifugalAccelBF
currentspeed = GPS3DspeedFiltered;
*acc_ignore_slope_multipiler = 4.0f;
}
#ifdef USE_PITOT
else if (sensors(SENSOR_PITOT) && pitotIsHealthy()) {
// second choice is pitot
currentspeed = getAirspeedEstimate();
*acc_ignore_slope_multipiler = 2.0f;
}
#endif
else
{
//third choice is fixedWingReferenceAirspeed
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void updatePIDCoefficients(void)
float tpaFactor=1.0f;
float iTermFactor=1.0f; // Separate factor for I-term scaling
if(usedPidControllerType == PID_TYPE_PIFF){ // Fixed wing TPA calculation
if(currentControlProfile->throttle.apa_pow>0 && pitotValidForAirspeed()){
if(currentControlProfile->throttle.apa_pow>0 && pitotGetValidForAirspeed()){
tpaFactor = calculateFixedWingAirspeedTPAFactor();
iTermFactor = calculateFixedWingAirspeedITermFactor(); // Less aggressive I-term scaling
}else{
Expand Down
14 changes: 11 additions & 3 deletions src/main/sensors/pitotmeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ pitot_t pitot = {.lastMeasurementUs = 0, .lastSeenHealthyMs = 0};
static bool pitotHardwareFailed = false;
static uint16_t pitotFailureCounter = 0;
static uint16_t pitotRecoveryCounter = 0;
#define PITOT_FAILURE_THRESHOLD 20 // 0.2 seconds at 100Hz - fast detection per LOG00002 analysis
#define PITOT_RECOVERY_THRESHOLD 200 // 2 seconds of consecutive good readings to recover
static bool pitotAirspeedValidCached = false;
#define PITOT_FAILURE_THRESHOLD 10 // 0.2 seconds at 50Hz - fast detection per LOG00002 analysis
#define PITOT_RECOVERY_THRESHOLD 100 // 2 seconds of consecutive good readings to recover

// Forward declaration for GPS-based airspeed fallback
static float getVirtualAirspeedEstimate(void);
Expand Down Expand Up @@ -231,6 +232,7 @@ static void performPitotCalibrationCycle(void)
}
}


STATIC_PROTOTHREAD(pitotThread)
{
ptBegin(pitotThread);
Expand Down Expand Up @@ -280,6 +282,7 @@ STATIC_PROTOTHREAD(pitotThread)
pitotPressureTmp = sq(fakePitotGetAirspeed()) * SSL_AIR_DENSITY / 20000.0f + SSL_AIR_PRESSURE;
}
#endif
pitotAirspeedValidCached = pitotValidateAirspeed();
ptYield();

// Calculate IAS
Expand Down Expand Up @@ -449,7 +452,7 @@ bool pitotHasFailed(void)
return pitotHardwareFailed;
}

bool pitotValidForAirspeed(void)
bool pitotValidateAirspeed(void)
{
bool ret = false;
ret = pitotIsHealthy() && pitotIsCalibrationComplete();
Expand Down Expand Up @@ -508,4 +511,9 @@ bool pitotValidForAirspeed(void)

return ret;
}

bool pitotGetValidForAirspeed(void)
{
return pitotAirspeedValidCached;
}
#endif /* PITOT */
3 changes: 2 additions & 1 deletion src/main/sensors/pitotmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void pitotStartCalibration(void);
void pitotUpdate(void);
float getAirspeedEstimate(void);
bool pitotIsHealthy(void);
bool pitotValidForAirspeed(void);
bool pitotValidateAirspeed(void);
bool pitotGetValidForAirspeed(void);
bool pitotHasFailed(void);

#endif
Loading