Skip to content

Commit

Permalink
only check throttle jam while ignition is on #489
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 18, 2024
1 parent 877ec23 commit 64108b6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions firmware/controllers/actuators/electronic_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ expected<percent_t> EtbController::getClosedLoop(percent_t target, percent_t obs
return getClosedLoopAutotune(target, observation);
} else {
checkJam(target, observation);

// Normal case - use PID to compute closed loop part
return m_pid.getOutput(target, observation, etbPeriodSeconds);
}
Expand Down Expand Up @@ -614,13 +615,12 @@ void EtbController::checkJam(percent_t setpoint, percent_t observation) {
if (jamDetectThreshold != 0) {
auto nowNt = getTimeNowNt();

if (absError > jamDetectThreshold) {
if (absError > jamDetectThreshold && engine->module<IgnitionController>()->getIgnState()) {
if (m_jamDetectTimer.hasElapsedSec(engineConfiguration->etbJamTimeout)) {
// ETB is jammed!
jamDetected = true;

// TODO: do something about it!
// getLimpManager()->reportEtbProblem();
getLimpManager()->reportEtbProblem();
}
} else {
m_jamDetectTimer.reset(nowNt);
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Engine final : public TriggerStateListener {
AlternatorController,
#endif /* EFI_ALTERNATOR_CONTROL */
MainRelayController,
IgnitionController,
Mockable<IgnitionController>,
Mockable<AcController>,
PrimeController,
DfcoController,
Expand Down
6 changes: 6 additions & 0 deletions firmware/controllers/ignition_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

class IgnitionController : public EngineModule {
public:
using interface_t = IgnitionController;

void onSlowCallback() override;

virtual bool getIgnState() const {
return m_lastState;
}

private:
Timer m_timeSinceIgnVoltage;
bool m_lastState = false;
Expand Down
6 changes: 6 additions & 0 deletions unit_tests/mocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ MockStepperHardware::~MockStepperHardware() { }

MockTsChannel::MockTsChannel() : TsChannelBase("mock") { }
MockTsChannel::~MockTsChannel() { }

MockIdleController::MockIdleController() { }
MockIdleController::~MockIdleController() { }

MockIgnitionController::MockIgnitionController() { }
MockIgnitionController::~MockIgnitionController() { }
12 changes: 12 additions & 0 deletions unit_tests/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class MockTsChannel : public TsChannelBase {
};

class MockIdleController : public IIdleController {
public:
MockIdleController();
virtual ~MockIdleController();

MOCK_METHOD(IIdleController::Phase, determinePhase, (int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction), (override));
MOCK_METHOD(int, getTargetRpm, (float clt), (override));
MOCK_METHOD(float, getCrankingOpenLoop, (float clt), (const, override));
Expand All @@ -132,3 +136,11 @@ class MockIdleController : public IIdleController {
MOCK_METHOD(bool, isIdlingOrTaper, (), (const, override));
MOCK_METHOD(float, getIdleTimingAdjustment, (int rpm), (override));
};

class MockIgnitionController : public IgnitionController {
public:
MockIgnitionController();
virtual ~MockIgnitionController();

MOCK_METHOD(bool, getIgnState, (), (const, override));
};
7 changes: 7 additions & 0 deletions unit_tests/tests/actuators/test_etb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ TEST(etb, closedLoopPid) {
TEST(etb, jamDetection) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);

MockIgnitionController ignController;

EXPECT_CALL(ignController, getIgnState).WillRepeatedly(Return(true));

// This only works when the ignition is on!
engine->module<IgnitionController>().set(&ignController);

// Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Expand Down

0 comments on commit 64108b6

Please sign in to comment.