skip etb init if no primary sensor (#3136)

* skip init if no primary sensor

* specific test
This commit is contained in:
Matthew Kennedy 2021-08-11 14:45:44 -07:00 committed by GitHub
parent 068daf3d1b
commit 90a0e47b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -185,6 +185,11 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara
return false;
}
// If no sensor is configured for this throttle, skip initialization.
if (!Sensor::hasSensor(functionToTpsSensorPrimary(function))) {
return false;
}
if (!Sensor::isRedundant(m_positionSensor)) {
firmwareError(
OBD_Throttle_Position_Sensor_Circuit_Malfunction,

View File

@ -174,6 +174,7 @@ TEST(etb, initializationNotRedundantTps) {
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
// Not redundant, should fail upon init
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, false);
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
@ -186,11 +187,32 @@ TEST(etb, initializationNotRedundantPedal) {
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, false);
// Normal redundant TPS
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
}
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));
}
TEST(etb, initializationNoThrottles) {
// This tests the case where you don't want an ETB, and expect everything to go fine
EtbController duts[2];
@ -209,6 +231,7 @@ TEST(etb, initializationNoThrottles) {
Sensor::resetMockValue(SensorType::AcceleratorPedal);
// Not redundant TPS (aka cable throttle)
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, false);
EXPECT_NO_FATAL_ERROR(doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE));
@ -251,6 +274,7 @@ TEST(etb, testSetpointOnlyPedal) {
EXPECT_EQ(etb.getSetpoint(), unexpected);
// 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);
@ -296,6 +320,7 @@ TEST(etb, setpointIdle) {
engineConfiguration->etbIdleThrottleRange = 0;
// 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);
@ -353,6 +378,7 @@ TEST(etb, setpointRevLimit) {
engineConfiguration->etbRevLimitRange = 750;
// 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);
@ -482,6 +508,7 @@ TEST(etb, setOutputInvalid) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Redundant TPS & accelerator pedal required for init
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
@ -502,6 +529,7 @@ TEST(etb, setOutputValid) {
StrictMock<MockMotor> motor;
// 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);
@ -522,6 +550,7 @@ TEST(etb, setOutputValid2) {
StrictMock<MockMotor> motor;
// 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);
@ -542,6 +571,7 @@ TEST(etb, setOutputOutOfRangeHigh) {
StrictMock<MockMotor> motor;
// 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);
@ -562,6 +592,7 @@ TEST(etb, setOutputOutOfRangeLow) {
StrictMock<MockMotor> motor;
// 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);
@ -582,6 +613,7 @@ TEST(etb, setOutputPauseControl) {
StrictMock<MockMotor> motor;
// 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);
@ -603,6 +635,7 @@ TEST(etb, setOutputLimpHome) {
StrictMock<MockMotor> motor;
// 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);
@ -626,6 +659,7 @@ TEST(etb, closedLoopPid) {
pid.minValue = -60;
// 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);
@ -651,6 +685,7 @@ TEST(etb, openLoopThrottle) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Redundant TPS & accelerator pedal required for init
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
@ -673,6 +708,7 @@ TEST(etb, openLoopNonThrottle) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Redundant TPS & accelerator pedal required for init
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);