rusEFI
The most advanced open source ECU
accel_enrichment.cpp
Go to the documentation of this file.
1 /**
2  * @file accel_enrichment.cpp
3  * @brief Acceleration enrichment calculator
4  *
5  * In this file we have three strategies for acceleration/deceleration fuel correction
6  *
7  * 1) MAP rate-of-change correction
8  * 2) TPS rate-of-change correction
9  * 3) fuel film/wal wetting correction
10  * AWC Added to Wall Coefficient, %
11  * AWA Added to Wall Amount
12  * SOC Sucked Off wall Coefficient, %
13  * SOA Sucked Off wall amount
14  * WF current on-Wall Fuel amount
15  *
16  *
17  * http://rusefi.com/wiki/index.php?title=Manual:Software:Fuel_Control
18  * @date Apr 21, 2014
19  * @author Dmitry Sidin
20  * @author Andrey Belomutskiy, (c) 2012-2020
21  * @author Matthew Kennedy
22  */
23 
24 #include "pch.h"
25 #include "accel_enrichment.h"
26 
28 
31 
33  // If disabled, return 0.
34  return 0;
35  }
37  if (rpm == 0) {
38  return 0;
39  }
40 
44  } else if (isBelowDecelThreshold) {
46  } else {
47  extraFuel = 0;
48  }
49 
50  // Fractional enrichment (fuel portions are accumulated and split between several engine cycles.
51  // This is a crude imitation of carburetor's acceleration pump.
54  // make sure both values are non-zero
55  float periodF = (float)maxI(engineConfiguration->tpsAccelFractionPeriod, 1);
56  float divisor = maxF(engineConfiguration->tpsAccelFractionDivisor, 1.0f);
57 
58  // if current extra fuel portion is not "strong" enough, then we keep up the "pump pressure" with the accumulated portion
59  floatms_t maxExtraFuel = maxF(extraFuel, accumulatedValue);
60  // use only a fixed fraction of the accumulated portion
61  fractionalInjFuel = maxExtraFuel / divisor;
62 
63  // update max counters
66 
67  // evenly split it between several engine cycles
68  extraFuel = fractionalInjFuel / periodF;
69  } else {
71  }
72 
73 #if EFI_TUNER_STUDIO
74  if (engineConfiguration->debugMode == DBG_TPS_ACCEL) {
83  }
84 #endif /* EFI_TUNER_STUDIO */
85 
86  float mult = interpolate2d(rpm, config->tpsTspCorrValuesBins,
88  if (mult != 0 && (mult < 0.01 || mult > 100)) {
89  mult = 1;
90  }
91 
92  return extraFuel * mult;
93 }
94 
96  // we update values in handleFuel() directly by calling onNewValue()
97 
99 
100  // we used some extra fuel during the current cycle, so we "charge" our "acceleration pump" with it
103  maxExtraPerCycle = 0;
105 
106  // update the accumulated value every 'Period' engine cycles
109  maxExtraPerPeriod = 0;
110 
111  // we've injected this portion during the cycle, so we set what's left for the next cycle
114 
115  // it's an infinitely convergent series, so we set a limit at some point
116  // (also make sure that accumulatedValue is positive, for safety)
117  static const floatms_t smallEpsilon = 0.001f;
118  belowEpsilon = accumulatedValue < smallEpsilon;
119  if (belowEpsilon) {
120  accumulatedValue = 0;
121  }
122 
123  // reset the counter
125  }
126 }
127 
129  int len = minI(cb.getSize(), cb.getCount());
130  tooShort = len < 2;
131  if (tooShort)
132  return 0;
133  int ci = cb.currentIndex - 1;
134  float maxValue = cb.get(ci) - cb.get(ci - 1);
135  int resultIndex = ci;
136 
137  // todo: 'get' method is maybe a bit heavy because of the branching
138  // todo: this could be optimized with some careful magic
139 
140  for (int i = 1; i<len - 1;i++) {
141  float v = cb.get(ci - i) - cb.get(ci - i - 1);
142  if (v > maxValue) {
143  maxValue = v;
144  resultIndex = ci - i;
145  }
146  }
147 
148  return resultIndex;
149 }
150 
152  int index = getMaxDeltaIndex();
153 
154  return (cb.get(index) - (cb.get(index - 1)));
155 }
156 
158  cb.clear();
160 }
161 
163  accumulatedValue = 0;
164  maxExtraPerCycle = 0;
165  maxExtraPerPeriod = 0;
167  cycleCnt = 0;
168 }
169 
171  cb.setSize(length);
172 }
173 
174 void TpsAccelEnrichment::onNewValue(float currentValue) {
175  // Push new value in to the history buffer
176  cb.add(currentValue);
177 
178  // Update deltas
179  int maxDeltaIndex = getMaxDeltaIndex();
180  tpsFrom = cb.get(maxDeltaIndex - 1);
181  tpsTo = cb.get(maxDeltaIndex);
182  deltaTps = tpsTo - tpsFrom;
183 
184  // Update threshold detection
186 
187  // TODO: can deltaTps actually be negative? Will this ever trigger?
189 }
190 
192  resetAE();
193  cb.setSize(4);
194 }
195 
196 #if ! EFI_UNIT_TEST
197 
198 static void accelInfo() {
199 // efiPrintf("TPS accel length=%d", tpsInstance.cb.getSize());
200  efiPrintf("TPS accel th=%.2f/mult=%.2f", engineConfiguration->tpsAccelEnrichmentThreshold, -1);
201 
202  efiPrintf("beta=%.2f/tau=%.2f", engineConfiguration->wwaeBeta, engineConfiguration->wwaeTau);
203 }
204 
205 void setTpsAccelThr(float value) {
207  accelInfo();
208 }
209 
210 void setTpsDecelThr(float value) {
212  accelInfo();
213 }
214 
215 void setTpsDecelMult(float value) {
217  accelInfo();
218 }
219 
220 void setTpsAccelLen(int length) {
221  if (length < 1) {
222  efiPrintf("setTpsAccelLen: Length should be positive [%d]", length);
223  return;
224  }
226  accelInfo();
227 }
228 
230  constexpr float slowCallbackPeriodSecond = SLOW_CALLBACK_PERIOD_MS / 1000.0f;
231  setTpsAccelLen(engineConfiguration->tpsAccelLookback / slowCallbackPeriodSecond);
232 }
233 
234 #endif /* ! EFI_UNIT_TEST */
235 
236 
239 
240 #if ! EFI_UNIT_TEST
241 
242  addConsoleAction("accelinfo", accelInfo);
243 
245 #endif /* ! EFI_UNIT_TEST */
246 }
247 
static void accelInfo()
void setTpsDecelThr(float value)
void setTpsDecelMult(float value)
void setTpsAccelThr(float value)
void setTpsAccelLen(int length)
void initAccelEnrichment()
static tps_tps_Map3D_t tpsTpsMap
void updateAccelParameters()
Acceleration enrichment calculator.
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
TpsAccelEnrichment tpsAccelEnrichment
Definition: engine.h:278
float getValue(float xColumn, float yRow) const final
Definition: table_helper.h:43
void initTable(TValueInit(&table)[TRowNum][TColNum], const TXColumnInit(&columnBins)[TColNum], const TRowInit(&rowBins)[TRowNum])
Definition: table_helper.h:33
static float getOrZero(SensorType type)
Definition: sensor.h:92
cyclic_buffer< float > cb
void onNewValue(float currentValue)
void setLength(int length)
floatms_t getTpsEnrichment()
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
Engine * engine
@ GetTpsEnrichment
persistent_config_s * config
engine_configuration_s * engineConfiguration
float floatms_t
Definition: rusefi_types.h:67
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]