Etb function cfg: actually read config (#1884)

* two throttles one thread

* look at all this RAM!

* add enum

* switch from index to function

* test fixup

* improve init logic

* remove old vw idle mode bit

* add config

* better spot for it

* use config init values

* handle null controller array

* fatal error testability

* test new init config

* defaults

* fix for default config
This commit is contained in:
Matthew Kennedy 2020-10-18 14:26:38 -07:00 committed by GitHub
parent 89dbcf7faf
commit 44653da2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 13 deletions

View File

@ -828,19 +828,15 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
addConsoleActionI("etb_freq", setEtbFrequency); addConsoleActionI("etb_freq", setEtbFrequency);
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
// If you don't have a pedal we have no business here.
if (Sensor::hasSensor(SensorType::AcceleratorPedalPrimary)) {
engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1;
} else {
engine->etbActualCount = 0;
}
pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins); pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins);
// TODO: remove etbActualCount
engine->etbActualCount = ETB_COUNT;
bool mustHaveEtbConfigured = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary); bool mustHaveEtbConfigured = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
bool anyEtbConfigured = false; bool anyEtbConfigured = false;
for (int i = 0 ; i < engine->etbActualCount; i++) { for (int i = 0 ; i < ETB_COUNT; i++) {
auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX); auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX);
// If this motor is actually set up, init the etb // If this motor is actually set up, init the etb
@ -851,8 +847,7 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
continue; continue;
} }
// TODO: configure per-motor in config so wastegate/VW idle works auto func = CONFIG(etbFunctions[i]);
auto func = i == 0 ? ETB_Throttle1 : ETB_Throttle2;
anyEtbConfigured |= controller->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap); anyEtbConfigured |= controller->init(func, motor, &engineConfiguration->etb, &pedal2tpsMap);
INJECT_ENGINE_REFERENCE(engine->etbControllers[i]); INJECT_ENGINE_REFERENCE(engine->etbControllers[i]);

View File

@ -27,9 +27,34 @@ TEST(etb, initializationNoPedal) {
engine->etbControllers[i] = &mocks[i]; engine->etbControllers[i] = &mocks[i];
} }
// We expect no throttle init stuff to be called - lack of pedal should disable ETB EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, _, _)).WillOnce(Return(false));
EXPECT_CALL(mocks[1], init(ETB_Throttle2, _, _, _)).WillOnce(Return(false));
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); // This shouldn't throw, since no throttles are configured, but no pedal is configured either
EXPECT_NO_FATAL_ERROR(doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE));
}
TEST(etb, initializationMissingThrottle) {
StrictMock<MockEtb> mocks[ETB_COUNT];
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
for (int i = 0; i < ETB_COUNT; i++) {
engine->etbControllers[i] = &mocks[i];
}
engineConfiguration->etbFunctions[0] = ETB_None;
engineConfiguration->etbFunctions[1] = ETB_None;
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _)).WillOnce(Return(false));
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _)).WillOnce(Return(false));
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
// This should throw: a pedal is configured but no throttles
EXPECT_FATAL_ERROR(doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE));
} }
TEST(etb, initializationSingleThrottle) { TEST(etb, initializationSingleThrottle) {
@ -45,10 +70,39 @@ TEST(etb, initializationSingleThrottle) {
Sensor::setMockValue(SensorType::AcceleratorPedal, 0); Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0); Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
engineConfiguration->etbFunctions[1] = ETB_None;
// Expect mock0 to be init as throttle 1, and PID params // Expect mock0 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true)); EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));
// We do not expect throttle #2 to be initialized // Expect mock1 to be init as none
EXPECT_CALL(mocks[1], init(ETB_None, _, _, _)).WillOnce(Return(true));
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
}
TEST(etb, initializationSingleThrottleInSecondSlot) {
StrictMock<MockEtb> mocks[ETB_COUNT];
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
for (int i = 0; i < ETB_COUNT; i++) {
engine->etbControllers[i] = &mocks[i];
}
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 0);
engineConfiguration->etbFunctions[0] = ETB_None;
engineConfiguration->etbFunctions[1] = ETB_Throttle1;
// Expect mock0 to be init as none
EXPECT_CALL(mocks[0], init(ETB_None, _, _, _)).WillOnce(Return(true));
// Expect mock1 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[1], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE); doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
} }
@ -69,6 +123,9 @@ TEST(etb, initializationDualThrottle) {
// The presence of a second TPS indicates dual throttle // The presence of a second TPS indicates dual throttle
Sensor::setMockValue(SensorType::Tps2, 25.0f); Sensor::setMockValue(SensorType::Tps2, 25.0f);
engineConfiguration->etbFunctions[0] = ETB_Throttle1;
engineConfiguration->etbFunctions[1] = ETB_Throttle2;
// Expect mock0 to be init as throttle 1, and PID params // Expect mock0 to be init as throttle 1, and PID params
EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true)); EXPECT_CALL(mocks[0], init(ETB_Throttle1, _, &engineConfiguration->etb, Ne(nullptr))).WillOnce(Return(true));