Idle test that fails (#2781)

* make member func

* failing test
This commit is contained in:
Matthew Kennedy 2021-05-31 03:18:15 -07:00 committed by GitHub
parent d2f7e96747
commit a50f8e0077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 2 deletions

View File

@ -340,7 +340,7 @@ static void undoIdleBlipIfNeeded() {
/** /**
* @return idle valve position percentage for automatic closed loop mode * @return idle valve position percentage for automatic closed loop mode
*/ */
static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm, IIdleController::Phase phase DECLARE_ENGINE_PARAMETER_SUFFIX) { float IdleController::getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm) {
auto idlePid = getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE); auto idlePid = getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE);
if (shouldResetPid) { if (shouldResetPid) {
@ -515,7 +515,7 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm,
// let's re-apply CLT correction // let's re-apply CLT correction
iacPosition = manualIdleController(cltCorrection PASS_ENGINE_PARAMETER_SUFFIX); iacPosition = manualIdleController(cltCorrection PASS_ENGINE_PARAMETER_SUFFIX);
} else { } else {
iacPosition = automaticIdleController(tps.Value, rpm, targetRpm, phase PASS_ENGINE_PARAMETER_SUFFIX); iacPosition = getClosedLoop(phase, tps.Value, rpm, targetRpm);
} }
iacPosition = clampPercentValue(iacPosition); iacPosition = clampPercentValue(iacPosition);

View File

@ -51,6 +51,9 @@ public:
float getIdleTimingAdjustment(int rpm); float getIdleTimingAdjustment(int rpm);
float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase); float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase);
// CLOSED LOOP CORRECTION
float getClosedLoop(IIdleController::Phase phase, float tpsPos, int rpm, int targetRpm);
// Allow querying state from outside // Allow querying state from outside
bool isIdling() { bool isIdling() {
return m_lastPhase == Phase::Idling; return m_lastPhase == Phase::Idling;

View File

@ -270,3 +270,65 @@ TEST(idle_v2, openLoopRunningTaper) {
} }
EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Idling, 30, 0)); EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Idling, 30, 0));
} }
extern int timeNowUs;
TEST(idle_v2, closedLoopBasic) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
IdleController dut;
INJECT_ENGINE_REFERENCE(&dut);
// Not testing PID here, so we can set very simple PID gains
CONFIG(idleRpmPid).pFactor = 0.5; // 0.5 output per 1 RPM error = 50% per 100 rpm
CONFIG(idleRpmPid).iFactor = 0;
CONFIG(idleRpmPid).dFactor = 0;
CONFIG(idleRpmPid).offset = 0;
CONFIG(idleRpmPid).iFactor = 0;
CONFIG(idleRpmPid).periodMs = 0;
CONFIG(idleRpmPid).minValue = -50;
CONFIG(idleRpmPid).maxValue = 50;
CONFIG(idlePidRpmDeadZone) = 0;
// burn one update then advance time 5 seconds to avoid difficulty from wasResetPid
dut.getClosedLoop(ICP::Idling, 0, 900, 900);
timeNowUs += 5'000'000;
// Test above target, should return negative
// TODO: this fails, returns 55, why?
// EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
// Below target, should return positive
// TODO: this fails, returns 55, why?
// EXPECT_FLOAT_EQ(25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 850, /*tgt*/ 900));
}
TEST(idle_v2, closedLoopDeadzone) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
IdleController dut;
INJECT_ENGINE_REFERENCE(&dut);
// Not testing PID here, so we can set very simple PID gains
CONFIG(idleRpmPid).pFactor = 0.5; // 0.5 output per 1 RPM error = 50% per 100 rpm
CONFIG(idleRpmPid).iFactor = 0;
CONFIG(idleRpmPid).dFactor = 0;
CONFIG(idleRpmPid).offset = 0;
CONFIG(idleRpmPid).iFactor = 0;
CONFIG(idleRpmPid).periodMs = 0;
CONFIG(idleRpmPid).minValue = -50;
CONFIG(idleRpmPid).maxValue = 50;
CONFIG(idlePidRpmDeadZone) = 25;
// burn one then advance time 5 seconds to avoid difficulty from wasResetPid
dut.getClosedLoop(ICP::Idling, 0, 900, 900);
timeNowUs += 5'000'000;
// Test above target, should return negative
// TODO: this fails, returns 55, why?
// EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
// Inside deadzone, should return same as last time
// TODO: this fails, returns 55, why?
// EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 900, /*tgt*/ 900));
}