AE is engine module

This commit is contained in:
Matthew Kennedy 2024-08-02 00:45:54 -04:00 committed by rusefillc
parent 03036afe85
commit cfa7ad9741
10 changed files with 43 additions and 57 deletions

View File

@ -113,7 +113,7 @@ const engine_state_s* getLiveData(size_t) {
template<> template<>
const tps_accel_state_s* getLiveData(size_t) { const tps_accel_state_s* getLiveData(size_t) {
return &engine->tpsAccelEnrichment; return &engine->module<TpsAccelEnrichment>().unmock();
} }
template<> template<>

View File

@ -181,29 +181,21 @@ TpsAccelEnrichment::TpsAccelEnrichment() {
cb.setSize(4); cb.setSize(4);
} }
#if ! EFI_UNIT_TEST void TpsAccelEnrichment::onConfigurationChange(engine_configuration_s const* /*previousConfig*/) {
constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
int length = engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond;
static void setTpsAccelLen(int length) {
if (length < 1) { if (length < 1) {
efiPrintf("setTpsAccelLen: Length should be positive [%d]", length); efiPrintf("setTpsAccelLen: Length should be positive [%d]", length);
return; return;
} }
engine->tpsAccelEnrichment.setLength(length);
setLength(length);
} }
void updateAccelParameters() {
constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
setTpsAccelLen(engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond);
}
#endif /* ! EFI_UNIT_TEST */
void initAccelEnrichment() { void initAccelEnrichment() {
tpsTpsMap.initTable(config->tpsTpsAccelTable, config->tpsTpsAccelToRpmBins, config->tpsTpsAccelFromRpmBins); tpsTpsMap.initTable(config->tpsTpsAccelTable, config->tpsTpsAccelToRpmBins, config->tpsTpsAccelFromRpmBins);
#if ! EFI_UNIT_TEST engine->module<TpsAccelEnrichment>()->onConfigurationChange(nullptr);
updateAccelParameters();
#endif /* ! EFI_UNIT_TEST */
} }

View File

@ -16,10 +16,12 @@
typedef Map3D<TPS_TPS_ACCEL_TABLE, TPS_TPS_ACCEL_TABLE, float, float, float> tps_tps_Map3D_t; typedef Map3D<TPS_TPS_ACCEL_TABLE, TPS_TPS_ACCEL_TABLE, float, float, float> tps_tps_Map3D_t;
class TpsAccelEnrichment : public tps_accel_state_s { class TpsAccelEnrichment : public tps_accel_state_s, public EngineModule {
public: public:
TpsAccelEnrichment(); TpsAccelEnrichment();
void onConfigurationChange(engine_configuration_s const* previousConfig) override;
int getMaxDeltaIndex(); int getMaxDeltaIndex();
float getMaxDelta(); float getMaxDelta();
@ -38,5 +40,3 @@ public:
}; };
void initAccelEnrichment(); void initAccelEnrichment();
void updateAccelParameters();

View File

@ -162,7 +162,7 @@ void Engine::periodicSlowCallback() {
updateSlowSensors(); updateSlowSensors();
checkShutdown(); checkShutdown();
tpsAccelEnrichment.onNewValue(Sensor::getOrZero(SensorType::Tps1)); module<TpsAccelEnrichment>()->onNewValue(Sensor::getOrZero(SensorType::Tps1));
updateVrThresholdPwm(); updateVrThresholdPwm();

View File

@ -167,6 +167,7 @@ public:
#if EFI_BOOST_CONTROL #if EFI_BOOST_CONTROL
BoostController, BoostController,
#endif // EFI_BOOST_CONTROL #endif // EFI_BOOST_CONTROL
TpsAccelEnrichment,
EngineModule // dummy placeholder so the previous entries can all have commas EngineModule // dummy placeholder so the previous entries can all have commas
> engineModules; > engineModules;
@ -218,8 +219,6 @@ public:
void setConfig(); void setConfig();
LocalVersionHolder versionForConfigurationListeners;
AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2]; AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2];
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
@ -280,8 +279,6 @@ public:
*/ */
int globalConfigurationVersion = 0; int globalConfigurationVersion = 0;
TpsAccelEnrichment tpsAccelEnrichment;
#if EFI_SHAFT_POSITION_INPUT #if EFI_SHAFT_POSITION_INPUT
TriggerCentral triggerCentral; TriggerCentral triggerCentral;
#endif // EFI_SHAFT_POSITION_INPUT #endif // EFI_SHAFT_POSITION_INPUT

View File

@ -223,7 +223,7 @@ enum class engine_type_e : uint16_t {
*/ */
typedef enum __attribute__ ((__packed__)) { typedef enum __attribute__ ((__packed__)) {
DBG_0 = 0, DBG_0 = 0,
DBG_TPS_ACCEL = 1, DBG_1 = 1,
DBG_2 = 2, DBG_2 = 2,
DBG_STEPPER_IDLE_CONTROL = 3, DBG_STEPPER_IDLE_CONTROL = 3,
DBG_EL_ACCEL = 4, DBG_EL_ACCEL = 4,

View File

@ -328,7 +328,7 @@ float getInjectionMass(int rpm) {
engine->module<InjectorModelSecondary>()->prepare(); engine->module<InjectorModelSecondary>()->prepare();
} }
float tpsAccelEnrich = engine->tpsAccelEnrichment.getTpsEnrichment(); float tpsAccelEnrich = engine->module<TpsAccelEnrichment>()->getTpsEnrichment();
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0); efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !std::isnan(tpsAccelEnrich), "NaN tpsAccelEnrich", 0);
engine->engineState.tpsAccelEnrich = tpsAccelEnrich; engine->engineState.tpsAccelEnrich = tpsAccelEnrich;

View File

@ -173,7 +173,8 @@ class EngineStateBlinkingTask : public PeriodicTimerController {
static EngineStateBlinkingTask engineStateBlinkingTask; static EngineStateBlinkingTask engineStateBlinkingTask;
static void resetAccel() { static void resetAccel() {
engine->tpsAccelEnrichment.resetAE(); engine->module<TpsAccelEnrichment>()->resetAE();
#if EFI_ENGINE_CONTROL #if EFI_ENGINE_CONTROL
for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++) for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++)
{ {
@ -192,10 +193,6 @@ static void doPeriodicSlowCallback() {
if (engine->rpmCalculator.isStopped()) { if (engine->rpmCalculator.isStopped()) {
resetAccel(); resetAccel();
} }
if (engine->versionForConfigurationListeners.isOld(engine->getGlobalConfigurationVersion())) {
updateAccelParameters();
}
#endif /* EFI_SHAFT_POSITION_INPUT */ #endif /* EFI_SHAFT_POSITION_INPUT */
engine->periodicSlowCallback(); engine->periodicSlowCallback();

View File

@ -882,7 +882,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
#endif /* EFI_CDM_INTEGRATION */ #endif /* EFI_CDM_INTEGRATION */
if (engine->rpmCalculator.getCachedRpm() > 0 && triggerIndexForListeners == 0) { if (engine->rpmCalculator.getCachedRpm() > 0 && triggerIndexForListeners == 0) {
engine->tpsAccelEnrichment.onEngineCycleTps(); engine->module<TpsAccelEnrichment>()->onEngineCycleTps();
} }
// Handle ignition and injection // Handle ignition and injection

View File

@ -20,23 +20,23 @@ TEST(fuel, testTpsAccelEnrichmentMath) {
engine->rpmCalculator.setRpmValue(600); engine->rpmCalculator.setRpmValue(600);
engine->periodicFastCallback(); engine->periodicFastCallback();
engine->tpsAccelEnrichment.setLength(4); engine->module<TpsAccelEnrichment>()->setLength(4);
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta"; ASSERT_EQ( 0, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta";
engine->tpsAccelEnrichment.onNewValue(10); engine->module<TpsAccelEnrichment>()->onNewValue(10);
ASSERT_EQ( 10, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta#1"; ASSERT_EQ( 10, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta#1";
engine->tpsAccelEnrichment.onNewValue(30); engine->module<TpsAccelEnrichment>()->onNewValue(30);
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta#2"; ASSERT_EQ( 20, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta#2";
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta#3"; ASSERT_EQ( 20, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta#3";
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
ASSERT_EQ( 20, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta#4"; ASSERT_EQ( 20, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta#4";
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta#5"; ASSERT_EQ( 0, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta#5";
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
ASSERT_EQ( 0, engine->tpsAccelEnrichment.getMaxDelta()) << "maxDelta"; ASSERT_EQ( 0, engine->module<TpsAccelEnrichment>()->getMaxDelta()) << "maxDelta";
} }
TEST(fuel, testTpsAccelEnrichmentScheduling) { TEST(fuel, testTpsAccelEnrichmentScheduling) {
@ -58,25 +58,25 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */); eth.fireTriggerEvents2(/* count */ 4, 25 /* ms */);
ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM"; ASSERT_EQ( 1200, Sensor::getOrZero(SensorType::Rpm)) << "RPM";
int expectedInvocationCounter = 1; int expectedInvocationCounter = 1;
ASSERT_EQ(expectedInvocationCounter, engine->tpsAccelEnrichment.onUpdateInvocationCounter); ASSERT_EQ(expectedInvocationCounter, engine->module<TpsAccelEnrichment>()->onUpdateInvocationCounter);
Sensor::setMockValue(SensorType::Tps1, 70); Sensor::setMockValue(SensorType::Tps1, 70);
eth.fireTriggerEvents2(/* count */ 1, 25 /* ms */); eth.fireTriggerEvents2(/* count */ 1, 25 /* ms */);
float expectedAEValue = 7; float expectedAEValue = 7;
// it does not matter how many times we invoke 'getTpsEnrichment' - state does not change // it does not matter how many times we invoke 'getTpsEnrichment' - state does not change
for (int i = 0; i <20;i++) { for (int i = 0; i < 20; i++) {
ASSERT_NEAR(expectedAEValue, engine->tpsAccelEnrichment.getTpsEnrichment(), EPS4D); ASSERT_NEAR(expectedAEValue, engine->module<TpsAccelEnrichment>()->getTpsEnrichment(), EPS4D);
} }
expectedInvocationCounter++; expectedInvocationCounter++;
ASSERT_EQ(expectedInvocationCounter, engine->tpsAccelEnrichment.onUpdateInvocationCounter); ASSERT_EQ(expectedInvocationCounter, engine->module<TpsAccelEnrichment>()->onUpdateInvocationCounter);
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
eth.engine.periodicFastCallback(); eth.engine.periodicFastCallback();
ASSERT_EQ(expectedInvocationCounter, engine->tpsAccelEnrichment.onUpdateInvocationCounter); ASSERT_EQ(expectedInvocationCounter, engine->module<TpsAccelEnrichment>()->onUpdateInvocationCounter);
} }
static void doFractionalTpsIteration(int period, int divisor, int numCycles, std::vector<floatms_t> &tpsEnrich) { static void doFractionalTpsIteration(int period, int divisor, int numCycles, std::vector<floatms_t> &tpsEnrich) {
@ -85,12 +85,12 @@ static void doFractionalTpsIteration(int period, int divisor, int numCycles, std
// split into 2 portions // split into 2 portions
engineConfiguration->tpsAccelFractionDivisor = divisor; engineConfiguration->tpsAccelFractionDivisor = divisor;
engine->tpsAccelEnrichment.resetAE(); engine->module<TpsAccelEnrichment>()->resetAE();
engine->tpsAccelEnrichment.onNewValue(0); engine->module<TpsAccelEnrichment>()->onNewValue(0);
for (int i = 0; i < numCycles; i++) { for (int i = 0; i < numCycles; i++) {
engine->tpsAccelEnrichment.onNewValue(10); engine->module<TpsAccelEnrichment>()->onNewValue(10);
engine->tpsAccelEnrichment.onEngineCycleTps(); engine->module<TpsAccelEnrichment>()->onEngineCycleTps();
tpsEnrich[i] = engine->tpsAccelEnrichment.getTpsEnrichment(); tpsEnrich[i] = engine->module<TpsAccelEnrichment>()->getTpsEnrichment();
} }
} }
@ -116,7 +116,7 @@ TEST(fuel, testAccelEnrichmentFractionalTps) {
engine->rpmCalculator.setRpmValue(600); engine->rpmCalculator.setRpmValue(600);
engine->periodicFastCallback(); engine->periodicFastCallback();
engine->tpsAccelEnrichment.setLength(2); engine->module<TpsAccelEnrichment>()->setLength(2);
const int numCycles = 4; const int numCycles = 4;