rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
engine_math.cpp File Reference

Detailed Description

Date
Jul 13, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

This file is part of rusEfi - see http://rusefi.com

rusEfi is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file engine_math.cpp.

Functions

floatms_t getEngineCycleDuration (float rpm)
 
floatms_t getCrankshaftRevolutionTimeMs (float rpm)
 
float getFuelingLoad ()
 
float getIgnitionLoad ()
 
void setSingleCoilDwell ()
 
ignition_mode_e getCurrentIgnitionMode ()
 
void prepareOutputSignals ()
 
angle_t getPerCylinderFiringOrderOffset (uint8_t cylinderIndex, uint8_t cylinderNumber)
 
void setTimingRpmBin (float from, float to)
 
void setAlgorithm (engine_load_mode_e algo)
 
void setFlatInjectorLag (float value)
 
BlendResult calculateBlend (blend_table_s &cfg, float rpm, float load)
 

Variables

bool verboseMode
 

Function Documentation

◆ calculateBlend()

BlendResult calculateBlend ( blend_table_s cfg,
float  rpm,
float  load 
)

Definition at line 161 of file engine_math.cpp.

161 {
162 // If set to 0, skip the math as its disabled
163 if (cfg.blendParameter == GPPWM_Zero) {
164 return { 0, 0, 0, 0 };
165 }
166
167 auto value = readGppwmChannel(cfg.blendParameter);
168
169 if (!value) {
170 return { 0, 0, 0, 0 };
171 }
172
173 // Override Y axis value (if necessary)
174 if (cfg.yAxisOverride != GPPWM_Zero) {
175 // TODO: is this value_or(0) correct or even reasonable?
176 load = readGppwmChannel(cfg.yAxisOverride).value_or(0);
177 }
178
179 float tableValue = interpolate3d(
180 cfg.table,
181 cfg.loadBins, load,
182 cfg.rpmBins, rpm
183 );
184
185 float blendFactor = interpolate2d(value.Value, cfg.blendBins, cfg.blendValues);
186
187 return { value.Value, blendFactor, 0.01f * blendFactor * tableValue, load };
188}
expected< float > readGppwmChannel(gppwm_channel_e channel)
scaled_channel< int16_t, 10, 1 > blendBins[BLEND_FACTOR_SIZE]
scaled_channel< uint8_t, 2, 1 > blendValues[BLEND_FACTOR_SIZE]
scaled_channel< int16_t, 10, 1 > table[BLEND_TABLE_COUNT][BLEND_TABLE_COUNT]

Referenced by BoostController::getOpenLoop(), getRunningAdvance(), BoostController::getSetpoint(), FuelComputer::getTargetLambda(), and AirmassVeModelBase::getVe().

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

◆ getCrankshaftRevolutionTimeMs()

floatms_t getCrankshaftRevolutionTimeMs ( float  rpm)
Returns
number of milliseconds in one crank shaft revolution

Definition at line 40 of file engine_math.cpp.

40 {
41 if (rpm == 0) {
42 return NAN;
43 }
44 return 360 * getOneDegreeTimeMs(rpm);
45}

Referenced by getCoilDutyCycle(), getEngineCycleDuration(), and InjectionEvent::onTriggerTooth().

Here is the caller graph for this function:

◆ getCurrentIgnitionMode()

ignition_mode_e getCurrentIgnitionMode ( )
Returns
IM_WASTED_SPARK if in SPINNING mode and IM_INDIVIDUAL_COILS setting
engineConfiguration->ignitionMode otherwise

Definition at line 78 of file engine_math.cpp.

78 {
80#if EFI_SHAFT_POSITION_INPUT
81 // In spin-up cranking mode we don't have full phase sync info yet, so wasted spark mode is better
82 if (ignitionMode == IM_INDIVIDUAL_COILS) {
83 bool missingPhaseInfoForSequential =
85
86 if (engine->rpmCalculator.isSpinningUp() || missingPhaseInfoForSequential) {
87 ignitionMode = IM_WASTED_SPARK;
88 }
89 }
90#endif /* EFI_SHAFT_POSITION_INPUT */
91 return ignitionMode;
92}
TriggerCentral triggerCentral
Definition engine.h:318
RpmCalculator rpmCalculator
Definition engine.h:306
bool hasSynchronizedPhase() const
bool isSpinningUp() const
PrimaryTriggerDecoder triggerState
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
ignition_mode_e

Referenced by getCoilDutyCycle(), onTriggerEventSparkLogic(), prepareCylinderIgnitionSchedule(), prepareIgnitionSchedule(), and startDwellByTurningSparkPinHigh().

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

◆ getEngineCycleDuration()

floatms_t getEngineCycleDuration ( float  rpm)

Definition at line 33 of file engine_math.cpp.

33 {
35}
virtual operation_mode_e getOperationMode() const =0
EngineRotationState * getEngineRotationState()
Definition engine.cpp:573
floatms_t getCrankshaftRevolutionTimeMs(float rpm)
@ TWO_STROKE

Referenced by getBaseFuelMass(), getInjectorDutyCycle(), getInjectorDutyCycleStage2(), and IFuelComputer::getTChargeCoefficient().

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

◆ getFuelingLoad()

float getFuelingLoad ( )

Definition at line 47 of file engine_math.cpp.

47 {
49}
EngineState * getEngineState()
Definition engine.cpp:577

Referenced by IdleController::getClosedLoop(), VvtController::getSetpoint(), handleGetDataRequest(), EngineState::periodicFastCallback(), and readGppwmChannel().

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

◆ getIgnitionLoad()

float getIgnitionLoad ( )

Definition at line 51 of file engine_math.cpp.

51 {
53}

Referenced by KnockController::getMaximumRetard(), EngineState::periodicFastCallback(), and readGppwmChannel().

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

◆ getPerCylinderFiringOrderOffset()

angle_t getPerCylinderFiringOrderOffset ( uint8_t  cylinderIndex,
uint8_t  cylinderNumber 
)

Gets phase offset for a particular cylinder's ID and number For example on 4 cylinder engine with firing order 1-3-4-2, this returns 0-180-360-540 for index 0-1-2-3 Cylinder number is used for per-cylinder adjustment, if you have an odd-fire engine (v-twin, V10, some v6, etc)

Definition at line 131 of file engine_math.cpp.

131 {
132 // base = position of this cylinder in the firing order.
133 // We get a cylinder every n-th of an engine cycle where N is the number of cylinders
134 auto firingOrderOffset = engine->engineState.engineCycle * cylinderIndex / engineConfiguration->cylindersCount;
135
136 // Plus or minus any adjustment if this is an odd-fire engine
137 auto adjustment = engineConfiguration->timing_offset_cylinder[cylinderNumber];
138
139 auto result = firingOrderOffset + adjustment;
140
141 assertAngleRange(result, "getCylinderAngle", ObdCode::CUSTOM_ERR_CYL_ANGLE);
142
143 return result;
144}
EngineState engineState
Definition engine.h:344
angle_t engineCycle
@ CUSTOM_ERR_CYL_ANGLE

Referenced by InjectionEvent::computeInjectionAngle(), and prepareCylinderIgnitionSchedule().

Here is the caller graph for this function:

◆ prepareOutputSignals()

void prepareOutputSignals ( )

This heavy method is only invoked in case of a configuration change or initialization.

Definition at line 99 of file engine_math.cpp.

99 {
100 auto operationMode = getEngineRotationState()->getOperationMode();
101 getEngineState()->engineCycle = getEngineCycle(operationMode);
102
103 bool isOddFire = false;
104 for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
106 isOddFire = true;
107 break;
108 }
109 }
110
112
113 // Use odd fire wasted spark logic if not two stroke, and an odd fire or odd cylinder # engine
115 && (isOddFire | (engineConfiguration->cylindersCount % 2 == 1));
116
117#if EFI_UNIT_TEST
118 if (verboseMode) {
120 }
121#endif /* EFI_UNIT_TEST */
122
123#if EFI_SHAFT_POSITION_INPUT
125#endif // EFI_SHAFT_POSITION_INPUT
126
127 // Fuel schedule may now be completely wrong, force a reset
129}
const char * getIgnition_mode_e(ignition_mode_e value)
FuelSchedule injectionEvents
Definition engine.h:288
bool useOddFireWastedSpark
void prepareTriggerShape()
bool verboseMode
void updateCylinders(void)
angle_t getEngineCycle(operation_mode_e operationMode)
printf("\n")

Referenced by commonInitEngineController(), setIgnitionMode(), and Engine::updateTriggerConfiguration().

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

◆ setAlgorithm()

void setAlgorithm ( engine_load_mode_e  algo)

◆ setFlatInjectorLag()

void setFlatInjectorLag ( float  value)

Definition at line 157 of file engine_math.cpp.

157 {
159}
scaled_channel< int16_t, 100, 1 > battLagCorrTable[VBAT_INJECTOR_CURVE_PRESSURE_SIZE][VBAT_INJECTOR_CURVE_SIZE]
constexpr void setTable(TElement(&dest)[N][M], const VElement value)

Referenced by fuelBenchMode().

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

◆ setSingleCoilDwell()

void setSingleCoilDwell ( )

see also setConstantDwell

Definition at line 58 of file engine_math.cpp.

58 {
59 for (int i = 0; i < DWELL_CURVE_SIZE; i++) {
60 config->sparkDwellRpmBins[i] = (i + 1) * 50;
62 }
63
64 config->sparkDwellRpmBins[5] = 500;
66
67 config->sparkDwellRpmBins[6] = 4500;
69
70 config->sparkDwellRpmBins[7] = 12500;
72}
static constexpr persistent_config_s * config
scaled_channel< uint16_t, 100, 1 > sparkDwellValues[DWELL_CURVE_SIZE]

Referenced by setFordAspireEngineConfiguration(), and setFordEscortGt().

Here is the caller graph for this function:

◆ setTimingRpmBin()

void setTimingRpmBin ( float  from,
float  to 
)

Definition at line 146 of file engine_math.cpp.

146 {
147 setRpmBin(config->ignitionRpmBins, IGN_RPM_COUNT, from, to);
148}
void setRpmBin(kType array[], int size, float idleRpm, float topRpm)

Referenced by setDefaultIgnition().

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

Variable Documentation

◆ verboseMode

bool verboseMode
extern

Referenced by prepareOutputSignals().

Go to the source code of this file.