rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
airmass.cpp
Go to the documentation of this file.
1#include "pch.h"
2
3#include "airmass.h"
4#include "idle_thread.h"
5
6AirmassVeModelBase::AirmassVeModelBase(const ValueProvider3D& veTable) : m_veTable(&veTable) {}
7
8float getVeLoadAxis(ve_override_e mode, float passedLoad) {
9 switch(mode) {
10 case VE_None: return passedLoad;
11 case VE_MAP: return Sensor::getOrZero(SensorType::Map);
12 case VE_TPS: return Sensor::getOrZero(SensorType::Tps1);
13 default: return 0;
14 }
15}
16
17float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const {
18 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0);
19
20 // Override the load value if necessary
22
23 percent_t ve = m_veTable->getValue(rpm, load);
24
25#if EFI_IDLE_CONTROL
26 auto tps = Sensor::get(SensorType::Tps1);
27 // get VE from the separate table for Idle if idling
30 float idleVeLoad = getVeLoadAxis(engineConfiguration->idleVeOverrideMode, load);
31
32 percent_t idleVe = interpolate3d(
34 config->idleVeLoadBins, idleVeLoad,
36 );
37
38 // interpolate between idle table and normal (running) table using TPS threshold
39 // 0 TPS -> idle table
40 // 1/2 threshold -> idle table
41 // idle threshold -> normal table
43 ve = interpolateClamped(idleThreshold / 2, idleVe, idleThreshold, ve, tps.Value);
44 }
45#endif // EFI_IDLE_CONTROL
46
47 // Add any adjustments if configured
48 for (size_t i = 0; i < efi::size(config->veBlends); i++) {
49 auto result = calculateBlend(config->veBlends[i], rpm, load);
50
51 if (postState) {
52 engine->outputChannels.veBlendParameter[i] = result.BlendParameter;
53 engine->outputChannels.veBlendBias[i] = result.Bias;
54 engine->outputChannels.veBlendOutput[i] = result.Value;
55 engine->outputChannels.veBlendYAxis[i] = result.TableYAxis;
56 }
57
58 // Skip extra floating point math if we can...
59 if (result.Value == 0) {
60 continue;
61 }
62
63 // Apply as a multiplier, not as an adder
64 // Value of +5 means add 5%, aka multiply by 1.05
65 ve *= ((100 + result.Value) * 0.01f);
66 }
67
68 if (postState) {
71 }
72
73 return ve * PERCENT_DIV;
74}
float getVeLoadAxis(ve_override_e mode, float passedLoad)
Definition airmass.cpp:8
float getVeLoadAxis(ve_override_e mode, float passedLoad)
Definition airmass.cpp:8
float getVe(float rpm, percent_t load, bool postState) const
Definition airmass.cpp:17
const ValueProvider3D *const m_veTable
Definition airmass.h:23
AirmassVeModelBase(const ValueProvider3D &veTable)
Definition airmass.cpp:6
EngineState engineState
Definition engine.h:344
TunerStudioOutputChannels outputChannels
Definition engine.h:109
constexpr auto & module()
Definition engine.h:200
bool isIdlingOrTaper() const override
Definition idle_thread.h:88
virtual SensorResult get() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
virtual float getValue(float xColumn, float yRow) const =0
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
static EngineAccessor engine
Definition engine.h:413
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
BlendResult calculateBlend(blend_table_s &cfg, float rpm, float load)
Idle Valve Control thread.
@ OBD_PCM_Processor_Fault
ve_override_e
scaled_channel< uint16_t, 100, 1 > veTableYAxis
scaled_channel< int16_t, 10, 1 > veBlendParameter[VE_BLEND_COUNT]
scaled_channel< uint8_t, 2, 1 > veBlendBias[VE_BLEND_COUNT]
scaled_channel< int16_t, 10, 1 > veBlendYAxis[VE_BLEND_COUNT]
scaled_channel< int16_t, 100, 1 > veBlendOutput[VE_BLEND_COUNT]
scaled_channel< uint8_t, 1, 10 > idleVeRpmBins[IDLE_VE_SIZE]
scaled_channel< uint16_t, 10, 1 > idleVeTable[IDLE_VE_SIZE][IDLE_VE_SIZE]