2019-12-13 11:55:20 -08:00
|
|
|
/*
|
|
|
|
* @file test_etb.cpp
|
|
|
|
*
|
|
|
|
* @date Dec 13, 2019
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2019-12-13 11:55:20 -08:00
|
|
|
*/
|
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2020-12-06 22:27:27 -08:00
|
|
|
#include "electronic_throttle_impl.h"
|
2019-12-13 11:55:20 -08:00
|
|
|
#include "dc_motor.h"
|
2020-07-26 09:03:36 -07:00
|
|
|
#include "idle_thread.h"
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-20 13:26:35 -07:00
|
|
|
#include "mocks.h"
|
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
using ::testing::_;
|
2020-04-20 11:34:45 -07:00
|
|
|
using ::testing::Ne;
|
2020-04-19 17:32:41 -07:00
|
|
|
using ::testing::StrictMock;
|
|
|
|
|
|
|
|
TEST(etb, initializationNoPedal) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, _, _, false)).WillOnce(Return(false));
|
|
|
|
EXPECT_CALL(mocks[1], init(ETB_Throttle2, _, _, _, false)).WillOnce(Return(false));
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-10-18 14:26:38 -07:00
|
|
|
// This shouldn't throw, since no throttles are configured, but no pedal is configured either
|
2021-11-16 01:15:29 -08:00
|
|
|
EXPECT_NO_FATAL_ERROR(doInitElectronicThrottle());
|
2020-10-18 14:26:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, initializationMissingThrottle) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE, [](engine_configuration_s* engineConfiguration) {
|
2021-11-08 09:39:41 -08:00
|
|
|
engineConfiguration->etbFunctions[0] = ETB_None;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_None;
|
|
|
|
});
|
2020-10-18 14:26:38 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
2021-11-08 09:44:37 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).Times(0);
|
|
|
|
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).Times(0);
|
2020-10-18 14:26:38 -07:00
|
|
|
|
|
|
|
// Must have a sensor configured before init
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
2020-10-18 14:26:38 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
|
|
|
|
|
|
|
|
// This should throw: a pedal is configured but no throttles
|
2021-11-16 01:15:29 -08:00
|
|
|
EXPECT_FATAL_ERROR(doInitElectronicThrottle());
|
2020-04-19 17:32:41 -07:00
|
|
|
}
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
TEST(etb, initializationSingleThrottle) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE, [](engine_configuration_s* engineConfiguration) {
|
2021-11-08 09:39:41 -08:00
|
|
|
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_None;
|
|
|
|
});
|
2019-12-13 11:55:20 -08:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
2020-04-02 05:04:12 -07:00
|
|
|
// Must have a sensor configured before init
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
2020-06-16 18:38:09 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
// Expect mock0 to be init as throttle 1, and PID params
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
|
2020-04-19 17:32:41 -07:00
|
|
|
|
2020-10-18 14:26:38 -07:00
|
|
|
// Expect mock1 to be init as none
|
2021-11-08 09:44:37 -08:00
|
|
|
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).Times(0);
|
2020-10-18 14:26:38 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
doInitElectronicThrottle();
|
2020-10-18 14:26:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, initializationSingleThrottleInSecondSlot) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE, [](engine_configuration_s* engineConfiguration) {
|
2021-11-08 09:39:41 -08:00
|
|
|
engineConfiguration->etbFunctions[0] = ETB_None;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_Throttle1;
|
|
|
|
});
|
2020-10-18 14:26:38 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must have a sensor configured before init
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0, false);
|
2020-10-18 14:26:38 -07:00
|
|
|
|
|
|
|
// Expect mock0 to be init as none
|
2021-11-08 09:44:37 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _, true)).Times(0);
|
2020-10-18 14:26:38 -07:00
|
|
|
|
|
|
|
// Expect mock1 to be init as throttle 1, and PID params
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[1], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
|
2020-04-19 17:32:41 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
doInitElectronicThrottle();
|
2020-04-19 17:32:41 -07:00
|
|
|
}
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
TEST(etb, initializationDualThrottle) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-19 17:32:41 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must have a sensor configured before init
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0, false);
|
2020-04-19 17:32:41 -07:00
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 25.0f, true);
|
|
|
|
Sensor::setMockValue(SensorType::Tps2, 25.0f, true);
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-10-18 14:26:38 -07:00
|
|
|
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_Throttle2;
|
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
// Expect mock0 to be init as throttle 1, and PID params
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
// Expect mock1 to be init as throttle 2, and PID params
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[1], init(ETB_Throttle2, _, &engineConfiguration->etb, Ne(nullptr), true)).WillOnce(Return(true));
|
2020-04-19 17:32:41 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
doInitElectronicThrottle();
|
2019-12-13 11:55:20 -08:00
|
|
|
}
|
|
|
|
|
2020-10-19 05:04:27 -07:00
|
|
|
TEST(etb, initializationWastegate) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE, [](engine_configuration_s* engineConfiguration) {
|
2021-11-08 09:27:02 -08:00
|
|
|
engineConfiguration->etbFunctions[0] = ETB_Wastegate;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_None;
|
|
|
|
});
|
2020-10-19 05:04:27 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expect mock0 to be init as throttle 1, and PID wastegate params
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_CALL(mocks[0], init(ETB_Wastegate, _, &engineConfiguration->etbWastegatePid, Ne(nullptr), false)).WillOnce(Return(true));
|
2020-10-19 05:04:27 -07:00
|
|
|
|
|
|
|
// Expect mock1 to be init as none
|
2021-11-08 09:44:37 -08:00
|
|
|
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, false)).Times(0);
|
2020-10-19 05:04:27 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
doInitElectronicThrottle();
|
2020-10-19 05:04:27 -07:00
|
|
|
}
|
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
TEST(etb, initializationNoFunction) {
|
|
|
|
StrictMock<MockMotor> motor;
|
2020-07-26 03:11:56 -07:00
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
EtbController dut;
|
2020-07-26 09:03:36 -07:00
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
// When init called with ETB_None, should ignore the provided params and return false
|
2020-12-08 03:24:20 -08:00
|
|
|
EXPECT_FALSE(dut.init(ETB_None, &motor, nullptr, nullptr, false));
|
2020-07-26 09:03:36 -07:00
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
// This should no-op, it shouldn't call motor.set(float duty)
|
|
|
|
dut.setOutput(0.5f);
|
2020-07-26 03:11:56 -07:00
|
|
|
}
|
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
TEST(etb, initializationNotRedundantTps) {
|
|
|
|
EtbController dut;
|
|
|
|
|
|
|
|
// Needs pedal for init
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
|
|
|
// Not redundant, should fail upon init
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, false);
|
|
|
|
|
|
|
|
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
|
|
|
|
}
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
TEST(etb, initializationNotRedundantPedal) {
|
|
|
|
EtbController dut;
|
|
|
|
|
|
|
|
// Init pedal without redundancy
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, false);
|
|
|
|
|
|
|
|
// Normal redundant TPS
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
|
|
|
|
|
|
|
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
|
|
|
|
}
|
|
|
|
|
2021-08-11 14:45:44 -07:00
|
|
|
TEST(etb, initializationNoPrimarySensor) {
|
|
|
|
Sensor::resetAllMocks();
|
|
|
|
|
|
|
|
EtbController dut;
|
|
|
|
|
|
|
|
// Needs pedal for init
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
|
|
|
|
|
|
|
// Redundant, but no primary configured
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
|
|
|
|
|
|
|
EXPECT_FALSE(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
|
|
|
|
|
|
|
|
// Now configure primary TPS
|
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
|
|
|
|
|
|
|
// With primary TPS, should return true (ie, throttle was configured)
|
|
|
|
EXPECT_TRUE(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
|
|
|
|
}
|
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
TEST(etb, initializationNoThrottles) {
|
|
|
|
// This tests the case where you don't want an ETB, and expect everything to go fine
|
|
|
|
EtbController duts[2];
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &duts[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure ETB functions, but no pedal
|
|
|
|
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
|
|
|
|
engineConfiguration->etbFunctions[1] = ETB_Throttle2;
|
|
|
|
|
|
|
|
// No pedal - don't init ETBs
|
|
|
|
Sensor::resetMockValue(SensorType::AcceleratorPedal);
|
|
|
|
|
|
|
|
// Not redundant TPS (aka cable throttle)
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, false);
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
EXPECT_NO_FATAL_ERROR(doInitElectronicThrottle());
|
2020-12-08 03:24:20 -08:00
|
|
|
}
|
|
|
|
|
2020-04-20 13:26:35 -07:00
|
|
|
TEST(etb, idlePlumbing) {
|
|
|
|
StrictMock<MockEtb> mocks[ETB_COUNT];
|
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-07-26 09:03:36 -07:00
|
|
|
engineConfiguration->useETBforIdleControl = true;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
|
|
|
|
for (int i = 0; i < ETB_COUNT; i++) {
|
|
|
|
engine->etbControllers[i] = &mocks[i];
|
|
|
|
|
|
|
|
EXPECT_CALL(mocks[i], setIdlePosition(33.0f));
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
applyIACposition(33.0f);
|
2020-04-20 13:26:35 -07:00
|
|
|
}
|
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
TEST(etb, testSetpointOnlyPedal) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-03-03 14:56:50 -08:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
// Don't use ETB for idle, we aren't testing that yet - just pedal table for now
|
|
|
|
engineConfiguration->useETBforIdleControl = false;
|
|
|
|
|
|
|
|
EtbController etb;
|
2020-04-20 11:34:45 -07:00
|
|
|
|
|
|
|
// Mock pedal map that's just passthru pedal -> target
|
|
|
|
StrictMock<MockVp3d> pedalMap;
|
|
|
|
EXPECT_CALL(pedalMap, getValue(_, _))
|
|
|
|
.WillRepeatedly([](float xRpm, float y) {
|
|
|
|
return y;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Uninitialized ETB must return unexpected (and not deference a null pointer)
|
|
|
|
EXPECT_EQ(etb.getSetpoint(), unexpected);
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
|
2020-03-19 17:02:49 -07:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
// Check endpoints and midpoint
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-19 17:32:41 -07:00
|
|
|
EXPECT_EQ(50, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
|
2020-04-19 17:32:41 -07:00
|
|
|
EXPECT_EQ(100, etb.getSetpoint().value_or(-1));
|
2019-12-13 11:55:20 -08:00
|
|
|
|
2020-04-19 17:32:41 -07:00
|
|
|
// Test some floating point pedal/output values
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.8302f, true);
|
2020-04-19 17:32:41 -07:00
|
|
|
EXPECT_NEAR(50.8302, etb.getSetpoint().value_or(-1), EPS4D);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 51.6605f, true);
|
2020-04-19 17:32:41 -07:00
|
|
|
EXPECT_NEAR(51.6605, etb.getSetpoint().value_or(-1), EPS4D);
|
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
// Valid but out of range - should clamp to [0, 100]
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, -5, true);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 105, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
EXPECT_EQ(100, etb.getSetpoint().value_or(-1));
|
|
|
|
|
2020-04-20 13:26:35 -07:00
|
|
|
// Check that ETB idle does NOT work - it's disabled
|
|
|
|
etb.setIdlePosition(50);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 20, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
EXPECT_EQ(20, etb.getSetpoint().value_or(-1));
|
|
|
|
|
2020-04-28 13:52:40 -07:00
|
|
|
// Test invalid pedal position - should give 0 position
|
2020-04-19 17:32:41 -07:00
|
|
|
Sensor::resetMockValue(SensorType::AcceleratorPedal);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// Check that adjustable clamping works correctly
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->etbMaximumPosition = 90;
|
2021-11-05 15:16:19 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 85, true);
|
|
|
|
EXPECT_EQ(85, etb.getSetpoint().value_or(-1));
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 90, true);
|
|
|
|
EXPECT_EQ(90, etb.getSetpoint().value_or(-1));
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 95, true);
|
|
|
|
EXPECT_EQ(90, etb.getSetpoint().value_or(-1));
|
2020-03-03 14:56:50 -08:00
|
|
|
}
|
2020-04-19 14:18:47 -07:00
|
|
|
|
2020-04-20 13:26:35 -07:00
|
|
|
TEST(etb, setpointIdle) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-20 13:26:35 -07:00
|
|
|
|
|
|
|
// Use ETB for idle, but don't give it any range (yet)
|
|
|
|
engineConfiguration->useETBforIdleControl = true;
|
|
|
|
engineConfiguration->etbIdleThrottleRange = 0;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-20 13:26:35 -07:00
|
|
|
EtbController etb;
|
|
|
|
|
|
|
|
// Mock pedal map that's just passthru pedal -> target
|
|
|
|
StrictMock<MockVp3d> pedalMap;
|
|
|
|
EXPECT_CALL(pedalMap, getValue(_, _))
|
|
|
|
.WillRepeatedly([](float xRpm, float y) {
|
|
|
|
return y;
|
|
|
|
});
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
|
|
|
|
// No idle range, should just pass pedal
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
EXPECT_EQ(50, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// Idle should now have 10% range
|
|
|
|
engineConfiguration->etbIdleThrottleRange = 10;
|
|
|
|
|
2020-04-20 14:29:03 -07:00
|
|
|
// 50% idle position should increase setpoint by 5% when closed, and 0% when open
|
2020-04-20 13:26:35 -07:00
|
|
|
etb.setIdlePosition(50);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
EXPECT_FLOAT_EQ(5, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-20 14:29:03 -07:00
|
|
|
EXPECT_FLOAT_EQ(52.5, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
|
2020-04-20 14:29:03 -07:00
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
2020-04-20 13:26:35 -07:00
|
|
|
|
2020-04-20 14:29:03 -07:00
|
|
|
// 100% setpoint should increase by 10% closed, scaled 0% at wot
|
2020-04-20 13:26:35 -07:00
|
|
|
etb.setIdlePosition(100);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-20 14:29:03 -07:00
|
|
|
EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
|
2020-04-20 14:29:03 -07:00
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
2020-04-20 13:26:35 -07:00
|
|
|
|
|
|
|
// 125% setpoint should clamp to 10% increase
|
|
|
|
etb.setIdlePosition(125);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-04-20 13:26:35 -07:00
|
|
|
EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1));
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
|
2020-04-20 14:29:03 -07:00
|
|
|
EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1));
|
2020-04-20 13:26:35 -07:00
|
|
|
}
|
|
|
|
|
2021-06-16 05:44:48 -07:00
|
|
|
TEST(etb, setpointRevLimit) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2021-06-16 05:44:48 -07:00
|
|
|
|
|
|
|
// Configure 5000 limit start, with 750 rpm taper
|
|
|
|
engineConfiguration->etbRevLimitStart = 5000;
|
|
|
|
engineConfiguration->etbRevLimitRange = 750;
|
|
|
|
|
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2021-06-16 05:44:48 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
|
|
|
|
|
|
|
EtbController etb;
|
|
|
|
|
|
|
|
// Mock pedal map to just return 80%
|
|
|
|
StrictMock<MockVp3d> pedalMap;
|
|
|
|
EXPECT_CALL(pedalMap, getValue(_, _))
|
|
|
|
.WillRepeatedly([](float, float) {
|
|
|
|
return 80;
|
|
|
|
});
|
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
|
|
|
|
|
|
|
|
// Below threshold, should return unadjusted throttle
|
2022-01-20 19:40:15 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 1000);
|
2021-06-16 05:44:48 -07:00
|
|
|
EXPECT_EQ(80, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// At threshold, should return unadjusted throttle
|
2022-01-20 19:40:15 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 5000);
|
2021-06-16 05:44:48 -07:00
|
|
|
EXPECT_EQ(80, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// Middle of range, should return half of unadjusted
|
2022-01-20 19:40:15 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 5375);
|
2021-06-16 05:44:48 -07:00
|
|
|
EXPECT_EQ(40, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// At limit+range, should return 0
|
2022-01-20 19:40:15 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 5750);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-06-16 05:44:48 -07:00
|
|
|
|
|
|
|
// Above limit+range, should return 0
|
2022-01-20 19:40:15 -08:00
|
|
|
Sensor::setMockValue(SensorType::Rpm, 6000);
|
2021-11-05 15:16:19 -07:00
|
|
|
EXPECT_EQ(1, etb.getSetpoint().value_or(-1));
|
2021-06-16 05:44:48 -07:00
|
|
|
}
|
|
|
|
|
2020-12-06 20:59:18 -08:00
|
|
|
TEST(etb, setpointNoPedalMap) {
|
|
|
|
EtbController etb;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-06 22:27:27 -08:00
|
|
|
|
2020-12-06 20:59:18 -08:00
|
|
|
// Don't pass a pedal map
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, nullptr, true);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
EXPECT_EQ(etb.getSetpoint(), unexpected);
|
|
|
|
}
|
|
|
|
|
2020-09-28 13:33:07 -07:00
|
|
|
TEST(etb, setpointIdleValveController) {
|
2020-07-26 03:11:56 -07:00
|
|
|
EtbController etb;
|
2020-09-28 13:33:07 -07:00
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_IdleValve, nullptr, nullptr, nullptr, false);
|
2020-07-26 03:11:56 -07:00
|
|
|
|
|
|
|
etb.setIdlePosition(0);
|
|
|
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setIdlePosition(50);
|
|
|
|
EXPECT_FLOAT_EQ(50, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setIdlePosition(100);
|
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// Out of range should be clamped
|
|
|
|
etb.setIdlePosition(-10);
|
|
|
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setIdlePosition(110);
|
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
|
|
|
}
|
|
|
|
|
2020-10-18 18:57:04 -07:00
|
|
|
TEST(etb, setpointWastegateController) {
|
|
|
|
EtbController etb;
|
|
|
|
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Wastegate, nullptr, nullptr, nullptr, false);
|
2020-10-18 18:57:04 -07:00
|
|
|
|
|
|
|
etb.setWastegatePosition(0);
|
|
|
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setWastegatePosition(50);
|
|
|
|
EXPECT_FLOAT_EQ(50, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setWastegatePosition(100);
|
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
|
|
|
|
|
|
|
// Out of range should be clamped
|
|
|
|
etb.setWastegatePosition(-10);
|
|
|
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
|
|
|
etb.setWastegatePosition(110);
|
|
|
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
|
|
|
}
|
|
|
|
|
2020-04-19 14:18:47 -07:00
|
|
|
TEST(etb, etbTpsSensor) {
|
|
|
|
// Throw some distinct values on the TPS sensors so we can identify that we're getting the correct one
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 25.0f, true);
|
|
|
|
Sensor::setMockValue(SensorType::Tps2, 75.0f, true);
|
2020-09-28 13:33:07 -07:00
|
|
|
Sensor::setMockValue(SensorType::WastegatePosition, 33.0f);
|
|
|
|
Sensor::setMockValue(SensorType::IdlePosition, 66.0f);
|
2020-04-19 14:18:47 -07:00
|
|
|
|
2021-07-04 19:28:31 -07:00
|
|
|
// Redundant accelerator pedal required for init
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
|
2020-04-19 14:18:47 -07:00
|
|
|
// Test first throttle
|
|
|
|
{
|
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, nullptr, true);
|
2020-04-19 14:18:47 -07:00
|
|
|
EXPECT_EQ(etb.observePlant().Value, 25.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test second throttle
|
|
|
|
{
|
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle2, nullptr, nullptr, nullptr, true);
|
2020-04-19 14:18:47 -07:00
|
|
|
EXPECT_EQ(etb.observePlant().Value, 75.0f);
|
|
|
|
}
|
2020-09-28 13:33:07 -07:00
|
|
|
|
|
|
|
// Test wastegate control
|
|
|
|
{
|
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Wastegate, nullptr, nullptr, nullptr, true);
|
2020-09-28 13:33:07 -07:00
|
|
|
EXPECT_EQ(etb.observePlant().Value, 33.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test idle valve control
|
|
|
|
{
|
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_IdleValve, nullptr, nullptr, nullptr, true);
|
2020-09-28 13:33:07 -07:00
|
|
|
EXPECT_EQ(etb.observePlant().Value, 66.0f);
|
|
|
|
}
|
2020-04-19 14:18:47 -07:00
|
|
|
}
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
TEST(etb, setOutputInvalid) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-28 13:52:40 -07:00
|
|
|
|
2021-07-04 19:28:31 -07:00
|
|
|
// Redundant TPS & accelerator pedal required for init
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2021-07-04 19:28:31 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
// Should be disabled in case of unexpected
|
|
|
|
EXPECT_CALL(motor, disable());
|
|
|
|
|
|
|
|
etb.setOutput(unexpected);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, setOutputValid) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-20 10:52:20 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
// Should be enabled and value set
|
|
|
|
EXPECT_CALL(motor, enable());
|
|
|
|
EXPECT_CALL(motor, set(0.25f))
|
|
|
|
.WillOnce(Return(false));
|
|
|
|
|
|
|
|
etb.setOutput(25.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, setOutputValid2) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-20 10:52:20 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
// Should be enabled and value set
|
|
|
|
EXPECT_CALL(motor, enable());
|
|
|
|
EXPECT_CALL(motor, set(-0.25f))
|
|
|
|
.WillOnce(Return(false));
|
|
|
|
|
|
|
|
etb.setOutput(-25.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, setOutputOutOfRangeHigh) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-20 10:52:20 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
// Should be enabled and value set
|
|
|
|
EXPECT_CALL(motor, enable());
|
|
|
|
EXPECT_CALL(motor, set(0.90f));
|
|
|
|
|
|
|
|
// Off scale - should get clamped to 90%
|
|
|
|
etb.setOutput(110);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, setOutputOutOfRangeLow) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-20 10:52:20 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-20 10:52:20 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-20 10:52:20 -07:00
|
|
|
|
|
|
|
// Should be enabled and value set
|
|
|
|
EXPECT_CALL(motor, enable());
|
|
|
|
EXPECT_CALL(motor, set(-0.90f));
|
|
|
|
|
|
|
|
// Off scale - should get clamped to -90%
|
|
|
|
etb.setOutput(-110);
|
|
|
|
}
|
2020-04-24 14:54:03 -07:00
|
|
|
|
2020-04-28 13:52:40 -07:00
|
|
|
TEST(etb, setOutputPauseControl) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-04-28 13:52:40 -07:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-28 13:52:40 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
2020-04-28 13:52:40 -07:00
|
|
|
|
|
|
|
// Pause control - should get no output
|
|
|
|
engineConfiguration->pauseEtbControl = true;
|
|
|
|
|
|
|
|
// Disable should be called, and set shouldn't be called
|
|
|
|
EXPECT_CALL(motor, disable());
|
|
|
|
|
|
|
|
etb.setOutput(25.0f);
|
|
|
|
}
|
|
|
|
|
2020-12-26 18:47:27 -08:00
|
|
|
TEST(etb, setOutputLimpHome) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-26 18:47:27 -08:00
|
|
|
StrictMock<MockMotor> motor;
|
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-26 18:47:27 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-26 18:47:27 -08:00
|
|
|
|
|
|
|
EtbController etb;
|
|
|
|
etb.init(ETB_Throttle1, &motor, nullptr, nullptr, true);
|
|
|
|
|
|
|
|
// Should be disabled when in ETB limp mode
|
|
|
|
EXPECT_CALL(motor, disable());
|
|
|
|
|
|
|
|
// Trip a fatal error
|
2021-11-17 00:54:21 -08:00
|
|
|
engine->limpManager.fatalError();
|
2020-12-26 18:47:27 -08:00
|
|
|
|
|
|
|
etb.setOutput(25.0f);
|
|
|
|
}
|
|
|
|
|
2020-04-24 14:54:03 -07:00
|
|
|
TEST(etb, closedLoopPid) {
|
|
|
|
pid_s pid = {};
|
|
|
|
pid.pFactor = 5;
|
|
|
|
pid.maxValue = 75;
|
|
|
|
pid.minValue = -60;
|
2020-04-28 13:52:40 -07:00
|
|
|
|
2021-05-30 16:19:57 -07:00
|
|
|
// Must have TPS & PPS initialized for ETB setup
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2020-12-08 03:24:20 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
|
2021-05-30 16:19:57 -07:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
|
2020-12-08 03:24:20 -08:00
|
|
|
|
2020-04-24 14:54:03 -07:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, nullptr, &pid, nullptr, true);
|
2020-04-24 14:54:03 -07:00
|
|
|
|
|
|
|
// Disable autotune for now
|
|
|
|
Engine e;
|
2021-11-15 21:23:14 -08:00
|
|
|
EngineTestHelperBase base(&e, nullptr, nullptr);
|
2020-04-24 14:54:03 -07:00
|
|
|
e.etbAutoTune = false;
|
|
|
|
|
|
|
|
// Setpoint greater than actual, should be positive output
|
|
|
|
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 40).value_or(-1), 50);
|
|
|
|
// Likewise but negative
|
|
|
|
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 52).value_or(-1), -10);
|
|
|
|
|
|
|
|
// Test PID limiting
|
|
|
|
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 70).value_or(-1), -60);
|
|
|
|
EXPECT_FLOAT_EQ(etb.getClosedLoop(50, 30).value_or(-1), 75);
|
|
|
|
}
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
TEST(etb, openLoopThrottle) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
2021-07-04 19:28:31 -07:00
|
|
|
// Redundant TPS & accelerator pedal required for init
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2021-07-04 19:28:31 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
|
2020-12-06 20:59:18 -08:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Throttle1, nullptr, nullptr, nullptr, true);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
// Map [0, 100] -> [-50, 50]
|
2022-05-02 03:30:06 -07:00
|
|
|
setLinearCurve(config->etbBiasBins, 0, 100);
|
|
|
|
setLinearCurve(config->etbBiasValues, -50, 50);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
EXPECT_NEAR(-50, etb.getOpenLoop(0).value_or(-1), EPS4D);
|
|
|
|
EXPECT_NEAR(-25, etb.getOpenLoop(25).value_or(-1), EPS4D);
|
|
|
|
EXPECT_NEAR(0, etb.getOpenLoop(50).value_or(-1), EPS4D);
|
|
|
|
EXPECT_NEAR(25, etb.getOpenLoop(75).value_or(-1), EPS4D);
|
|
|
|
EXPECT_NEAR(50, etb.getOpenLoop(100).value_or(-1), EPS4D);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, openLoopNonThrottle) {
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth(TEST_ENGINE);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
2021-07-04 19:28:31 -07:00
|
|
|
// Redundant TPS & accelerator pedal required for init
|
2021-08-11 14:45:44 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1Primary, 0);
|
2021-07-04 19:28:31 -07:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 0, true);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
|
|
|
|
|
2020-12-06 20:59:18 -08:00
|
|
|
EtbController etb;
|
2020-12-08 03:24:20 -08:00
|
|
|
etb.init(ETB_Wastegate, nullptr, nullptr, nullptr, false);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
// Map [0, 100] -> [-50, 50]
|
2022-05-02 03:30:06 -07:00
|
|
|
setLinearCurve(config->etbBiasBins, 0, 100);
|
|
|
|
setLinearCurve(config->etbBiasValues, -50, 50);
|
2020-12-06 20:59:18 -08:00
|
|
|
|
|
|
|
// Should all return 0, as non-throttles don't use open loop table
|
|
|
|
EXPECT_EQ(0, etb.getOpenLoop(0).value_or(-1));
|
|
|
|
EXPECT_EQ(0, etb.getOpenLoop(25).value_or(-1));
|
|
|
|
EXPECT_EQ(0, etb.getOpenLoop(50).value_or(-1));
|
|
|
|
EXPECT_EQ(0, etb.getOpenLoop(75).value_or(-1));
|
|
|
|
EXPECT_EQ(0, etb.getOpenLoop(100).value_or(-1));
|
|
|
|
}
|