etb jam tests #489

This commit is contained in:
Matthew Kennedy 2024-09-17 18:18:00 -07:00
parent 5411f47767
commit 877ec23c47
2 changed files with 11 additions and 49 deletions

View File

@ -709,6 +709,8 @@ TEST(etb, setOutputLimpHome) {
}
TEST(etb, closedLoopPid) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
pid_s pid = {};
pid.pFactor = 5;
pid.maxValue = 75;
@ -723,9 +725,7 @@ TEST(etb, closedLoopPid) {
etb.init(DC_Throttle1, nullptr, &pid, nullptr, true);
// Disable autotune for now
Engine e;
EngineTestHelperBase base(&e, nullptr, nullptr);
e.etbAutoTune = false;
engine->etbAutoTune = false;
// Setpoint greater than actual, should be positive output
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 40).value_or(-1), 50);
@ -740,51 +740,37 @@ TEST(etb, closedLoopPid) {
TEST(etb, jamDetection) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
pid_s pid = {};
// I-only since we're testing out the integrator
pid.pFactor = 0;
pid.iFactor = 1;
pid.dFactor = 0;
pid.maxValue = 50;
pid.minValue = -50;
// Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
// Limit of 5%, 1 second
engineConfiguration->etbJamIntegratorLimit = 5;
engineConfiguration->jamDetectThreshold = 5;
engineConfiguration->etbJamTimeout = 1;
EtbController etb;
etb.init(DC_Throttle1, nullptr, &pid, nullptr, true);
etb.init(DC_Throttle1, nullptr, nullptr, nullptr, true);
setTimeNowUs(0);
// Reset timer while under integrator limit
EXPECT_EQ(etb.getPidState().iTerm, 0);
etb.checkOutput(0);
// Reset timer while under error limit
etb.checkJam(10, 14);
EXPECT_EQ(etb.jamTimer, 0);
EXPECT_FALSE(etb.jamDetected);
for (size_t i = 0; i < ETB_LOOP_FREQUENCY; i++) {
// Error of 10, should accumulate 10 integrator per second
etb.getClosedLoop(50, 40);
}
EXPECT_NEAR(etb.getPidState().iTerm, 10.0f, 1e-3);
// Start a jam
etb.checkJam(10, 16);
// Just under time limit, no jam yet
setTimeNowUs(0.9e6);
etb.checkOutput(0);
etb.checkJam(10, 16);
EXPECT_NEAR(etb.jamTimer, 0.9f, 1e-3);
EXPECT_FALSE(etb.jamDetected);
// Above the time limit, jam detected!
setTimeNowUs(1.1e6);
etb.checkOutput(0);
etb.checkJam(10, 16);
EXPECT_TRUE(etb.jamDetected);
}

View File

@ -23,30 +23,6 @@ static EtbController * initEtbIntegratedTest() {
return (EtbController*)engine->etbControllers[0];
}
TEST(etb, integrated) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
EtbController *etb = initEtbIntegratedTest();
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 40);
Sensor::setMockValue(SensorType::AcceleratorPedalSecondary, 40);
etb->update();
ASSERT_EQ(engine->outputChannels.etbTarget, 40);
ASSERT_NEAR(etb->prevOutput, 120.363, EPS3D);
ASSERT_NEAR(etb->etbDutyAverage, 60.1813, EPS3D);
Sensor::setMockValue(SensorType::AcceleratorPedal, 10, true);
etb->update();
ASSERT_NEAR(etb->etbDutyAverage, 70.0741, EPS3D);
ASSERT_NEAR(etb->etbDutyRateOfChange, 130.2554, EPS3D);
float destination;
int offset = ELECTRONIC_THROTTLE_BASE_ADDRESS + offsetof(electronic_throttle_s, etbDutyRateOfChange);
copyRange((uint8_t*)&destination, getLiveDataFragments(), offset, sizeof(destination));
ASSERT_NEAR(destination, 130.2554, EPS3D);
}
// TEST(etb, intermittentTps) {
// EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
// EtbController *etb = initEtbIntegratedTest();