2022-11-29 08:42:09 -08:00
|
|
|
#include "pch.h"
|
|
|
|
#include "init.h"
|
|
|
|
#include "electronic_throttle_impl.h"
|
2022-11-29 11:02:44 -08:00
|
|
|
#include "live_data.h"
|
2022-11-29 08:42:09 -08:00
|
|
|
|
2022-11-29 17:11:34 -08:00
|
|
|
static EtbController * initEtbIntegratedTest() {
|
2022-11-29 11:59:08 -08:00
|
|
|
etbPidReset(); // ETB controlles are global shared instances :(
|
2022-11-29 08:42:09 -08:00
|
|
|
|
|
|
|
engineConfiguration->tps1_1AdcChannel = EFI_ADC_3;
|
|
|
|
engineConfiguration->tps1_2AdcChannel = EFI_ADC_3;
|
|
|
|
|
|
|
|
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_3;
|
|
|
|
engineConfiguration->throttlePedalPositionSecondAdcChannel = EFI_ADC_3;
|
|
|
|
|
|
|
|
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 25.0f, true);
|
|
|
|
|
|
|
|
initTps();
|
|
|
|
doInitElectronicThrottle();
|
2022-11-30 17:08:19 -08:00
|
|
|
|
2023-02-12 13:49:12 -08:00
|
|
|
engine->etbControllers[0]->setIdlePosition(0);
|
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
return (EtbController*)engine->etbControllers[0];
|
2022-11-29 17:11:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(etb, integrated) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
|
2022-11-29 17:11:34 -08:00
|
|
|
EtbController *etb = initEtbIntegratedTest();
|
2022-11-29 08:42:09 -08:00
|
|
|
|
2022-11-29 17:36:03 -08:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalPrimary, 40);
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedalSecondary, 40);
|
|
|
|
|
2022-11-29 08:42:09 -08:00
|
|
|
etb->update();
|
|
|
|
|
|
|
|
ASSERT_EQ(engine->outputChannels.etbTarget, 40);
|
2022-11-30 12:25:50 -08:00
|
|
|
ASSERT_NEAR(etb->prevOutput, 120.363, EPS3D);
|
|
|
|
ASSERT_NEAR(etb->etbDutyAverage, 60.1813, EPS3D);
|
2022-11-29 08:42:09 -08:00
|
|
|
|
2022-11-29 11:02:44 -08:00
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 10, true);
|
|
|
|
etb->update();
|
2022-11-30 16:48:08 -08:00
|
|
|
ASSERT_NEAR(etb->etbDutyAverage, 70.0741, EPS3D);
|
|
|
|
ASSERT_NEAR(etb->etbDutyRateOfChange, 130.2554, EPS3D);
|
2022-11-29 11:02:44 -08:00
|
|
|
|
|
|
|
float destination;
|
|
|
|
int offset = ELECTRONIC_THROTTLE_BASE_ADDRESS + offsetof(electronic_throttle_s, etbDutyRateOfChange);
|
|
|
|
copyRange((uint8_t*)&destination, getLiveDataFragments(), offset, sizeof(destination));
|
2022-11-30 16:48:08 -08:00
|
|
|
ASSERT_NEAR(destination, 130.2554, EPS3D);
|
2022-11-29 08:42:09 -08:00
|
|
|
}
|
2022-11-29 17:11:34 -08:00
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
extern int timeNowUs;
|
2023-04-11 13:03:53 -07:00
|
|
|
extern WarningCodeState unitTestWarningCodeState;
|
2022-11-30 19:20:09 -08:00
|
|
|
|
|
|
|
TEST(etb, intermittentTps) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
|
2022-11-29 17:11:34 -08:00
|
|
|
EtbController *etb = initEtbIntegratedTest();
|
2023-04-11 15:33:15 -07:00
|
|
|
warningBuffer_t &recentWarnings = unitTestWarningCodeState.recentWarnings;
|
|
|
|
recentWarnings.clear();
|
2022-11-29 17:11:34 -08:00
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
// Tell the sensor checker that the ignition is on
|
|
|
|
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
|
|
|
engine->module<SensorChecker>()->onSlowCallback();
|
2023-04-11 15:33:15 -07:00
|
|
|
timeNowUs += MS2US(1000);
|
2022-11-30 19:20:09 -08:00
|
|
|
engine->module<SensorChecker>()->onSlowCallback();
|
2023-04-11 17:01:01 -07:00
|
|
|
// todo: fix me https://github.com/rusefi/rusefi/issues/5233
|
|
|
|
// EXPECT_EQ( 3, recentWarnings.getCount()) << "intermittentTps";
|
|
|
|
EXPECT_TRUE( recentWarnings.getCount() > 0) << "intermittentTps";
|
2022-11-30 19:20:09 -08:00
|
|
|
|
|
|
|
ASSERT_TRUE(engine->module<SensorChecker>()->analogSensorsShouldWork());
|
|
|
|
|
2022-11-29 17:11:34 -08:00
|
|
|
ASSERT_FALSE(isTps1Error());
|
2022-11-29 17:36:03 -08:00
|
|
|
|
|
|
|
etb->update();
|
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
EXPECT_EQ(0, etb->etbTpsErrorCounter);
|
|
|
|
EXPECT_EQ(0, etb->etbErrorCode);
|
|
|
|
|
|
|
|
int badCount = 0;
|
|
|
|
|
|
|
|
// Do some bad/good/bad/good cycles, make sure count keeps up
|
|
|
|
for (size_t i = 0; i < 50; i++) {
|
|
|
|
Sensor::setInvalidMockValue(SensorType::Tps1);
|
|
|
|
ASSERT_TRUE(isTps1Error());
|
|
|
|
etb->update();
|
2022-11-29 17:36:03 -08:00
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
badCount++;
|
|
|
|
EXPECT_EQ(badCount, etb->etbTpsErrorCounter);
|
|
|
|
EXPECT_EQ(0, etb->etbErrorCode);
|
2022-11-29 17:11:34 -08:00
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
Sensor::setMockValue(SensorType::Tps1, 20);
|
|
|
|
ASSERT_FALSE(isTps1Error());
|
|
|
|
etb->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 51st bad TPS should set etbErrorCode
|
2022-11-29 17:36:03 -08:00
|
|
|
Sensor::setInvalidMockValue(SensorType::Tps1);
|
2022-11-30 19:20:09 -08:00
|
|
|
ASSERT_TRUE(isTps1Error());
|
2022-11-29 17:11:34 -08:00
|
|
|
etb->update();
|
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
EXPECT_NE(0, etb->etbErrorCode);
|
2023-04-11 15:33:15 -07:00
|
|
|
|
2023-04-11 17:01:01 -07:00
|
|
|
// todo: fix me https://github.com/rusefi/rusefi/issues/5233
|
|
|
|
// EXPECT_EQ( 3, recentWarnings.getCount()) << "intermittentTps";
|
|
|
|
EXPECT_TRUE( recentWarnings.getCount() > 0) << "intermittentTps";
|
|
|
|
// todo: fix me https://github.com/rusefi/rusefi/issues/5233
|
|
|
|
// EXPECT_EQ(OBD_PPS_Correlation, recentWarnings.get(0).Code);
|
|
|
|
// EXPECT_EQ(OBD_TPS1_Primary_Timeout, recentWarnings.get(1).Code);
|
|
|
|
// EXPECT_EQ(OBD_PPS_Primary_Timeout, recentWarnings.get(2).Code);
|
2022-11-29 17:11:34 -08:00
|
|
|
}
|
2022-11-30 17:08:19 -08:00
|
|
|
|
|
|
|
TEST(etb, intermittentPps) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
|
2022-11-30 19:20:09 -08:00
|
|
|
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 10, true);
|
2022-11-30 17:08:19 -08:00
|
|
|
EtbController *etb = initEtbIntegratedTest();
|
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
// Tell the sensor checker that the ignition is on
|
|
|
|
engine->module<SensorChecker>()->onIgnitionStateChanged(true);
|
|
|
|
engine->module<SensorChecker>()->onSlowCallback();
|
|
|
|
timeNowUs += 10e6;
|
|
|
|
engine->module<SensorChecker>()->onSlowCallback();
|
|
|
|
|
|
|
|
ASSERT_TRUE(engine->module<SensorChecker>()->analogSensorsShouldWork());
|
|
|
|
|
2022-11-30 17:08:19 -08:00
|
|
|
ASSERT_FALSE(isPedalError());
|
2022-11-30 19:20:09 -08:00
|
|
|
|
2022-11-30 17:08:19 -08:00
|
|
|
etb->update();
|
|
|
|
|
2022-11-30 19:20:09 -08:00
|
|
|
EXPECT_EQ(0, etb->etbPpsErrorCounter);
|
|
|
|
EXPECT_EQ(0, etb->etbErrorCode);
|
|
|
|
|
|
|
|
int badCount = 0;
|
|
|
|
|
|
|
|
// Do some bad/good/bad/good cycles, make sure count keeps up
|
|
|
|
for (size_t i = 0; i < 50; i++) {
|
|
|
|
Sensor::setInvalidMockValue(SensorType::AcceleratorPedal);
|
|
|
|
ASSERT_TRUE(isPedalError());
|
|
|
|
etb->update();
|
|
|
|
|
|
|
|
badCount++;
|
|
|
|
EXPECT_EQ(badCount, etb->etbPpsErrorCounter);
|
|
|
|
EXPECT_EQ(0, etb->etbErrorCode);
|
|
|
|
|
|
|
|
Sensor::setMockValue(SensorType::AcceleratorPedal, 20);
|
|
|
|
ASSERT_FALSE(isPedalError());
|
|
|
|
etb->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 51st bad TPS should set etbErrorCode
|
2022-11-30 17:08:19 -08:00
|
|
|
Sensor::setInvalidMockValue(SensorType::AcceleratorPedal);
|
2022-11-30 19:20:09 -08:00
|
|
|
ASSERT_TRUE(isPedalError());
|
2022-11-30 17:08:19 -08:00
|
|
|
etb->update();
|
2022-11-30 19:20:09 -08:00
|
|
|
EXPECT_NE(0, etb->etbErrorCode);
|
2022-11-30 17:08:19 -08:00
|
|
|
}
|
2023-03-01 11:26:24 -08:00
|
|
|
|
|
|
|
TEST(etb, sentTpsIntegrated) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
|
2023-03-01 11:26:24 -08:00
|
|
|
|
|
|
|
engineConfiguration->sentInputPins[0] = Gpio::B3;
|
|
|
|
engineConfiguration->sentEtbType = SentEtbType::GM_TYPE_1;
|
|
|
|
|
|
|
|
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_3;
|
|
|
|
engineConfiguration->throttlePedalPositionSecondAdcChannel = EFI_ADC_3;
|
|
|
|
|
|
|
|
Sensor::setMockValue(SensorType::Tps1, 25.0f, true);
|
|
|
|
|
|
|
|
initTps();
|
|
|
|
doInitElectronicThrottle();
|
|
|
|
}
|
2023-03-01 14:20:34 -08:00
|
|
|
|
|
|
|
TEST(etb, sentTpsIntegratedDecode) {
|
2023-05-31 22:31:28 -07:00
|
|
|
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // we have a destructor so cannot move EngineTestHelper into utility method
|
2023-03-01 14:20:34 -08:00
|
|
|
|
|
|
|
engineConfiguration->sentEtbType = SentEtbType::GM_TYPE_1;
|
|
|
|
|
|
|
|
ASSERT_NEAR(20.246, decodeTpsSentValue(3000), EPS2D);
|
|
|
|
|
|
|
|
engineConfiguration->sentEtbType = SentEtbType::CUSTOM;
|
|
|
|
engineConfiguration->customSentTpsMin = 5000;
|
|
|
|
engineConfiguration->customSentTpsMax = 1000;
|
|
|
|
ASSERT_NEAR(75, decodeTpsSentValue(2000), EPS2D);
|
|
|
|
}
|