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 float idleVeLoad = load;
25
26#if EFI_IDLE_CONTROL
27 auto tps = Sensor::get(SensorType::Tps1);
28 // get VE from the separate table for Idle if idling
32
33 percent_t idleVe = interpolate3d(
35 config->idleVeLoadBins, idleVeLoad,
37 );
38
39 // interpolate between idle table and normal (running) table using TPS threshold
40 // 0 TPS -> idle table
41 // 1/2 threshold -> idle table
42 // idle threshold -> normal table
44 ve = interpolateClamped(idleThreshold / 2, idleVe, idleThreshold, ve, tps.Value);
45 }
46#endif // EFI_IDLE_CONTROL
47
48 // Add any adjustments if configured
49 for (size_t i = 0; i < efi::size(config->veBlends); i++) {
50 auto result = calculateBlend(config->veBlends[i], rpm, load);
51
52 if (postState) {
53 engine->outputChannels.veBlendParameter[i] = result.BlendParameter;
54 engine->outputChannels.veBlendBias[i] = result.Bias;
55 engine->outputChannels.veBlendOutput[i] = result.Value;
56 engine->outputChannels.veBlendYAxis[i] = result.TableYAxis;
57 }
58
59 // Skip extra floating point math if we can...
60 if (result.Value == 0) {
61 continue;
62 }
63
64 // Apply as a multiplier, not as an adder
65 // Value of +5 means add 5%, aka multiply by 1.05
66 ve *= ((100 + result.Value) * 0.01f);
67 }
68
69 if (postState) {
73 }
74
75 return ve * PERCENT_DIV;
76}
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< int16_t, 10, 1 > veTableIdleYAxis
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_RPM]
scaled_channel< uint16_t, 10, 1 > idleVeTable[IDLE_VE_SIZE][IDLE_VE_SIZE_RPM]