Skip to content

Commit

Permalink
simpler ETB jam detection #489
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mck1117 committed Sep 17, 2024
1 parent 23dda39 commit 21b6ee2
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 155 deletions.
37 changes: 8 additions & 29 deletions firmware/controllers/actuators/electronic_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,13 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam
m_pid.initPidClass(pidParameters);
m_pedalMap = pedalMap;

// Ignore 3% position error before complaining
m_errorAccumulator.init(3.0f, etbPeriodSeconds);

reset();

return true;
}

void EtbController::reset() {
m_shouldResetPid = true;
etbDutyRateOfChange = etbDutyAverage = 0;
m_dutyRocAverage.reset();
m_dutyAverage.reset();
etbTpsErrorCounter = 0;
Expand Down Expand Up @@ -482,15 +478,7 @@ expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t obs
if (m_isAutotune) {
return getClosedLoopAutotune(target, observation);
} else {
// Check that we're not over the error limit
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();
}

checkJam(target, observation);
// Normal case - use PID to compute closed loop part
return m_pid.getOutput(target, observation, etbPeriodSeconds);
}
Expand Down Expand Up @@ -615,33 +603,24 @@ void EtbController::update() {
return;
}

auto output = ClosedLoopController::update();

if (!output) {
return;
}

checkOutput(output.Value);
ClosedLoopController::update();
}

void EtbController::checkOutput(percent_t output) {
etbDutyAverage = m_dutyAverage.average(absF(output));

etbDutyRateOfChange = m_dutyRocAverage.average(absF(output - prevOutput));
prevOutput = output;
void EtbController::checkJam(percent_t setpoint, percent_t observation) {
float absError = std::abs(setpoint - observation);

float integrator = absF(m_pid.getIntegration());
auto integratorLimit = engineConfiguration->etbJamIntegratorLimit;
auto jamDetectThreshold = engineConfiguration->jamDetectThreshold;

if (integratorLimit != 0) {
if (jamDetectThreshold != 0) {
auto nowNt = getTimeNowNt();

if (integrator > integratorLimit) {
if (absError > jamDetectThreshold) {
if (m_jamDetectTimer.hasElapsedSec(engineConfiguration->etbJamTimeout)) {
// ETB is jammed!
jamDetected = true;

// TODO: do something about it!
// getLimpManager()->reportEtbProblem();
}
} else {
m_jamDetectTimer.reset(getTimeNowNt());
Expand Down
2 changes: 0 additions & 2 deletions firmware/controllers/actuators/electronic_throttle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ struct_no_prefix electronic_throttle_s
bit etbRevLimitActive
bit jamDetected

float etbDutyRateOfChange;"ETB duty rate of change";"per", 1, 0, -0,20, 2
float etbDutyAverage;"ETB average duty";"per", 1, 0, -20,50, 2
uint16_t etbTpsErrorCounter;"ETB TPS error counter";"count", 1, 0, 0,3, 0
uint16_t etbPpsErrorCounter;"ETB pedal error counter";"count", 1, 0, 0,3, 0

Expand Down
7 changes: 2 additions & 5 deletions firmware/controllers/actuators/electronic_throttle_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "sensor.h"
#include "efi_pid.h"
#include "error_accumulator.h"
#include "electronic_throttle_generated.h"
#include "exp_average.h"

Expand Down Expand Up @@ -53,9 +52,9 @@ class EtbController : public IEtbController, public electronic_throttle_s {
expected<percent_t> getClosedLoop(percent_t setpoint, percent_t observation) override;
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
const pid_state_s& getPidState() const override { return m_pid; };
Expand Down Expand Up @@ -90,8 +89,6 @@ class EtbController : public IEtbController, public electronic_throttle_s {
DcMotor *m_motor = nullptr;
Pid m_pid;
bool m_shouldResetPid = false;
// todo: rename to m_targetErrorAccumulator
ErrorAccumulator m_errorAccumulator;

/**
* @return true if OK, false if should be disabled
Expand Down
4 changes: 1 addition & 3 deletions firmware/controllers/closed_loop_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
template <typename TInput, typename TOutput>
class ClosedLoopController {
public:
expected<TOutput> update() {
void update() {
expected<TOutput> outputValue = getOutput();
setOutput(outputValue);

return outputValue;
}

private:
Expand Down
2 changes: 1 addition & 1 deletion firmware/integration/rusefi_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ float tChargeAirDecrLimit;Maximum allowed rate of decrease allowed for the estim

uint16_t autoscale fordInjectorSmallPulseBreakPoint;;"mg", 0.001, 0, 0, 65, 3

uint8_t etbJamIntegratorLimit;;"%", 1, 0, 0, 50, 0
uint8_t jamDetectThreshold;;"%", 1, 0, 0, 50, 0

! Someday there will be a 6th option for BMW S55 that uses a separate shaft just for HPFP
#define hpfp_cam_e_enum "NONE", "Intake 1", "Exhaust 1", "Intake 2", "Exhaust 2"
Expand Down
2 changes: 1 addition & 1 deletion firmware/tunerstudio/tunerstudio.template.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4225,7 +4225,7 @@ dialog = tcuControls, "Transmission Settings"
field = "PWM Frequency", etbFreq
field = "Minimum ETB position", etbMinimumPosition
field = "Maximum ETB position", etbMaximumPosition
field = "Jam detection integrator max", etbJamIntegratorLimit
field = "Jam detection error max", jamDetectThreshold
field = "Jam detection timeout period", etbJamTimeout
field = "Duty Averaging Length", etbExpAverageLength
field = "Rate of change Averaging Length", etbRocExpAverageLength
Expand Down
31 changes: 0 additions & 31 deletions firmware/util/math/error_accumulator.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions firmware/util/math/error_accumulator.h

This file was deleted.

1 change: 0 additions & 1 deletion firmware/util/util.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ UTILSRC_CPP = \
$(UTIL_DIR)/containers/listener_array.cpp \
$(UTIL_DIR)/containers/local_version_holder.cpp \
$(UTIL_DIR)/math/biquad.cpp \
$(UTIL_DIR)/math/error_accumulator.cpp \
$(UTIL_DIR)/math/efi_pid.cpp \
$(UTIL_DIR)/math/interpolation.cpp \
$(PROJECT_DIR)/util/datalogging.cpp \
Expand Down
53 changes: 0 additions & 53 deletions unit_tests/tests/util/test_error_accumulator.cpp

This file was deleted.

1 change: 0 additions & 1 deletion unit_tests/tests/util/test_util.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


CPPSRC += $(PROJECT_DIR)/../unit_tests/tests/util/test_buffered_writer.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_error_accumulator.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_exp_average.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_hash.cpp \

Expand Down

0 comments on commit 21b6ee2

Please sign in to comment.