rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
TpsAccelEnrichment Class Reference

#include <accel_enrichment.h>

Inheritance diagram for TpsAccelEnrichment:
Inheritance graph
[legend]
Collaboration diagram for TpsAccelEnrichment:
Collaboration graph
[legend]

Public Member Functions

 TpsAccelEnrichment ()
 
void onConfigurationChange (engine_configuration_s const *previousConfig) override
 
bool isAccelEventTriggered ()
 
int getMaxDeltaIndex ()
 
float getMaxDelta ()
 
void setLength (int length)
 
void onNewValue (float currentValue)
 
floatms_t getTpsEnrichment ()
 
void onEngineCycleTps ()
 
void resetFractionValues ()
 
void resetAE ()
 
float getTimeSinceAcell () const
 
- Public Member Functions inherited from EngineModule
virtual void initNoConfiguration ()
 
virtual void setDefaultConfiguration ()
 
virtual void onSlowCallback ()
 
virtual void onFastCallback ()
 
virtual void onEngineStop ()
 
virtual void onIgnitionStateChanged (bool)
 
virtual bool needsDelayedShutoff ()
 
virtual void onEnginePhase (float, efitick_t, angle_t, angle_t)
 

Data Fields

bool m_accelEventJustOccurred = false
 
Timer m_timeSinceAccel
 
cyclic_buffer< floatcb
 
int onUpdateInvocationCounter = 0
 
- Data Fields inherited from tps_accel_state_s
percent_t tpsFrom = (percent_t)0
 
percent_t tpsTo = (percent_t)0
 
percent_t deltaTps = (percent_t)0
 
floatms_t extraFuel = (floatms_t)0
 
float valueFromTable = (float)0
 
bool isAboveAccelThreshold: 1 {}
 
bool isBelowDecelThreshold: 1 {}
 
bool isTimeToResetAccumulator: 1 {}
 
bool isFractionalEnrichment: 1 {}
 
bool belowEpsilon: 1 {}
 
bool tooShort: 1 {}
 
bool unusedBit_11_6: 1 {}
 
bool unusedBit_11_7: 1 {}
 
bool unusedBit_11_8: 1 {}
 
bool unusedBit_11_9: 1 {}
 
bool unusedBit_11_10: 1 {}
 
bool unusedBit_11_11: 1 {}
 
bool unusedBit_11_12: 1 {}
 
bool unusedBit_11_13: 1 {}
 
bool unusedBit_11_14: 1 {}
 
bool unusedBit_11_15: 1 {}
 
bool unusedBit_11_16: 1 {}
 
bool unusedBit_11_17: 1 {}
 
bool unusedBit_11_18: 1 {}
 
bool unusedBit_11_19: 1 {}
 
bool unusedBit_11_20: 1 {}
 
bool unusedBit_11_21: 1 {}
 
bool unusedBit_11_22: 1 {}
 
bool unusedBit_11_23: 1 {}
 
bool unusedBit_11_24: 1 {}
 
bool unusedBit_11_25: 1 {}
 
bool unusedBit_11_26: 1 {}
 
bool unusedBit_11_27: 1 {}
 
bool unusedBit_11_28: 1 {}
 
bool unusedBit_11_29: 1 {}
 
bool unusedBit_11_30: 1 {}
 
bool unusedBit_11_31: 1 {}
 
float fractionalInjFuel = (float)0
 
floatms_t accumulatedValue = (floatms_t)0
 
floatms_t maxExtraPerCycle = (floatms_t)0
 
floatms_t maxExtraPerPeriod = (floatms_t)0
 
floatms_t maxInjectedPerPeriod = (floatms_t)0
 
int cycleCnt = (int)0
 

Detailed Description

Definition at line 19 of file accel_enrichment.h.

Constructor & Destructor Documentation

◆ TpsAccelEnrichment()

TpsAccelEnrichment::TpsAccelEnrichment ( )

Definition at line 209 of file accel_enrichment.cpp.

209 {
210 resetAE();
211 cb.setSize(4);
212}
cyclic_buffer< float > cb
Here is the call graph for this function:

Member Function Documentation

◆ getMaxDelta()

float TpsAccelEnrichment::getMaxDelta ( )

Definition at line 156 of file accel_enrichment.cpp.

156 {
157 int index = getMaxDeltaIndex();
158
159 return (cb.get(index) - (cb.get(index - 1)));
160}
Here is the call graph for this function:

◆ getMaxDeltaIndex()

int TpsAccelEnrichment::getMaxDeltaIndex ( )

Definition at line 132 of file accel_enrichment.cpp.

132 {
133 int len = minI(cb.getSize(), cb.getCount());
134 tooShort = len < 2;
135 if (tooShort) {
136 return 0;
137 }
138 int ci = cb.currentIndex - 1;
139 float maxValue = cb.get(ci) - cb.get(ci - 1);
140 int resultIndex = ci;
141
142 // todo: 'get' method is maybe a bit heavy because of the branching
143 // todo: this could be optimized with some careful magic
144
145 for (int i = 1; i<len - 1;i++) {
146 float v = cb.get(ci - i) - cb.get(ci - i - 1);
147 if (v > maxValue) {
148 maxValue = v;
149 resultIndex = ci - i;
150 }
151 }
152
153 return resultIndex;
154}

Referenced by getMaxDelta(), and onNewValue().

Here is the caller graph for this function:

◆ getTimeSinceAcell()

float TpsAccelEnrichment::getTimeSinceAcell ( ) const

Definition at line 226 of file accel_enrichment.cpp.

226 {
227 return m_timeSinceAccel.getElapsedSeconds();
228}

◆ getTpsEnrichment()

float TpsAccelEnrichment::getTpsEnrichment ( )
Returns
Extra fuel squirt duration for TPS acceleration

Definition at line 30 of file accel_enrichment.cpp.

30 {
32
33 // If predictive MAP mode is active, the old "adder" logic is disabled.
34 if (engineConfiguration->accelEnrichmentMode == AE_MODE_PREDICTIVE_MAP) {
35 return 0;
36 }
37
39 // If disabled, return 0.
40 return 0;
41 }
42
43#if EFI_TUNER_STUDIO
44 if (isTuningVeNow()) {
45 return 0;
46 }
47#endif
48
50 if (rpm < engineConfiguration->cranking.rpm) {
51 return 0;
52 }
53
55 valueFromTable = interpolate3d(config->tpsTpsAccelTable,
59 m_timeSinceAccel.reset();
60 } else if (isBelowDecelThreshold) {
62 m_timeSinceAccel.reset();
63 } else {
64 extraFuel = 0;
65 }
66
67 // Fractional enrichment (fuel portions are accumulated and split between several engine cycles.
68 // This is a crude imitation of carburetor's acceleration pump.
71 // make sure both values are non-zero
72 float periodF = std::max<int>(engineConfiguration->tpsAccelFractionPeriod, 1);
73 float divisor = std::max(engineConfiguration->tpsAccelFractionDivisor, 1.0f);
74
75 // if current extra fuel portion is not "strong" enough, then we keep up the "pump pressure" with the accumulated portion
76 floatms_t maxExtraFuel = std::max(extraFuel, accumulatedValue);
77 // use only a fixed fraction of the accumulated portion
78 fractionalInjFuel = maxExtraFuel / divisor;
79
80 // update max counters
83
84 // evenly split it between several engine cycles
85 extraFuel = fractionalInjFuel / periodF;
86 } else {
88 }
89
90 float mult = interpolate2d(rpm, config->tpsTspCorrValuesBins,
92 if (mult != 0 && (mult < 0.01 || mult > 100)) {
93 mult = 1;
94 }
95
96 return extraFuel * mult;
97}
static float getOrZero(SensorType type)
Definition sensor.h:83
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
@ GetTpsEnrichment
float floatms_t
float tpsTpsAccelTable[TPS_TPS_ACCEL_TABLE][TPS_TPS_ACCEL_TABLE]
scaled_channel< uint8_t, 1, 50 > tpsTspCorrValuesBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
scaled_channel< uint8_t, 50, 1 > tpsTspCorrValues[TPS_TPS_ACCEL_CLT_CORR_TABLE]
bool isTuningVeNow()
Here is the call graph for this function:

◆ isAccelEventTriggered()

bool TpsAccelEnrichment::isAccelEventTriggered ( )

Definition at line 201 of file accel_enrichment.cpp.

201 {
202 // Read the flag
203 bool result = m_accelEventJustOccurred;
204 // Reset it so we only fire once per event
206 return result;
207}

Referenced by SpeedDensityAirmass::getPredictiveMap().

Here is the caller graph for this function:

◆ onConfigurationChange()

void TpsAccelEnrichment::onConfigurationChange ( engine_configuration_s const *  previousConfig)
overridevirtual

Reimplemented from EngineModule.

Definition at line 214 of file accel_enrichment.cpp.

214 {
215 constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
216 int length = engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond;
217
218 if (length < 1) {
219 efiPrintf("setTpsAccelLen: Length should be positive [%d]", length);
220 return;
221 }
222
223 setLength(length);
224}
void setLength(int length)
Here is the call graph for this function:

◆ onEngineCycleTps()

void TpsAccelEnrichment::onEngineCycleTps ( )

Definition at line 99 of file accel_enrichment.cpp.

99 {
100 // we update values in handleFuel() directly by calling onNewValue()
101
103
104 // we used some extra fuel during the current cycle, so we "charge" our "acceleration pump" with it
109
110 // update the accumulated value every 'Period' engine cycles
114
115 // we've injected this portion during the cycle, so we set what's left for the next cycle
118
119 // it's an infinitely convergent series, so we set a limit at some point
120 // (also make sure that accumulatedValue is positive, for safety)
121 static const floatms_t smallEpsilon = 0.001f;
122 belowEpsilon = accumulatedValue < smallEpsilon;
123 if (belowEpsilon) {
125 }
126
127 // reset the counter
129 }
130}

◆ onNewValue()

void TpsAccelEnrichment::onNewValue ( float  currentValue)

Definition at line 179 of file accel_enrichment.cpp.

179 {
180 // Push new value in to the history buffer
181 cb.add(currentValue);
182
183 // Update deltas
184 int maxDeltaIndex = getMaxDeltaIndex();
185 tpsFrom = cb.get(maxDeltaIndex - 1);
186 tpsTo = cb.get(maxDeltaIndex);
188
189 // Update threshold detection
191
192 // If an acceleration event just happened, latch the flag so it can be read once.
195 }
196
197 // TODO: can deltaTps actually be negative? Will this ever trigger?
199}
Here is the call graph for this function:

◆ resetAE()

void TpsAccelEnrichment::resetAE ( )

Definition at line 162 of file accel_enrichment.cpp.

162 {
163 cb.clear();
165}

Referenced by TpsAccelEnrichment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetFractionValues()

void TpsAccelEnrichment::resetFractionValues ( )

Definition at line 167 of file accel_enrichment.cpp.

167 {
172 cycleCnt = 0;
173}

Referenced by getTpsEnrichment(), and resetAE().

Here is the caller graph for this function:

◆ setLength()

void TpsAccelEnrichment::setLength ( int  length)

Definition at line 175 of file accel_enrichment.cpp.

175 {
176 cb.setSize(length);
177}

Referenced by onConfigurationChange().

Here is the caller graph for this function:

Field Documentation

◆ cb

cyclic_buffer<float> TpsAccelEnrichment::cb

◆ m_accelEventJustOccurred

bool TpsAccelEnrichment::m_accelEventJustOccurred = false

Definition at line 25 of file accel_enrichment.h.

Referenced by isAccelEventTriggered(), and onNewValue().

◆ m_timeSinceAccel

Timer TpsAccelEnrichment::m_timeSinceAccel

Definition at line 31 of file accel_enrichment.h.

Referenced by getTimeSinceAcell(), and getTpsEnrichment().

◆ onUpdateInvocationCounter

int TpsAccelEnrichment::onUpdateInvocationCounter = 0

Definition at line 41 of file accel_enrichment.h.

Referenced by onEngineCycleTps().


The documentation for this class was generated from the following files: