| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include "pch.h" | |||
| 2 | ||||
| 3 | #include "engine_configuration.h" | |||
| 4 | #include "sensor.h" | |||
| 5 | #include "error_handling.h" | |||
| 6 | #include "efi_interpolation.h" | |||
| 7 | #include "table_helper.h" | |||
| 8 | #include "fuel_math.h" | |||
| 9 | #include "fuel_computer.h" | |||
| 10 | ||||
| 11 | #if EFI_ENGINE_CONTROL | |||
| 12 | ||||
| 13 | 1107 | mass_t FuelComputerBase::getCycleFuel(mass_t airmass, float rpm, float load) { | ||
| 14 | 1107 | load = getTargetLambdaLoadAxis(load); | ||
| 15 | ||||
| 16 | 1107 | float stoich = getStoichiometricRatio(); | ||
| 17 | 1107 | float lambda = getTargetLambda(rpm, load); | ||
| 18 | 1107 | float afr = stoich * lambda; | ||
| 19 | ||||
| 20 | 1107 | afrTableYAxis = load; | ||
| 21 | 1107 | targetLambda = lambda; | ||
| 22 | 1107 | targetAFR = afr; | ||
| 23 | 1107 | stoichiometricRatio = stoich; | ||
| 24 | ||||
| 25 | 1107 | return airmass / afr; | ||
| 26 | } | |||
| 27 | ||||
| 28 | 1112 | float FuelComputer::getStoichiometricRatio() const { | ||
| 29 | 1112 | float primary = engineConfiguration->stoichRatioPrimary; | ||
| 30 | ||||
| 31 | ||||
| 32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1112 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1112 times.
|
1112 | if (primary < 5) { |
| 33 | // Config compatibility: this field may be zero on ECUs with very old defaults | |||
| 34 | ✗ | criticalError("Please set stoichRatioPrimary"); | ||
| 35 | ✗ | return 0; | ||
| 36 | } | |||
| 37 | ||||
| 38 | // Without an ethanol/flex sensor, return primary configured stoich ratio | |||
| 39 |
2/2✓ Branch 1 taken 1107 times.
✓ Branch 2 taken 5 times.
|
2/2✓ Decision 'true' taken 1107 times.
✓ Decision 'false' taken 5 times.
|
1112 | if (!Sensor::hasSensor(SensorType::FuelEthanolPercent)) { |
| 40 | 1107 | return primary; | ||
| 41 | } | |||
| 42 | ||||
| 43 | 5 | float secondary = engineConfiguration->stoichRatioSecondary; | ||
| 44 | ||||
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 5 times.
|
5 | if (secondary < 5) { |
| 46 | // Config compatibility: this field may be zero on ECUs with very old defaults | |||
| 47 | ✗ | criticalError("Please set stoichRatioSecondary"); | ||
| 48 | ✗ | return 0; | ||
| 49 | } | |||
| 50 | ||||
| 51 | 5 | auto flex = Sensor::get(SensorType::FuelEthanolPercent); | ||
| 52 | ||||
| 53 | // TODO: what do do if flex sensor fails? | |||
| 54 | ||||
| 55 | // Linear interpolate between primary and secondary stoich ratios | |||
| 56 | 5 | return interpolateClamped(0, primary, 100, secondary, flex.Value); | ||
| 57 | } | |||
| 58 | ||||
| 59 | ||||
| 60 | 1106 | float FuelComputer::getTargetLambda(float rpm, float load) const { | ||
| 61 | 2212 | float target = interpolate3d( | ||
| 62 | 1106 | config->lambdaTable, | ||
| 63 | 1106 | config->lambdaLoadBins, load, | ||
| 64 | 1106 | config->lambdaRpmBins, rpm | ||
| 65 | ); | |||
| 66 | ||||
| 67 | // Add any blends if configured | |||
| 68 |
2/2✓ Branch 1 taken 2212 times.
✓ Branch 2 taken 1106 times.
|
2/2✓ Decision 'true' taken 2212 times.
✓ Decision 'false' taken 1106 times.
|
3318 | for (size_t i = 0; i < efi::size(config->targetAfrBlends); i++) { |
| 69 | 2212 | auto result = calculateBlend(config->targetAfrBlends[i], rpm, load); | ||
| 70 | ||||
| 71 | 2212 | engine->outputChannels.targetAfrBlendParameter[i] = result.BlendParameter; | ||
| 72 | 2212 | engine->outputChannels.targetAfrBlendBias[i] = result.Bias; | ||
| 73 | 2212 | engine->outputChannels.targetAfrBlendOutput[i] = result.Value; | ||
| 74 | 2212 | engine->outputChannels.targetAfrBlendYAxis[i] = result.TableYAxis; | ||
| 75 | ||||
| 76 | 2212 | target += result.Value; | ||
| 77 | } | |||
| 78 | ||||
| 79 | 1106 | return target; | ||
| 80 | } | |||
| 81 | ||||
| 82 | 1106 | float FuelComputer::getTargetLambdaLoadAxis(float defaultLoad) const { | ||
| 83 | 1106 | return getLoadOverride(defaultLoad, engineConfiguration->afrOverrideMode); | ||
| 84 | } | |||
| 85 | ||||
| 86 | 2212 | float IFuelComputer::getLoadOverride(float defaultLoad, load_override_e overrideMode) const { | ||
| 87 |
1/6✓ Branch 0 taken 2212 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2212 | switch(overrideMode) { | |
| 88 |
1/1✓ Decision 'true' taken 2212 times.
|
2212 | case AFR_None: return defaultLoad; | |
| 89 | // MAP default to 200kpa - failed MAP goes rich | |||
| 90 | ✗ | case AFR_MAP: return Sensor::get(SensorType::Map).value_or(200); | ||
| 91 | // TPS/pedal default to 100% - failed TPS goes rich | |||
| 92 | ✗ | case AFR_Tps: return Sensor::get(SensorType::Tps1).value_or(100); | ||
| 93 | ✗ | case AFR_AccPedal: return Sensor::get(SensorType::AcceleratorPedal).value_or(100); | ||
| 94 | ✗ | case AFR_CylFilling: return normalizedCylinderFilling; | ||
| 95 | ✗ | default: return 0; | ||
| 96 | } | |||
| 97 | } | |||
| 98 | ||||
| 99 | #endif // EFI_ENGINE_CONTROL | |||
| 100 |