AE is engine module

This commit is contained in:
Matthew Kennedy 2024-08-01 21:45:54 -07:00
parent 2bfa57d7d7
commit f3045af367
11 changed files with 38 additions and 69 deletions

View File

@ -97,7 +97,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

@ -608,9 +608,6 @@ void updateTunerStudioState() {
#endif #endif
switch (engineConfiguration->debugMode) { switch (engineConfiguration->debugMode) {
case DBG_TPS_ACCEL:
tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize();
break;
case DBG_SR5_PROTOCOL: { case DBG_SR5_PROTOCOL: {
const int _10_6 = 100000; const int _10_6 = 100000;
tsOutputChannels->debugIntField1 = tsState.textCommandCounter * _10_6 + tsState.totalCounter; tsOutputChannels->debugIntField1 = tsState.textCommandCounter * _10_6 + tsState.totalCounter;

View File

@ -70,19 +70,6 @@ floatms_t TpsAccelEnrichment::getTpsEnrichment() {
resetFractionValues(); resetFractionValues();
} }
#if EFI_TUNER_STUDIO
if (engineConfiguration->debugMode == DBG_TPS_ACCEL) {
engine->outputChannels.debugFloatField1 = tpsFrom;
engine->outputChannels.debugFloatField2 = tpsTo;
engine->outputChannels.debugFloatField3 = valueFromTable;
engine->outputChannels.debugFloatField4 = extraFuel;
engine->outputChannels.debugFloatField5 = accumulatedValue;
engine->outputChannels.debugFloatField6 = maxExtraPerPeriod;
engine->outputChannels.debugFloatField7 = maxInjectedPerPeriod;
engine->outputChannels.debugIntField1 = cycleCnt;
}
#endif /* EFI_TUNER_STUDIO */
float mult = interpolate2d(rpm, config->tpsTspCorrValuesBins, float mult = interpolate2d(rpm, config->tpsTspCorrValuesBins,
config->tpsTspCorrValues); config->tpsTspCorrValues);
if (mult != 0 && (mult < 0.01 || mult > 100)) { if (mult != 0 && (mult < 0.01 || mult > 100)) {
@ -193,9 +180,7 @@ TpsAccelEnrichment::TpsAccelEnrichment() {
cb.setSize(4); cb.setSize(4);
} }
#if ! EFI_UNIT_TEST void TpsAccelEnrichment::onConfigurationChange(engine_configuration_s const* /*previousConfig*/) {
void updateAccelParameters() {
constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f; constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
int length = engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond; int length = engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond;
@ -203,18 +188,12 @@ void updateAccelParameters() {
length = 1; length = 1;
} }
engine->tpsAccelEnrichment.setLength(length); setLength(length);
} }
#endif /* ! EFI_UNIT_TEST */
void initAccelEnrichment() { void initAccelEnrichment() {
tpsTpsMap.init(config->tpsTpsAccelTable, config->tpsTpsAccelFromRpmBins, config->tpsTpsAccelToRpmBins); tpsTpsMap.init(config->tpsTpsAccelTable, config->tpsTpsAccelFromRpmBins, config->tpsTpsAccelToRpmBins);
#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

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

View File

@ -174,6 +174,7 @@ public:
BoostController, BoostController,
#endif // EFI_BOOST_CONTROL #endif // EFI_BOOST_CONTROL
LedBlinkingTask, LedBlinkingTask,
TpsAccelEnrichment,
#include "modules_list_generated.h" #include "modules_list_generated.h"
@ -220,8 +221,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
@ -272,8 +271,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

@ -227,7 +227,7 @@ enum class engine_type_e : uint32_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

@ -324,7 +324,7 @@ float getInjectionMass(int rpm) {
engine->module<InjectorModelSecondary>()->prepare(); engine->module<InjectorModelSecondary>()->prepare();
} }
floatms_t tpsAccelEnrich = engine->tpsAccelEnrichment.getTpsEnrichment(); floatms_t 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

@ -131,7 +131,7 @@ private:
static PeriodicFastController fastController; static PeriodicFastController fastController;
static void resetAccel() { static void resetAccel() {
engine->tpsAccelEnrichment.resetAE(); engine->module<TpsAccelEnrichment>()->resetAE();
for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++) for (size_t i = 0; i < efi::size(engine->injectionEvents.elements); i++)
{ {
@ -163,10 +163,6 @@ static void doPeriodicSlowCallback() {
resetAccel(); resetAccel();
} }
if (engine->versionForConfigurationListeners.isOld(engine->getGlobalConfigurationVersion())) {
updateAccelParameters();
}
engine->periodicSlowCallback(); engine->periodicSlowCallback();
#else /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */ #else /* if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
#if EFI_INTERNAL_FLASH #if EFI_INTERNAL_FLASH

View File

@ -671,7 +671,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
expectedNextPhase = expectNextPhase; expectedNextPhase = expectNextPhase;
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,7 +58,7 @@ 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 */);
@ -66,17 +66,17 @@ TEST(fuel, testTpsAccelEnrichmentScheduling) {
float expectedAEValue = 1.4; float expectedAEValue = 1.4;
// 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;