2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file test_idle_controller.cpp
|
|
|
|
*
|
|
|
|
* @date Oct 17, 2013
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2019-03-22 19:55:51 -07:00
|
|
|
#include "advance_map.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "pid.h"
|
2019-09-12 04:31:13 -07:00
|
|
|
#include "fsio_impl.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
#include "idle_thread.h"
|
2019-09-22 14:58:27 -07:00
|
|
|
#include "electronic_throttle.h"
|
2019-09-19 19:56:54 -07:00
|
|
|
|
2020-12-26 16:34:42 -08:00
|
|
|
using ::testing::StrictMock;
|
|
|
|
using ::testing::_;
|
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
using ICP = IIdleController::Phase;
|
|
|
|
|
|
|
|
TEST(idle_v2, timingPid) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-01-07 05:06:36 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
engineConfiguration->useIdleTimingPidControl = true;
|
2019-03-22 19:55:51 -07:00
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
pid_s pidCfg{};
|
|
|
|
pidCfg.pFactor = 0.1;
|
|
|
|
pidCfg.minValue = -10;
|
|
|
|
pidCfg.maxValue = 10;
|
|
|
|
dut.init(&pidCfg);
|
|
|
|
|
|
|
|
// Check that out of idle mode it doesn't do anything
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Cranking));
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Coasting));
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Running));
|
|
|
|
|
|
|
|
// Check that it works in idle mode
|
|
|
|
EXPECT_FLOAT_EQ(-5, dut.getIdleTimingAdjustment(1050, 1000, ICP::Idling));
|
|
|
|
|
|
|
|
// ...but not when disabled
|
2020-12-31 09:22:54 -08:00
|
|
|
engineConfiguration->useIdleTimingPidControl = false;
|
2021-01-07 05:06:36 -08:00
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1050, 1000, ICP::Idling));
|
|
|
|
|
2019-12-11 14:48:55 -08:00
|
|
|
engineConfiguration->useIdleTimingPidControl = true;
|
2019-03-22 19:55:51 -07:00
|
|
|
|
2021-01-07 05:06:36 -08:00
|
|
|
// Now check that the deadzone works
|
|
|
|
engineConfiguration->idleTimingPidDeadZone = 50;
|
|
|
|
EXPECT_FLOAT_EQ(5.1, dut.getIdleTimingAdjustment(949, 1000, ICP::Idling));
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(951, 1000, ICP::Idling));
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1000, 1000, ICP::Idling));
|
|
|
|
EXPECT_EQ(0, dut.getIdleTimingAdjustment(1049, 1000, ICP::Idling));
|
|
|
|
EXPECT_FLOAT_EQ(-5.1, dut.getIdleTimingAdjustment(1051, 1000, ICP::Idling));
|
2019-03-22 19:55:51 -07:00
|
|
|
}
|
2020-12-17 14:46:51 -08:00
|
|
|
|
|
|
|
TEST(idle_v2, testTargetRpm) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-17 14:46:51 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < efi::size(engineConfiguration->cltIdleRpmBins); i++) {
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->cltIdleRpmBins[i] = i * 10;
|
|
|
|
engineConfiguration->cltIdleRpm[i] = i * 100;
|
2020-12-17 14:46:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_FLOAT_EQ(100, dut.getTargetRpm(10));
|
|
|
|
EXPECT_FLOAT_EQ(500, dut.getTargetRpm(50));
|
|
|
|
}
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
TEST(idle_v2, testDeterminePhase) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 05:32:01 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
// TPS threshold 5% for easy test
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idlePidDeactivationTpsThreshold = 5;
|
2020-12-26 05:32:01 -08:00
|
|
|
// RPM window is 100 RPM above target
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idlePidRpmUpperLimit = 100;
|
2021-07-04 06:35:12 -07:00
|
|
|
// Max VSS for idle is 10kph
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->maxIdleVss = 10;
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// First test stopped engine
|
|
|
|
engine->rpmCalculator.setRpmValue(0);
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Cranking, dut.determinePhase(0, 1000, unexpected, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// Now engine is running!
|
|
|
|
// Controller doesn't need this other than for isCranking()
|
|
|
|
engine->rpmCalculator.setRpmValue(1000);
|
|
|
|
|
|
|
|
// Test invalid TPS, but inside the idle window
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, unexpected, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// Valid TPS should now be inside the zone
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Idling, dut.determinePhase(1000, 1000, 0, 0, 10));
|
2021-07-04 06:35:12 -07:00
|
|
|
|
|
|
|
// Inside the zone, but vehicle speed too fast
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 0, 25, 10));
|
|
|
|
|
|
|
|
// Check that shortly after cranking, the cranking taper inhibits closed loop idle
|
2021-10-06 09:05:20 -07:00
|
|
|
EXPECT_EQ(ICP::CrankToIdleTaper, dut.determinePhase(1000, 1000, 0, 0, 0.5f));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// Above TPS threshold should be outside the zone
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1000, 1000, 10, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// Above target, below (target + upperLimit) should be in idle zone
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Idling, dut.determinePhase(1099, 1000, 0, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// above upper limit and on throttle should be out of idle zone
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Running, dut.determinePhase(1101, 1000, 10, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
|
|
|
|
// Below TPS but above RPM should be outside the zone
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_EQ(ICP::Coasting, dut.determinePhase(1101, 1000, 0, 0, 10));
|
|
|
|
EXPECT_EQ(ICP::Coasting, dut.determinePhase(5000, 1000, 0, 0, 10));
|
2020-12-26 05:32:01 -08:00
|
|
|
}
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
TEST(idle_v2, crankingOpenLoop) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 16:34:42 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
engineConfiguration->crankingIACposition = 50;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < efi::size(config->cltCrankingCorrBins); i++) {
|
|
|
|
config->cltCrankingCorrBins[i] = i * 10;
|
|
|
|
config->cltCrankingCorr[i] = i * 0.1f;
|
2021-05-31 04:37:02 -07:00
|
|
|
|
|
|
|
// different values in running so we can tell which one is used
|
|
|
|
config->cltIdleCorrBins[i] = i * 10;
|
|
|
|
config->cltIdleCorr[i] = i * 0.2f;
|
2020-12-26 16:34:42 -08:00
|
|
|
}
|
|
|
|
|
2021-05-31 04:37:02 -07:00
|
|
|
// First test without override (ie, normal running CLT corr table)
|
|
|
|
EXPECT_FLOAT_EQ(10, dut.getCrankingOpenLoop(10));
|
|
|
|
EXPECT_FLOAT_EQ(50, dut.getCrankingOpenLoop(50));
|
|
|
|
|
|
|
|
// Test with override (use separate table)
|
|
|
|
engineConfiguration->overrideCrankingIacSetting = true;
|
2020-12-26 16:34:42 -08:00
|
|
|
EXPECT_FLOAT_EQ(5, dut.getCrankingOpenLoop(10));
|
|
|
|
EXPECT_FLOAT_EQ(25, dut.getCrankingOpenLoop(50));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, runningOpenLoopBasic) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 16:34:42 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
engineConfiguration->manIdlePosition = 50;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < efi::size(config->cltIdleCorrBins); i++) {
|
|
|
|
config->cltIdleCorrBins[i] = i * 10;
|
|
|
|
config->cltIdleCorr[i] = i * 0.1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_FLOAT_EQ(5, dut.getRunningOpenLoop(10, 0));
|
|
|
|
EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(50, 0));
|
|
|
|
}
|
|
|
|
|
2021-05-31 14:45:04 -07:00
|
|
|
TEST(idle_v2, runningFanAcBump) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-05-31 14:45:04 -07:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
engineConfiguration->manIdlePosition = 50;
|
|
|
|
engineConfiguration->acIdleExtraOffset = 9;
|
|
|
|
engineConfiguration->fan1ExtraIdle = 7;
|
|
|
|
engineConfiguration->fan2ExtraIdle = 3;
|
|
|
|
|
|
|
|
setArrayValues(config->cltIdleCorr, 1.0f);
|
|
|
|
|
|
|
|
// Start with fan off
|
|
|
|
enginePins.fanRelay.setValue(0);
|
|
|
|
|
|
|
|
// Should be base position
|
|
|
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(10, 0));
|
|
|
|
|
|
|
|
// Turn on AC!
|
|
|
|
engine->acSwitchState = true;
|
|
|
|
EXPECT_FLOAT_EQ(50 + 9, dut.getRunningOpenLoop(10, 0));
|
|
|
|
engine->acSwitchState = false;
|
|
|
|
|
|
|
|
// Turn the fan on!
|
|
|
|
enginePins.fanRelay.setValue(1);
|
|
|
|
EXPECT_FLOAT_EQ(50 + 7, dut.getRunningOpenLoop(10, 0));
|
|
|
|
enginePins.fanRelay.setValue(0);
|
|
|
|
|
|
|
|
// Turn on the other fan!
|
2021-06-15 14:30:35 -07:00
|
|
|
enginePins.fanRelay2.setValue(1);
|
|
|
|
EXPECT_FLOAT_EQ(50 + 3, dut.getRunningOpenLoop(10, 0));
|
2021-05-31 14:45:04 -07:00
|
|
|
|
|
|
|
// Turn on everything!
|
|
|
|
engine->acSwitchState = true;
|
|
|
|
enginePins.fanRelay.setValue(1);
|
2021-06-15 14:30:35 -07:00
|
|
|
enginePins.fanRelay2.setValue(1);
|
|
|
|
EXPECT_FLOAT_EQ(50 + 9 + 7 + 3, dut.getRunningOpenLoop(10, 0));
|
2021-05-31 14:45:04 -07:00
|
|
|
}
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
TEST(idle_v2, runningOpenLoopTpsTaper) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 16:34:42 -08:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
// Zero out base tempco table
|
|
|
|
setArrayValues(config->cltIdleCorr, 0.0f);
|
|
|
|
|
|
|
|
// Add 50% idle position
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->iacByTpsTaper = 50;
|
2020-12-26 16:34:42 -08:00
|
|
|
// At 10% TPS
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idlePidDeactivationTpsThreshold = 10;
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
// Check in-bounds points
|
|
|
|
EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(0, 0));
|
|
|
|
EXPECT_FLOAT_EQ(25, dut.getRunningOpenLoop(0, 5));
|
|
|
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(0, 10));
|
|
|
|
|
|
|
|
// Check out of bounds - shouldn't leave the interval [0, 10]
|
|
|
|
EXPECT_FLOAT_EQ(0, dut.getRunningOpenLoop(0, -5));
|
|
|
|
EXPECT_FLOAT_EQ(50, dut.getRunningOpenLoop(0, 20));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MockOpenLoopIdler : public IdleController {
|
|
|
|
MOCK_METHOD(float, getCrankingOpenLoop, (float clt), (const, override));
|
|
|
|
MOCK_METHOD(float, getRunningOpenLoop, (float clt, SensorResult tps), (const, override));
|
|
|
|
};
|
|
|
|
|
2021-05-31 04:37:02 -07:00
|
|
|
TEST(idle_v2, testOpenLoopCranking) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 16:34:42 -08:00
|
|
|
StrictMock<MockOpenLoopIdler> dut;
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->overrideCrankingIacSetting = true;
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
EXPECT_CALL(dut, getCrankingOpenLoop(30)).WillOnce(Return(44));
|
|
|
|
|
|
|
|
// Should return the value from getCrankingOpenLoop, and ignore running numbers
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_FLOAT_EQ(44, dut.getOpenLoop(ICP::Cranking, 30, 0, 0));
|
2020-12-26 16:34:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, openLoopRunningTaper) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 16:34:42 -08:00
|
|
|
StrictMock<MockOpenLoopIdler> dut;
|
|
|
|
|
|
|
|
EXPECT_CALL(dut, getRunningOpenLoop(30, SensorResult(0))).WillRepeatedly(Return(25));
|
|
|
|
EXPECT_CALL(dut, getCrankingOpenLoop(30)).WillRepeatedly(Return(75));
|
|
|
|
|
|
|
|
// 0 cycles - no taper yet, pure cranking value
|
2021-07-24 13:12:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(75, dut.getOpenLoop(ICP::Running, 30, 0, 0));
|
2021-10-06 09:05:20 -07:00
|
|
|
EXPECT_FLOAT_EQ(75, dut.getOpenLoop(ICP::CrankToIdleTaper, 30, 0, 0));
|
2021-07-06 05:47:06 -07:00
|
|
|
|
|
|
|
// 1/2 taper - half way, 50% each value -> outputs 50
|
2021-07-24 13:12:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(50, dut.getOpenLoop(ICP::Running, 30, 0, 0.5f));
|
2021-10-06 09:05:20 -07:00
|
|
|
EXPECT_FLOAT_EQ(50, dut.getOpenLoop(ICP::CrankToIdleTaper, 30, 0, 0.5f));
|
2021-07-06 05:47:06 -07:00
|
|
|
|
|
|
|
// 1x taper - fully tapered, should be running value
|
2021-07-24 13:12:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Running, 30, 0, 1.0f));
|
2021-10-06 09:05:20 -07:00
|
|
|
EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::CrankToIdleTaper, 30, 0, 1.0f));
|
2021-07-06 05:47:06 -07:00
|
|
|
|
|
|
|
// 2x taper - still fully tapered, should be running value
|
2021-07-24 13:12:07 -07:00
|
|
|
EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::Running, 30, 0, 2.0f));
|
2021-10-06 09:05:20 -07:00
|
|
|
EXPECT_FLOAT_EQ(25, dut.getOpenLoop(ICP::CrankToIdleTaper, 30, 0, 2.0f));
|
2021-07-06 05:47:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, getCrankingTaperFraction) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-07-06 05:47:06 -07:00
|
|
|
StrictMock<MockOpenLoopIdler> dut;
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->afterCrankingIACtaperDuration = 500;
|
2021-07-06 05:47:06 -07:00
|
|
|
|
|
|
|
// 0 cycles - no taper yet, pure cranking value
|
|
|
|
EXPECT_FLOAT_EQ(0, dut.getCrankingTaperFraction());
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
// 250 cycles - half way, 50% each value -> outputs 50
|
|
|
|
for (size_t i = 0; i < 250; i++) {
|
|
|
|
engine->rpmCalculator.onNewEngineCycle();
|
|
|
|
}
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_FLOAT_EQ(0.5f, dut.getCrankingTaperFraction());
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
// 500 cycles - fully tapered, should be running value
|
|
|
|
for (size_t i = 0; i < 250; i++) {
|
|
|
|
engine->rpmCalculator.onNewEngineCycle();
|
|
|
|
}
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_FLOAT_EQ(1, dut.getCrankingTaperFraction());
|
2020-12-26 16:34:42 -08:00
|
|
|
|
|
|
|
// 1000 cycles - still fully tapered, should be running value
|
|
|
|
for (size_t i = 0; i < 500; i++) {
|
|
|
|
engine->rpmCalculator.onNewEngineCycle();
|
|
|
|
}
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_FLOAT_EQ(2, dut.getCrankingTaperFraction());
|
2020-12-26 16:34:42 -08:00
|
|
|
}
|
2021-05-31 03:18:15 -07:00
|
|
|
|
2021-05-31 14:43:58 -07:00
|
|
|
TEST(idle_v2, openLoopCoastingTable) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-05-31 14:43:58 -07:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
// enable & configure feature
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->useIacTableForCoasting = true;
|
2021-05-31 14:43:58 -07:00
|
|
|
for (size_t i = 0; i < CLT_CURVE_SIZE; i++) {
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->iacCoastingBins[i] = 10 * i;
|
|
|
|
engineConfiguration->iacCoasting[i] = 5 * i;
|
2021-05-31 14:43:58 -07:00
|
|
|
}
|
|
|
|
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_FLOAT_EQ(10, dut.getOpenLoop(ICP::Coasting, 20, 0, 2));
|
|
|
|
EXPECT_FLOAT_EQ(20, dut.getOpenLoop(ICP::Coasting, 40, 0, 2));
|
2021-05-31 14:43:58 -07:00
|
|
|
}
|
|
|
|
|
2021-05-31 03:18:15 -07:00
|
|
|
extern int timeNowUs;
|
|
|
|
|
|
|
|
TEST(idle_v2, closedLoopBasic) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-05-31 03:18:15 -07:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
// Not testing PID here, so we can set very simple PID gains
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idleRpmPid.pFactor = 0.5; // 0.5 output per 1 RPM error = 50% per 100 rpm
|
|
|
|
engineConfiguration->idleRpmPid.iFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.dFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.offset = 0;
|
|
|
|
engineConfiguration->idleRpmPid.iFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.periodMs = 0;
|
|
|
|
engineConfiguration->idleRpmPid.minValue = -50;
|
|
|
|
engineConfiguration->idleRpmPid.maxValue = 50;
|
2021-05-31 03:18:15 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idlePidRpmDeadZone = 0;
|
2021-05-31 03:18:15 -07:00
|
|
|
|
|
|
|
// 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
|
2021-06-12 11:21:11 -07:00
|
|
|
EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
|
2021-05-31 03:18:15 -07:00
|
|
|
|
|
|
|
// Below target, should return positive
|
2021-06-12 11:21:11 -07:00
|
|
|
EXPECT_FLOAT_EQ(25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 850, /*tgt*/ 900));
|
2021-05-31 03:18:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, closedLoopDeadzone) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-05-31 03:18:15 -07:00
|
|
|
IdleController dut;
|
|
|
|
|
|
|
|
// Not testing PID here, so we can set very simple PID gains
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idleRpmPid.pFactor = 0.5; // 0.5 output per 1 RPM error = 50% per 100 rpm
|
|
|
|
engineConfiguration->idleRpmPid.iFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.dFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.offset = 0;
|
|
|
|
engineConfiguration->idleRpmPid.iFactor = 0;
|
|
|
|
engineConfiguration->idleRpmPid.periodMs = 0;
|
|
|
|
engineConfiguration->idleRpmPid.minValue = -50;
|
|
|
|
engineConfiguration->idleRpmPid.maxValue = 50;
|
2021-05-31 03:18:15 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idlePidRpmDeadZone = 25;
|
2021-05-31 03:18:15 -07:00
|
|
|
|
|
|
|
// 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
|
2021-06-12 11:21:11 -07:00
|
|
|
EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 950, /*tgt*/ 900));
|
2021-05-31 03:18:15 -07:00
|
|
|
|
|
|
|
// Inside deadzone, should return same as last time
|
2021-06-12 11:21:11 -07:00
|
|
|
EXPECT_FLOAT_EQ(-25, dut.getClosedLoop(ICP::Idling, 0, /*rpm*/ 900, /*tgt*/ 900));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct IntegrationIdleMock : public IdleController {
|
|
|
|
MOCK_METHOD(int, getTargetRpm, (float clt), (const, override));
|
2021-07-06 05:47:06 -07:00
|
|
|
MOCK_METHOD(ICP, determinePhase, (int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction), (const, override));
|
2021-11-23 12:52:43 -08:00
|
|
|
MOCK_METHOD(float, getOpenLoop, (ICP phase, float clt, SensorResult tps, float crankingTaperFraction), (override));
|
2021-06-12 11:21:11 -07:00
|
|
|
MOCK_METHOD(float, getClosedLoop, (ICP phase, float tps, int rpm, int target), (override));
|
2021-07-06 05:47:06 -07:00
|
|
|
MOCK_METHOD(float, getCrankingTaperFraction, (), (const, override));
|
2021-06-12 11:21:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST(idle_v2, IntegrationManual) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-06-12 11:21:11 -07:00
|
|
|
StrictMock<IntegrationIdleMock> dut;
|
|
|
|
|
|
|
|
SensorResult expectedTps = 1;
|
|
|
|
float expectedClt = 37;
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
|
|
|
|
Sensor::setMockValue(SensorType::Clt, expectedClt);
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.mockRpm = 950;
|
2021-06-12 11:21:11 -07:00
|
|
|
|
|
|
|
// Target of 1000 rpm
|
|
|
|
EXPECT_CALL(dut, getTargetRpm(expectedClt))
|
|
|
|
.WillOnce(Return(1000));
|
|
|
|
|
2021-07-06 05:47:06 -07:00
|
|
|
// 30% of the way through cranking taper
|
|
|
|
EXPECT_CALL(dut, getCrankingTaperFraction())
|
|
|
|
.WillOnce(Return(0.3f));
|
|
|
|
|
2021-06-12 11:21:11 -07:00
|
|
|
// Determine phase will claim we're idling
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.3f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(ICP::Idling));
|
|
|
|
|
|
|
|
// Open loop should be asked for an open loop position
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, getOpenLoop(ICP::Idling, expectedClt, expectedTps, 0.3f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(13));
|
|
|
|
|
|
|
|
// getClosedLoop() should not be called!
|
|
|
|
|
|
|
|
EXPECT_EQ(13, dut.getIdlePosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, IntegrationAutomatic) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-06-12 11:21:11 -07:00
|
|
|
StrictMock<IntegrationIdleMock> dut;
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idleMode = IM_AUTO;
|
2021-06-12 11:21:11 -07:00
|
|
|
|
|
|
|
SensorResult expectedTps = 1;
|
|
|
|
float expectedClt = 37;
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
|
|
|
|
Sensor::setMockValue(SensorType::Clt, expectedClt);
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.mockRpm = 950;
|
2021-06-12 11:21:11 -07:00
|
|
|
|
|
|
|
// Target of 1000 rpm
|
|
|
|
EXPECT_CALL(dut, getTargetRpm(expectedClt))
|
|
|
|
.WillOnce(Return(1000));
|
|
|
|
|
2021-07-06 05:47:06 -07:00
|
|
|
// 40% of the way through cranking taper
|
|
|
|
EXPECT_CALL(dut, getCrankingTaperFraction())
|
|
|
|
.WillOnce(Return(0.4f));
|
|
|
|
|
2021-06-12 11:21:11 -07:00
|
|
|
// Determine phase will claim we're idling
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.4f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(ICP::Idling));
|
|
|
|
|
|
|
|
// Open loop should be asked for an open loop position
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, getOpenLoop(ICP::Idling, expectedClt, expectedTps, 0.4f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(13));
|
|
|
|
|
|
|
|
// Closed loop should get called
|
|
|
|
EXPECT_CALL(dut, getClosedLoop(ICP::Idling, expectedTps.Value, 950, 1000))
|
|
|
|
.WillOnce(Return(7));
|
|
|
|
|
|
|
|
// Result should be open + closed
|
|
|
|
EXPECT_EQ(13 + 7, dut.getIdlePosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(idle_v2, IntegrationClamping) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-06-12 11:21:11 -07:00
|
|
|
StrictMock<IntegrationIdleMock> dut;
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->idleMode = IM_AUTO;
|
2021-06-12 11:21:11 -07:00
|
|
|
|
|
|
|
SensorResult expectedTps = 1;
|
|
|
|
float expectedClt = 37;
|
|
|
|
Sensor::setMockValue(SensorType::DriverThrottleIntent, expectedTps.Value);
|
|
|
|
Sensor::setMockValue(SensorType::Clt, expectedClt);
|
2021-08-12 12:16:51 -07:00
|
|
|
Sensor::setMockValue(SensorType::VehicleSpeed, 15.0);
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->rpmCalculator.mockRpm = 950;
|
2021-06-12 11:21:11 -07:00
|
|
|
|
|
|
|
// Target of 1000 rpm
|
|
|
|
EXPECT_CALL(dut, getTargetRpm(expectedClt))
|
|
|
|
.WillOnce(Return(1000));
|
|
|
|
|
2021-07-06 05:47:06 -07:00
|
|
|
// 50% of the way through cranking taper
|
|
|
|
EXPECT_CALL(dut, getCrankingTaperFraction())
|
|
|
|
.WillOnce(Return(0.5f));
|
|
|
|
|
2021-06-12 11:21:11 -07:00
|
|
|
// Determine phase will claim we're idling
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, determinePhase(950, 1000, expectedTps, 15, 0.5f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(ICP::Idling));
|
|
|
|
|
|
|
|
// Open loop should be asked for an open loop position
|
2021-07-06 05:47:06 -07:00
|
|
|
EXPECT_CALL(dut, getOpenLoop(ICP::Idling, expectedClt, expectedTps, 0.5f))
|
2021-06-12 11:21:11 -07:00
|
|
|
.WillOnce(Return(75));
|
|
|
|
|
|
|
|
// Closed loop should get called
|
|
|
|
EXPECT_CALL(dut, getClosedLoop(ICP::Idling, expectedTps.Value, 950, 1000))
|
|
|
|
.WillOnce(Return(75));
|
|
|
|
|
|
|
|
// Result would be 75 + 75 = 150, but it should clamp to 100
|
|
|
|
EXPECT_EQ(100, dut.getIdlePosition());
|
2021-05-31 03:18:15 -07:00
|
|
|
}
|