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 265 of file limp_manager.cpp.

265  {
266  return m_allowEtb;
267 }
Clearable m_allowEtb
Definition: limp_manager.h:145

◆ allowIgnition()

LimpState LimpManager::allowIgnition ( ) const

Definition at line 283 of file limp_manager.cpp.

283  {
284  if (!m_allowIgnition) {
285  return {false, m_allowIgnition.clearReason};
286  }
288  return {false, m_transientAllowIgnition.clearReason};
289  }
290  return {true, ClearReason::None};
291 }
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 273 of file limp_manager.cpp.

273  {
274  if (!m_allowInjection) {
275  return {false, m_allowInjection.clearReason};
276  }
278  return {false, m_transientAllowInjection.clearReason};
279  }
280  return {true, ClearReason::None};
281 }
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 269 of file limp_manager.cpp.

269  {
270  return m_allowTriggerInput;
271 }
Clearable m_allowTriggerInput
Definition: limp_manager.h:148

◆ fatalError()

void LimpManager::fatalError ( )

Definition at line 250 of file limp_manager.cpp.

250  {
255 
256  setFaultRevLimit(/*rpm*/0);
257 }
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 299 of file limp_manager.cpp.

299  {
301  return 1.0f; // no correction
302  return m_fuelCorrection;
303 }
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 293 of file limp_manager.cpp.

293  {
295  return 0;
296  return m_timingRetard;
297 }
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 305 of file limp_manager.cpp.

305  {
306  return m_lastCutTime.getElapsedSeconds();
307 }
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 239 of file limp_manager.cpp.

239  {
240  m_ignitionOn = ignitionOn;
241 }
bool m_ignitionOn
Definition: limp_manager.h:156

◆ setFaultRevLimit()

void LimpManager::setFaultRevLimit ( int  limit)
private

Definition at line 259 of file limp_manager.cpp.

259  {
260  // Only allow decreasing the limit
261  // aka uses the limit of the worst fault to yet occur
262  m_faultRevLimit = minI(m_faultRevLimit, limit);
263 }
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:73

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 
88 #if EFI_HD_ACR
89  // Don't inject fuel during Harley compression release - it sprays fuel everywhere
91  allowFuel.clear(ClearReason::ACR);
92  }
93 #endif // EFI_HD_ACR
94 
95  updateRevLimit(rpm);
98  allowFuel.clear(ClearReason::HardLimit);
99  }
100 
102  allowSpark.clear(ClearReason::HardLimit);
103  }
104  }
105 
106 #if EFI_SHAFT_POSITION_INPUT
107  if (engine->lambdaMonitor.isCut()) {
109  }
110 
113  // Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync
114  // examples:
115  // NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync
116  // VTwin Harley: uneven firing order, so we need "cam" MAP sync to make sure no spark happens out of sync
117  allowFuel.clear(ClearReason::EnginePhase);
118  allowSpark.clear(ClearReason::EnginePhase);
119  }
120 
121  // Force fuel limiting on the fault rev limit
122  if (rpm > m_faultRevLimit) {
124  }
125 
126  // Limit fuel only on boost pressure (limiting spark bends valves)
127  float mapCut = engineConfiguration->boostCutPressure;
128  if (mapCut != 0) {
129  // require drop of 'boostCutPressureHyst' kPa to resume fuel
131  allowFuel.clear(ClearReason::BoostCut);
132  }
133  }
134 
135  if (engine->rpmCalculator.isRunning()) {
136  uint16_t minOilPressure = engineConfiguration->minOilPressureAfterStart;
137 
138  // Only check if the setting is enabled and you have an oil pressure sensor
139  if (minOilPressure > 0 && Sensor::hasSensor(SensorType::OilPressure)) {
140  // Has it been long enough we should have pressure?
141  bool isTimedOut = engine->rpmCalculator.getSecondsSinceEngineStart(nowNt) > 5.0f;
142 
143  // Only check before timed out
144  if (!isTimedOut) {
146 
147  if (oilp) {
148  // We had oil pressure! Set the flag.
149  if (oilp.Value > minOilPressure) {
151  }
152  }
153  }
154 
155  // If time is up, the sensor works, and no pressure, kill the engine.
156  if (isTimedOut && !m_hadOilPressureAfterStart) {
157  allowFuel.clear(ClearReason::OilPressure);
158  }
159  }
160  } else {
161  // reset state in case of stalled engine
163  }
164 
165  // If we're in engine stop mode, inhibit fuel
166  if (shutdownController.isEngineStop(nowNt)) {
167  /**
168  * todo: we need explicit clarification on why do we cut fuel but do not cut spark here!
169  */
171  }
172 
173  {
174  // If duty cycle is high, impose a fuel cut rev limiter.
175  // This is safer than attempting to limp along with injectors or a pump that are out of flow.
176  // Two conditions will trigger a cut:
177  // - An instantaneous excursion above maxInjectorDutyInstant
178  // - A sustained excursion above maxInjectorDutySustained for a duration of >= maxInjectorDutySustainedTimeout
179  // Only reset once below 20% duty to force the driver to lift off the pedal
180 
181  auto injDutyCycle = getInjectorDutyCycle(rpm);
182  bool isOverInstantDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutyInstant;
183  bool isOverSustainedDutyCycle = injDutyCycle > engineConfiguration->maxInjectorDutySustained;
184  bool isUnderLowDuty = injDutyCycle < 20;
185 
186  if (!isOverSustainedDutyCycle) {
187  // Duty cycle is OK, reset timer.
188  m_injectorDutySustainedTimer.reset(nowNt);
189  }
190 
191  // True if isOverSustainedDutyCycle has been true for longer than the timeout
192  bool sustainedLimitTimedOut = m_injectorDutySustainedTimer.hasElapsedSec(engineConfiguration->maxInjectorDutySustainedTimeout);
193 
194  bool someLimitTripped = isOverInstantDutyCycle || sustainedLimitTimedOut;
195 
196  if (m_injectorDutyCutHysteresis.test(someLimitTripped, isUnderLowDuty)) {
198  warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Injector duty cycle cut %.1f", injDutyCycle);
199  }
200  }
201 
202  // If the pedal is pushed while not running, cut fuel to clear a flood condition.
203  if (!engine->rpmCalculator.isRunning() &&
206  allowFuel.clear(ClearReason::FloodClear);
207  }
208 #endif // EFI_SHAFT_POSITION_INPUT
209 
210  if (!engine->isMainRelayEnabled()) {
211 /*
212 todo AndreiKA this change breaks 22 unit tests?
213  allowFuel.clear();
214  allowSpark.clear();
215 */
216  }
217 
218 #if EFI_LAUNCH_CONTROL
219  // Fuel cut if launch control engaged
221  allowFuel.clear(ClearReason::LaunchCut);
222  }
223 
224  // Spark cut if launch control engaged
226  allowSpark.clear(ClearReason::LaunchCut);
227  }
228 #endif // EFI_LAUNCH_CONTROL
229 
230  m_transientAllowInjection = allowFuel;
231  m_transientAllowIgnition = allowSpark;
232 
234  // Tracks the last time any cut happened
235  m_lastCutTime.reset(nowNt);
236  }
237 }
TriggerCentral triggerCentral
Definition: engine.h:285
bool isMainRelayEnabled() const
Definition: engine.cpp:540
LaunchControlBase launchController
Definition: engine.h:189
EngineState engineState
Definition: engine.h:314
RpmCalculator rpmCalculator
Definition: engine.h:272
constexpr auto & module()
Definition: engine.h:174
LambdaMonitor lambdaMonitor
Definition: engine.h:204
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:155
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:279
bool isGdiEngine()
static bool noFiringUntilVvtSync(vvt_mode_e vvtMode)
@ CUSTOM_TOO_LONG_FUEL_INJECTION
@ DriverThrottleIntent
bool isCut() const
scaled_channel< uint8_t, 10, 1 > maxInjectorDutySustainedTimeout

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 doScheduleStopEngine(), and updateState().


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