require redundant pedal (#2758)

* require redundant pedal

* return false

* I don't typing good

* tests

* tests
This commit is contained in:
Matthew Kennedy 2021-05-30 16:19:57 -07:00 committed by GitHub
parent 1a55e563ef
commit ec8e1eee69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 37 deletions

View File

@ -200,6 +200,15 @@ bool EtbController::init(etb_function_e function, DcMotor *motor, pid_s *pidPara
return false; return false;
} }
if (!Sensor::isRedundant(SensorType::AcceleratorPedal)) {
firmwareError(
OBD_Throttle_Position_Sensor_Circuit_Malfunction,
"Use of electronic throttle requires accelerator pedal to be redundant."
);
return false;
}
} }
m_motor = motor; m_motor = motor;

View File

@ -50,7 +50,7 @@ TEST(etb, initializationMissingThrottle) {
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).WillOnce(Return(false)); EXPECT_CALL(mocks[1], init(ETB_None, _, _, _, true)).WillOnce(Return(false));
// Must have a sensor configured before init // Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
// This should throw: a pedal is configured but no throttles // This should throw: a pedal is configured but no throttles
@ -67,7 +67,7 @@ TEST(etb, initializationSingleThrottle) {
} }
// Must have a sensor configured before init // Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
engineConfiguration->etbFunctions[0] = ETB_Throttle1; engineConfiguration->etbFunctions[0] = ETB_Throttle1;
@ -92,8 +92,8 @@ TEST(etb, initializationSingleThrottleInSecondSlot) {
} }
// Must have a sensor configured before init // Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0, false);
engineConfiguration->etbFunctions[0] = ETB_None; engineConfiguration->etbFunctions[0] = ETB_None;
engineConfiguration->etbFunctions[1] = ETB_Throttle1; engineConfiguration->etbFunctions[1] = ETB_Throttle1;
@ -117,8 +117,8 @@ TEST(etb, initializationDualThrottle) {
} }
// Must have a sensor configured before init // Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0, false);
Sensor::setMockValue(SensorType::Tps1, 25.0f, true); Sensor::setMockValue(SensorType::Tps1, 25.0f, true);
Sensor::setMockValue(SensorType::Tps2, 25.0f, true); Sensor::setMockValue(SensorType::Tps2, 25.0f, true);
@ -172,7 +172,7 @@ TEST(etb, initializationNotRedundantTps) {
EtbController dut; EtbController dut;
// Needs pedal for init // Needs pedal for init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
// Not redundant, should fail upon init // Not redundant, should fail upon init
Sensor::setMockValue(SensorType::Tps1, 0.0f, false); Sensor::setMockValue(SensorType::Tps1, 0.0f, false);
@ -180,6 +180,18 @@ TEST(etb, initializationNotRedundantTps) {
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true)); EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
} }
TEST(etb, initializationNotRedundantPedal) {
EtbController dut;
// Init pedal without redundancy
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, false);
// Normal redundant TPS
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
EXPECT_FATAL_ERROR(dut.init(ETB_Throttle1, nullptr, nullptr, nullptr, true));
}
TEST(etb, initializationNoThrottles) { TEST(etb, initializationNoThrottles) {
// This tests the case where you don't want an ETB, and expect everything to go fine // This tests the case where you don't want an ETB, and expect everything to go fine
EtbController duts[2]; EtbController duts[2];
@ -209,7 +221,7 @@ TEST(etb, idlePlumbing) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
engineConfiguration->useETBforIdleControl = true; engineConfiguration->useETBforIdleControl = true;
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
for (int i = 0; i < ETB_COUNT; i++) { for (int i = 0; i < ETB_COUNT; i++) {
engine->etbControllers[i] = &mocks[i]; engine->etbControllers[i] = &mocks[i];
@ -239,36 +251,37 @@ TEST(etb, testSetpointOnlyPedal) {
// Uninitialized ETB must return unexpected (and not deference a null pointer) // Uninitialized ETB must return unexpected (and not deference a null pointer)
EXPECT_EQ(etb.getSetpoint(), unexpected); EXPECT_EQ(etb.getSetpoint(), unexpected);
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true); etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
// Check endpoints and midpoint // Check endpoints and midpoint
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EXPECT_EQ(0, etb.getSetpoint().value_or(-1)); EXPECT_EQ(0, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
EXPECT_EQ(50, etb.getSetpoint().value_or(-1)); EXPECT_EQ(50, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
EXPECT_EQ(100, etb.getSetpoint().value_or(-1)); EXPECT_EQ(100, etb.getSetpoint().value_or(-1));
// Test some floating point pedal/output values // Test some floating point pedal/output values
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.8302f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.8302f, true);
EXPECT_NEAR(50.8302, etb.getSetpoint().value_or(-1), EPS4D); EXPECT_NEAR(50.8302, etb.getSetpoint().value_or(-1), EPS4D);
Sensor::setMockValue(SensorType::AcceleratorPedal, 51.6605f); Sensor::setMockValue(SensorType::AcceleratorPedal, 51.6605f, true);
EXPECT_NEAR(51.6605, etb.getSetpoint().value_or(-1), EPS4D); EXPECT_NEAR(51.6605, etb.getSetpoint().value_or(-1), EPS4D);
// Valid but out of range - should clamp to [0, 100] // Valid but out of range - should clamp to [0, 100]
Sensor::setMockValue(SensorType::AcceleratorPedal, -5); Sensor::setMockValue(SensorType::AcceleratorPedal, -5, true);
EXPECT_EQ(0, etb.getSetpoint().value_or(-1)); EXPECT_EQ(0, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 105); Sensor::setMockValue(SensorType::AcceleratorPedal, 105, true);
EXPECT_EQ(100, etb.getSetpoint().value_or(-1)); EXPECT_EQ(100, etb.getSetpoint().value_or(-1));
// Check that ETB idle does NOT work - it's disabled // Check that ETB idle does NOT work - it's disabled
etb.setIdlePosition(50); etb.setIdlePosition(50);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0, true);
EXPECT_EQ(0, etb.getSetpoint().value_or(-1)); EXPECT_EQ(0, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 20); Sensor::setMockValue(SensorType::AcceleratorPedal, 20, true);
EXPECT_EQ(20, etb.getSetpoint().value_or(-1)); EXPECT_EQ(20, etb.getSetpoint().value_or(-1));
// Test invalid pedal position - should give 0 position // Test invalid pedal position - should give 0 position
@ -283,8 +296,9 @@ TEST(etb, setpointIdle) {
engineConfiguration->useETBforIdleControl = true; engineConfiguration->useETBforIdleControl = true;
engineConfiguration->etbIdleThrottleRange = 0; engineConfiguration->etbIdleThrottleRange = 0;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -298,9 +312,9 @@ TEST(etb, setpointIdle) {
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true); etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
// No idle range, should just pass pedal // No idle range, should just pass pedal
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EXPECT_EQ(0, etb.getSetpoint().value_or(-1)); EXPECT_EQ(0, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
EXPECT_EQ(50, etb.getSetpoint().value_or(-1)); EXPECT_EQ(50, etb.getSetpoint().value_or(-1));
// Idle should now have 10% range // Idle should now have 10% range
@ -308,35 +322,36 @@ TEST(etb, setpointIdle) {
// 50% idle position should increase setpoint by 5% when closed, and 0% when open // 50% idle position should increase setpoint by 5% when closed, and 0% when open
etb.setIdlePosition(50); etb.setIdlePosition(50);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EXPECT_FLOAT_EQ(5, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(5, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
EXPECT_FLOAT_EQ(52.5, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(52.5, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
// 100% setpoint should increase by 10% closed, scaled 0% at wot // 100% setpoint should increase by 10% closed, scaled 0% at wot
etb.setIdlePosition(100); etb.setIdlePosition(100);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 100.0f, true);
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
// 125% setpoint should clamp to 10% increase // 125% setpoint should clamp to 10% increase
etb.setIdlePosition(125); etb.setIdlePosition(125);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(10, etb.getSetpoint().value_or(-1));
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f); Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f, true);
EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1)); EXPECT_FLOAT_EQ(55, etb.getSetpoint().value_or(-1));
} }
TEST(etb, setpointNoPedalMap) { TEST(etb, setpointNoPedalMap) {
EtbController etb; EtbController etb;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
// Don't pass a pedal map // Don't pass a pedal map
etb.init(ETB_Throttle1, nullptr, nullptr, nullptr, true); etb.init(ETB_Throttle1, nullptr, nullptr, nullptr, true);
@ -437,8 +452,9 @@ TEST(etb, setOutputValid) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -456,8 +472,9 @@ TEST(etb, setOutputValid2) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -475,8 +492,9 @@ TEST(etb, setOutputOutOfRangeHigh) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -494,8 +512,9 @@ TEST(etb, setOutputOutOfRangeLow) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -513,8 +532,9 @@ TEST(etb, setOutputPauseControl) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -533,8 +553,9 @@ TEST(etb, setOutputLimpHome) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE); WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
StrictMock<MockMotor> motor; StrictMock<MockMotor> motor;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
INJECT_ENGINE_REFERENCE(&etb); INJECT_ENGINE_REFERENCE(&etb);
@ -555,8 +576,9 @@ TEST(etb, closedLoopPid) {
pid.maxValue = 75; pid.maxValue = 75;
pid.minValue = -60; pid.minValue = -60;
// Must have TPS initialized for ETB setup // Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1, 0.0f, true); Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController etb; EtbController etb;
etb.init(ETB_Throttle1, nullptr, &pid, nullptr, true); etb.init(ETB_Throttle1, nullptr, &pid, nullptr, true);