simpler ETB jam detection #6925

rather than try to integrate error over time, simply fault if there's been too much error for too long. Up to +-X error is allowed for any period of time, more is allowed for Y seconds.
This commit is contained in:
Matthew Kennedy 2024-09-17 19:39:16 -04:00 committed by rusefillc
parent 454e1d9d94
commit 3ee894594d
2 changed files with 9 additions and 27 deletions

View File

@ -196,9 +196,6 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam
m_pid.initPidClass(pidParameters); m_pid.initPidClass(pidParameters);
m_pedalProvider = pedalProvider; m_pedalProvider = pedalProvider;
// Ignore 3% position error before complaining
m_errorAccumulator.init(3.0f, etbPeriodSeconds);
reset(); reset();
return true; return true;
@ -498,15 +495,7 @@ expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t obs
if (m_isAutotune) { if (m_isAutotune) {
return getClosedLoopAutotune(target, observation); return getClosedLoopAutotune(target, observation);
} else { } else {
// Check that we're not over the error limit checkJam(target, observation);
etbIntegralError = m_errorAccumulator.accumulate(target - observation);
// Allow up to 10 percent-seconds of error
if (etbIntegralError > 10.0f) {
// TODO: figure out how to handle uncalibrated ETB
//getLimpManager()->reportEtbProblem();
}
// Normal case - use PID to compute closed loop part // Normal case - use PID to compute closed loop part
return m_pid.getOutput(target, observation, etbPeriodSeconds); return m_pid.getOutput(target, observation, etbPeriodSeconds);
} }
@ -636,23 +625,21 @@ void EtbController::update() {
ClosedLoopController::update(); ClosedLoopController::update();
} }
void EtbController::checkOutput(percent_t output) { void EtbController::checkJam(percent_t setpoint, percent_t observation) {
float absError = std::abs(setpoint - observation);
prevOutput = output; auto jamDetectThreshold = engineConfiguration->jamDetectThreshold;
#if EFI_UNIT_TEST if (jamDetectThreshold != 0) {
auto integratorLimit = engineConfiguration->jamDetectThreshold;
if (integratorLimit != 0) {
float integrator = absF(m_pid.getIntegration());
auto nowNt = getTimeNowNt(); auto nowNt = getTimeNowNt();
if (integrator > integratorLimit) { if (absError > jamDetectThreshold) {
if (m_jamDetectTimer.hasElapsedSec(engineConfiguration->etbJamTimeout)) { if (m_jamDetectTimer.hasElapsedSec(engineConfiguration->etbJamTimeout)) {
// ETB is jammed! // ETB is jammed!
jamDetected = true; jamDetected = true;
// TODO: do something about it! // TODO: do something about it!
// getLimpManager()->reportEtbProblem();
} }
} else { } else {
m_jamDetectTimer.reset(nowNt); m_jamDetectTimer.reset(nowNt);
@ -661,8 +648,6 @@ void EtbController::checkOutput(percent_t output) {
jamTimer = m_jamDetectTimer.getElapsedSeconds(nowNt); jamTimer = m_jamDetectTimer.getElapsedSeconds(nowNt);
} }
#endif // EFI_UNIT_TEST
} }
void EtbController::autoCalibrateTps() { void EtbController::autoCalibrateTps() {

View File

@ -12,7 +12,6 @@
#include "sensor.h" #include "sensor.h"
#include "efi_pid.h" #include "efi_pid.h"
#include "error_accumulator.h"
#include "electronic_throttle_generated.h" #include "electronic_throttle_generated.h"
/** /**
@ -53,9 +52,9 @@ public:
expected<percent_t> getClosedLoop(percent_t setpoint, percent_t observation) override; expected<percent_t> getClosedLoop(percent_t setpoint, percent_t observation) override;
expected<percent_t> getClosedLoopAutotune(percent_t setpoint, percent_t actualThrottlePosition); expected<percent_t> getClosedLoopAutotune(percent_t setpoint, percent_t actualThrottlePosition);
void setOutput(expected<percent_t> outputValue) override; void checkJam(percent_t setpoint, percent_t observation);
void checkOutput(percent_t output); void setOutput(expected<percent_t> outputValue) override;
// Used to inspect the internal PID controller's state // Used to inspect the internal PID controller's state
const pid_state_s& getPidState() const override { return m_pid; }; const pid_state_s& getPidState() const override { return m_pid; };
@ -94,8 +93,6 @@ private:
DcMotor *m_motor = nullptr; DcMotor *m_motor = nullptr;
Pid m_pid; Pid m_pid;
bool m_shouldResetPid = false; bool m_shouldResetPid = false;
// todo: rename to m_targetErrorAccumulator
ErrorAccumulator m_errorAccumulator;
/** /**
* @return true if OK, false if should be disabled * @return true if OK, false if should be disabled