rusEFI
The most advanced open source ECU
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
LimpManager Class Reference

#include <limp_manager.h>

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

Public Member Functions

void updateState (int rpm, efitick_t nowNt)
 
void onFastCallback () override
 
void onIgnitionStateChanged (bool ignitionOn) override
 
bool allowElectronicThrottle () const
 
LimpState allowInjection () const
 
LimpState allowIgnition () const
 
float getTimeSinceAnyCut () const
 
bool allowTriggerInput () const
 
void updateRevLimit (int rpm)
 
angle_t getLimitingTimingRetard () const
 
float getLimitingFuelCorrection () const
 
void fatalError ()
 
- Public Member Functions inherited from EngineModule
virtual void onConfigurationChange (engine_configuration_s const *)
 
virtual void onSlowCallback ()
 
virtual bool needsDelayedShutoff ()
 

Data Fields

ShutdownController shutdownController
 
Timer gdiComms
 

Private Member Functions

void setFaultRevLimit (int limit)
 

Private Attributes

Hysteresis m_revLimitHysteresis
 
Hysteresis m_boostCutHysteresis
 
Hysteresis m_injectorDutyCutHysteresis
 
int32_t m_faultRevLimit = INT32_MAX
 
Clearable m_allowEtb
 
Clearable m_allowInjection
 
Clearable m_allowIgnition
 
Clearable m_allowTriggerInput
 
Clearable m_transientAllowInjection = true
 
Clearable m_transientAllowIgnition = true
 
bool m_hadOilPressureAfterStart = false
 
bool m_ignitionOn = false
 
angle_t m_timingRetard = 0
 
float m_fuelCorrection = 1.0f
 
float m_revLimit
 
float resumeRpm
 
Timer m_lastCutTime
 
Timer m_injectorDutySustainedTimer
 

Detailed Description

Definition at line 106 of file limp_manager.h.

Member Function Documentation

◆ allowElectronicThrottle()

bool LimpManager::allowElectronicThrottle ( ) const

Definition at line 269 of file limp_manager.cpp.

269  {
270  return m_allowEtb;
271 }
Clearable m_allowEtb
Definition: limp_manager.h:145

◆ allowIgnition()

LimpState LimpManager::allowIgnition ( ) const

Definition at line 287 of file limp_manager.cpp.

287  {
288  if (!m_allowIgnition) {
289  return {false, m_allowIgnition.clearReason};
290  }
292  return {false, m_transientAllowIgnition.clearReason};
293  }
294  return {true, ClearReason::None};
295 }
ClearReason clearReason
Definition: limp_manager.h:70
Clearable m_allowIgnition
Definition: limp_manager.h:147
Clearable m_transientAllowIgnition
Definition: limp_manager.h:151

Referenced by onTriggerEventSparkLogic().

Here is the caller graph for this function:

◆ allowInjection()

LimpState LimpManager::allowInjection ( ) const

Definition at line 277 of file limp_manager.cpp.

277  {
278  if (!m_allowInjection) {
279  return {false, m_allowInjection.clearReason};
280  }
282  return {false, m_transientAllowInjection.clearReason};
283  }
284  return {true, ClearReason::None};
285 }
Clearable m_transientAllowInjection
Definition: limp_manager.h:150
Clearable m_allowInjection
Definition: limp_manager.h:146

Referenced by handleFuel().

Here is the caller graph for this function:

◆ allowTriggerInput()

bool LimpManager::allowTriggerInput ( ) const

Definition at line 273 of file limp_manager.cpp.

273  {
274  return m_allowTriggerInput;
275 }
Clearable m_allowTriggerInput
Definition: limp_manager.h:148

◆ fatalError()

void LimpManager::fatalError ( )

Definition at line 254 of file limp_manager.cpp.

254  {
259 
260  setFaultRevLimit(/*rpm*/0);
261 }
void clear(ClearReason p_clearReason)
Definition: limp_manager.h:59
void setFaultRevLimit(int limit)

Referenced by firmwareError().

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

◆ getLimitingFuelCorrection()

float LimpManager::getLimitingFuelCorrection ( ) const

Definition at line 303 of file limp_manager.cpp.

303  {
305  return 1.0f; // no correction
306  return m_fuelCorrection;
307 }
float m_fuelCorrection
Definition: limp_manager.h:159
engine_configuration_s * engineConfiguration

Referenced by getRunningFuel().

Here is the caller graph for this function:

◆ getLimitingTimingRetard()

angle_t LimpManager::getLimitingTimingRetard ( ) const

Definition at line 297 of file limp_manager.cpp.

297  {
299  return 0;
300  return m_timingRetard;
301 }
angle_t m_timingRetard
Definition: limp_manager.h:158

Referenced by EngineState::periodicFastCallback().

Here is the caller graph for this function:

◆ getTimeSinceAnyCut()

float LimpManager::getTimeSinceAnyCut ( ) const

Definition at line 309 of file limp_manager.cpp.

309  {
310  return m_lastCutTime.getElapsedSeconds();
311 }
Timer m_lastCutTime
Definition: limp_manager.h:166

◆ onFastCallback()

void LimpManager::onFastCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 46 of file limp_manager.cpp.

46  {
48 }
void updateState(int rpm, efitick_t nowNt)
static float getOrZero(SensorType type)
Definition: sensor.h:92
efitick_t getTimeNowNt()
Definition: efitime.cpp:19

Referenced by TriggerCentral::decodeMapCam().

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

◆ onIgnitionStateChanged()

void LimpManager::onIgnitionStateChanged ( bool  ignitionOn)
overridevirtual

Reimplemented from EngineModule.

Definition at line 243 of file limp_manager.cpp.

243  {
244  m_ignitionOn = ignitionOn;
245 }
bool m_ignitionOn
Definition: limp_manager.h:156

◆ setFaultRevLimit()

void LimpManager::setFaultRevLimit ( int  limit)
private

Definition at line 263 of file limp_manager.cpp.

263  {
264  // Only allow decreasing the limit
265  // aka uses the limit of the worst fault to yet occur
266  m_faultRevLimit = minI(m_faultRevLimit, limit);
267 }
int32_t m_faultRevLimit
Definition: limp_manager.h:143

Referenced by fatalError().

Here is the caller graph for this function:

◆ updateRevLimit()

void LimpManager::updateRevLimit ( int  rpm)

Definition at line 50 of file limp_manager.cpp.

50  {
51  // User-configured hard RPM limit, either constant or CLT-lookup
54  : (float)engineConfiguration->rpmHardLimit;
55 
56  // Require configurable rpm drop before resuming
58 
60 
62  m_fuelCorrection = 1.0f + fuelAdded / 100;
63 }
float m_revLimit
Definition: limp_manager.h:162
float resumeRpm
Definition: limp_manager.h:163
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
persistent_config_s * config
float percent_t
Definition: rusefi_types.h:74

Referenced by EngineState::periodicFastCallback(), and updateState().

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

◆ updateState()

void LimpManager::updateState ( int  rpm,
efitick_t  nowNt 
)

todo: we need explicit clarification on why do we cut fuel but do not cut spark here!

Definition at line 65 of file limp_manager.cpp.

65  {
68 
69 #if EFI_SHAFT_POSITION_INPUT && !EFI_UNIT_TEST
70  if (!m_ignitionOn
71  && !engine->triggerCentral.directSelfStimulation // useful to try things on real ECU even without ignition voltage
72  ) {
74  allowSpark.clear(ClearReason::IgnitionOff);
75  }
76 #endif
77 
78  if (isGdiEngine()) {
79  if (gdiComms.getElapsedSeconds() > 1) {
80  allowFuel.clear(ClearReason::GdiComms);
81  }
82  }
83 
85  allowSpark.clear(ClearReason::Lua);
86  }
87 
89  allowFuel.clear(ClearReason::Lua);
90  }
91 
92 #if EFI_HD_ACR
93  // Don't inject fuel during Harley compression release - it sprays fuel everywhere
95  allowFuel.clear(ClearReason::ACR);
96  }
97 #endif // EFI_HD_ACR
98 
99  updateRevLimit(rpm);
102  allowFuel.clear(ClearReason::HardLimit);
103  }
104 
106  allowSpark.clear(ClearReason::HardLimit);
107  }
108  }
109 
110 #if EFI_SHAFT_POSITION_INPUT
111  if (engine->lambdaMonitor.isCut()) {
113  }
114 
117  // Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync
118  // examples:
119  // NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync
120  // VTwin Harley: uneven firing order, so we need "cam" MAP sync to make sure no spark happens out of sync
121  allowFuel.clear(ClearReason::EnginePhase);
122  allowSpark.clear(ClearReason::EnginePhase);
123  }
124 
125  // Force fuel limiting on the fault rev limit
126  if (rpm > m_faultRevLimit) {
128  }
129 
130  // Limit fuel only on boost pressure (limiting spark bends valves)
131  float mapCut = engineConfiguration->boostCutPressure;
132  if (mapCut != 0) {
133  // require drop of 'boostCutPressureHyst' kPa to resume fuel
135  allowFuel.clear(ClearReason::BoostCut);
136  }
137  }
138 
139  if (engine->rpmCalculator.isRunning()) {
140  uint16_t minOilPressure = engineConfiguration->minOilPressureAfterStart;
141 
142  // Only check if the setting is enabled and you have an oil pressure sensor
143  if (minOilPressure > 0 && Sensor::hasSensor(SensorType::OilPressure)) {
144  // Has it been long enough we should have pressure?
145  bool isTimedOut = engine->rpmCalculator.getSecondsSinceEngineStart(nowNt) > 5.0f;
146 
147  // Only check before timed out
148  if (!isTimedOut) {
150 
151  if (oilp) {
152  // We had oil pressure! Set the flag.
153  if (oilp.Value > minOilPressure) {
155  }
156  }
157  }
158 
159  // If time is up, the sensor works, and no pressure, kill the engine.
160  if (isTimedOut && !m_hadOilPressureAfterStart) {
161  allowFuel.clear(ClearReason::OilPressure);
162  }
163  }
164  } else {
165  // reset state in case of stalled engine
167  }
168 
169  // If we're in engine stop mode, inhibit fuel
170  if (shutdownController.isEngineStop(nowNt)) {
171  /**
172  * todo: we need explicit clarification on why do we cut fuel but do not cut spark here!
173  */
175  }
176 
177  {
178  // If duty cycle is high, impose a fuel cut rev limiter.
179  // This is safer than attempting to limp along with injectors or a pump that are out of flow.
180  // Two conditions will trigger a cut:
181  // - An instantaneous excursion above maxInjectorDutyInstant
182  // - A sustained excursion above maxInjectorDutySustained for a duration of >= maxInjectorDutySustainedTimeout
183  // Only reset once below 20% duty to force the driver to lift off the pedal
184 
185  auto injDutyCycle = getInjectorDutyCycle(rpm);
186  bool isOverInstantDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutyInstant;
187  bool isOverSustainedDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutySustained;
188  bool isUnderLowDuty = injDutyCycle < 20;
189 
190  if (!isOverSustainedDutyCycle) {
191  // Duty cycle is OK, reset timer.
192  m_injectorDutySustainedTimer.reset(nowNt);
193  }
194 
195  // True if isOverSustainedDutyCycle has been true for longer than the timeout
196  bool sustainedLimitTimedOut = m_injectorDutySustainedTimer.hasElapsedSec(engineConfiguration->maxInjectorDutySustainedTimeout);
197 
198  bool someLimitTripped = isOverInstantDutyCycle || sustainedLimitTimedOut;
199 
200  if (m_injectorDutyCutHysteresis.test(someLimitTripped, isUnderLowDuty)) {
202  warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Injector duty cycle cut %.1f", injDutyCycle);
203  }
204  }
205 
206  // If the pedal is pushed while not running, cut fuel to clear a flood condition.
207  if (!engine->rpmCalculator.isRunning() &&
210  allowFuel.clear(ClearReason::FloodClear);
211  }
212 #endif // EFI_SHAFT_POSITION_INPUT
213 
214  if (!engine->isMainRelayEnabled()) {
215 /*
216 todo AndreiKA this change breaks 22 unit tests?
217  allowFuel.clear();
218  allowSpark.clear();
219 */
220  }
221 
222 #if EFI_LAUNCH_CONTROL
223  // Fuel cut if launch control engaged
225  allowFuel.clear(ClearReason::LaunchCut);
226  }
227 
228  // Spark cut if launch control engaged
230  allowSpark.clear(ClearReason::LaunchCut);
231  }
232 #endif // EFI_LAUNCH_CONTROL
233 
234  m_transientAllowInjection = allowFuel;
235  m_transientAllowIgnition = allowSpark;
236 
238  // Tracks the last time any cut happened
239  m_lastCutTime.reset(nowNt);
240  }
241 }
TriggerCentral triggerCentral
Definition: engine.h:286
bool isMainRelayEnabled() const
Definition: engine.cpp:560
LaunchControlBase launchController
Definition: engine.h:192
EngineState engineState
Definition: engine.h:312
RpmCalculator rpmCalculator
Definition: engine.h:273
constexpr auto & module()
Definition: engine.h:177
LambdaMonitor lambdaMonitor
Definition: engine.h:207
bool isActive() const
Definition: harley_acr.cpp:66
bool test(float value, float rising, float falling)
Definition: limp_manager.h:88
bool isLaunchFuelRpmRetardCondition() const
bool isLaunchSparkRpmRetardCondition() const
void updateRevLimit(int rpm)
Hysteresis m_boostCutHysteresis
Definition: limp_manager.h:139
Hysteresis m_revLimitHysteresis
Definition: limp_manager.h:138
bool m_hadOilPressureAfterStart
Definition: limp_manager.h:153
Timer m_injectorDutySustainedTimer
Definition: limp_manager.h:169
Timer gdiComms
Definition: limp_manager.h:133
Hysteresis m_injectorDutyCutHysteresis
Definition: limp_manager.h:140
ShutdownController shutdownController
Definition: limp_manager.h:108
bool hasSynchronizedPhase() const
float getSecondsSinceEngineStart(efitick_t nowNt) const
bool isRunning() const
virtual bool hasSensor() const
Definition: sensor.h:150
virtual SensorResult get() const =0
bool isEngineStop(efitick_t nowNt) const
PrimaryTriggerDecoder triggerState
bool directSelfStimulation
Engine * engine
bool warning(ObdCode code, const char *fmt,...)
percent_t getInjectorDutyCycle(int rpm)
Definition: fuel_math.cpp:282
bool isGdiEngine()
static bool noFiringUntilVvtSync(vvt_mode_e vvtMode)
@ CUSTOM_TOO_LONG_FUEL_INJECTION
@ DriverThrottleIntent
bool isCut() const

Referenced by onFastCallback().

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

Field Documentation

◆ gdiComms

Timer LimpManager::gdiComms

Definition at line 133 of file limp_manager.h.

Referenced by processCanRxMessage(), and updateState().

◆ m_allowEtb

Clearable LimpManager::m_allowEtb
private

Definition at line 145 of file limp_manager.h.

Referenced by allowElectronicThrottle(), and fatalError().

◆ m_allowIgnition

Clearable LimpManager::m_allowIgnition
private

Definition at line 147 of file limp_manager.h.

Referenced by allowIgnition(), and fatalError().

◆ m_allowInjection

Clearable LimpManager::m_allowInjection
private

Definition at line 146 of file limp_manager.h.

Referenced by allowInjection(), and fatalError().

◆ m_allowTriggerInput

Clearable LimpManager::m_allowTriggerInput
private

Definition at line 148 of file limp_manager.h.

Referenced by allowTriggerInput(), and fatalError().

◆ m_boostCutHysteresis

Hysteresis LimpManager::m_boostCutHysteresis
private

Definition at line 139 of file limp_manager.h.

Referenced by updateState().

◆ m_faultRevLimit

int32_t LimpManager::m_faultRevLimit = INT32_MAX
private

Definition at line 143 of file limp_manager.h.

Referenced by setFaultRevLimit(), and updateState().

◆ m_fuelCorrection

float LimpManager::m_fuelCorrection = 1.0f
private

Definition at line 159 of file limp_manager.h.

Referenced by getLimitingFuelCorrection(), and updateRevLimit().

◆ m_hadOilPressureAfterStart

bool LimpManager::m_hadOilPressureAfterStart = false
private

Definition at line 153 of file limp_manager.h.

Referenced by updateState().

◆ m_ignitionOn

bool LimpManager::m_ignitionOn = false
private

Definition at line 156 of file limp_manager.h.

Referenced by onIgnitionStateChanged(), and updateState().

◆ m_injectorDutyCutHysteresis

Hysteresis LimpManager::m_injectorDutyCutHysteresis
private

Definition at line 140 of file limp_manager.h.

Referenced by updateState().

◆ m_injectorDutySustainedTimer

Timer LimpManager::m_injectorDutySustainedTimer
private

Definition at line 169 of file limp_manager.h.

Referenced by updateState().

◆ m_lastCutTime

Timer LimpManager::m_lastCutTime
private

Definition at line 166 of file limp_manager.h.

Referenced by getTimeSinceAnyCut(), and updateState().

◆ m_revLimit

float LimpManager::m_revLimit
private

Definition at line 162 of file limp_manager.h.

Referenced by updateRevLimit(), and updateState().

◆ m_revLimitHysteresis

Hysteresis LimpManager::m_revLimitHysteresis
private

Definition at line 138 of file limp_manager.h.

Referenced by updateState().

◆ m_timingRetard

angle_t LimpManager::m_timingRetard = 0
private

Definition at line 158 of file limp_manager.h.

Referenced by getLimitingTimingRetard(), and updateRevLimit().

◆ m_transientAllowIgnition

Clearable LimpManager::m_transientAllowIgnition = true
private

Definition at line 151 of file limp_manager.h.

Referenced by allowIgnition(), and updateState().

◆ m_transientAllowInjection

Clearable LimpManager::m_transientAllowInjection = true
private

Definition at line 150 of file limp_manager.h.

Referenced by allowInjection(), and updateState().

◆ resumeRpm

float LimpManager::resumeRpm
private

Definition at line 163 of file limp_manager.h.

Referenced by updateRevLimit(), and updateState().

◆ shutdownController

ShutdownController LimpManager::shutdownController

Definition at line 108 of file limp_manager.h.

Referenced by configureRusefiLuaHooks(), doScheduleStopEngine(), and updateState().


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