rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
BoostController Class Reference

#include <boost_control.h>

Inheritance diagram for BoostController:
Inheritance graph
[legend]
Collaboration diagram for BoostController:
Collaboration graph
[legend]

Public Member Functions

void init (IPwm *const pmw, const ValueProvider3D *const openLoopMap, const ValueProvider3D *const closedLoopTargetMap, const ValueProvider2D &cltMultiplierProvider, const ValueProvider2D &iatMultiplierProvider, const ValueProvider2D &cltAdderProvider, const ValueProvider2D &iatAdderProvider, pid_s *const pidParams)
 
void onFastCallback () override
 
void setDefaultConfiguration () override
 
void resetLua ()
 
void onConfigurationChange (engine_configuration_s const *previousConfig) override
 
expected< floatobservePlant () override
 
expected< floatgetSetpoint () override
 
expected< percent_tgetOpenLoop (float target) override
 
expected< percent_tgetClosedLoop (float target, float manifoldPressure) override
 
void setOutput (expected< percent_t > outputValue) override
 
- Public Member Functions inherited from EngineModule
virtual void initNoConfiguration ()
 
virtual void onSlowCallback ()
 
virtual void onEngineStop ()
 
virtual void onIgnitionStateChanged (bool)
 
virtual bool needsDelayedShutoff ()
 
virtual void onEnginePhase (float, efitick_t, angle_t, angle_t)
 
- Public Member Functions inherited from ClosedLoopController< float, percent_t >
void update ()
 

Private Member Functions

percent_t getClosedLoopImpl (float target, float manifoldPressure)
 
float getBoostControlDutyCycleWithTemperatureCorrections (const float rpm, const float driverIntent) const
 
std::optional< floatgetBoostControlTargetTemperatureAdder () const
 
std::optional< floatgetBoostTemperatureCorrection (const SensorType sensorType, const ValueProvider2D &correctionCurve) const
 

Private Attributes

Pid m_pid
 
const ValueProvider3Dm_openLoopMap = nullptr
 
const ValueProvider3Dm_closedLoopTargetMap = nullptr
 
const ValueProvider2Dm_cltBoostCorrMap = nullptr
 
const ValueProvider2Dm_iatBoostCorrMap = nullptr
 
const ValueProvider2Dm_cltBoostAdderMap = nullptr
 
const ValueProvider2Dm_iatBoostAdderMap = nullptr
 
IPwmm_pwm = nullptr
 

Additional Inherited Members

- Data Fields inherited from boost_control_s
bool isTpsInvalid: 1 {}
 
bool m_shouldResetPid: 1 {}
 
bool isBelowClosedLoopThreshold: 1 {}
 
bool isNotClosedLoop: 1 {}
 
bool isZeroRpm: 1 {}
 
bool hasInitBoost: 1 {}
 
bool rpmTooLow: 1 {}
 
bool tpsTooLow: 1 {}
 
bool mapTooLow: 1 {}
 
bool isPlantValid: 1 {}
 
bool isBoostControlled: 1 {}
 
bool unusedBit_11_11: 1 {}
 
bool unusedBit_11_12: 1 {}
 
bool unusedBit_11_13: 1 {}
 
bool unusedBit_11_14: 1 {}
 
bool unusedBit_11_15: 1 {}
 
bool unusedBit_11_16: 1 {}
 
bool unusedBit_11_17: 1 {}
 
bool unusedBit_11_18: 1 {}
 
bool unusedBit_11_19: 1 {}
 
bool unusedBit_11_20: 1 {}
 
bool unusedBit_11_21: 1 {}
 
bool unusedBit_11_22: 1 {}
 
bool unusedBit_11_23: 1 {}
 
bool unusedBit_11_24: 1 {}
 
bool unusedBit_11_25: 1 {}
 
bool unusedBit_11_26: 1 {}
 
bool unusedBit_11_27: 1 {}
 
bool unusedBit_11_28: 1 {}
 
bool unusedBit_11_29: 1 {}
 
bool unusedBit_11_30: 1 {}
 
bool unusedBit_11_31: 1 {}
 
scaled_channel< int16_t, 2, 1 > luaTargetAdd = (int16_t)0
 
uint8_t alignmentFill_at_6 [2] = {}
 
float luaTargetMult = (float)0
 
scaled_channel< int16_t, 30, 1 > boostControlTarget = (int16_t)0
 
uint8_t alignmentFill_at_14 [2] = {}
 
float openLoopPart = (float)0
 
float luaOpenLoopAdd = (float)0
 
scaled_channel< int8_t, 2, 1 > boostControllerClosedLoopPart = (int8_t)0
 
uint8_t alignmentFill_at_25 [1] = {}
 
scaled_channel< int16_t, 100, 1 > boostOutput = (int16_t)0
 

Detailed Description

Definition at line 17 of file boost_control.h.

Member Function Documentation

◆ getBoostControlDutyCycleWithTemperatureCorrections()

float BoostController::getBoostControlDutyCycleWithTemperatureCorrections ( const float  rpm,
const float  driverIntent 
) const
private

Definition at line 197 of file boost_control.cpp.

200 {
201 float result = m_openLoopMap->getValue(rpm, driverIntent);
202 std::optional<float> cltBoostMultiplier = getBoostTemperatureCorrection(SensorType::Clt, *m_cltBoostCorrMap);
203 if (cltBoostMultiplier.has_value()) {
204 result *= cltBoostMultiplier.value();
205 }
206 std::optional<float> iatBoostMultiplier = getBoostTemperatureCorrection(SensorType::Iat, *m_iatBoostCorrMap);
207 if (iatBoostMultiplier.has_value()) {
208 result *= iatBoostMultiplier.value();
209 }
210 return result;
211}
const ValueProvider2D * m_cltBoostCorrMap
const ValueProvider2D * m_iatBoostCorrMap
std::optional< float > getBoostTemperatureCorrection(const SensorType sensorType, const ValueProvider2D &correctionCurve) const
const ValueProvider3D * m_openLoopMap
virtual float getValue(float xColumn, float yRow) const =0
static ProxySensor driverIntent(SensorType::DriverThrottleIntent)

Referenced by getOpenLoop().

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

◆ getBoostControlTargetTemperatureAdder()

std::optional< float > BoostController::getBoostControlTargetTemperatureAdder ( ) const
private

Definition at line 213 of file boost_control.cpp.

213 {
215 const std::optional<float> iatBoostAdder = getBoostTemperatureCorrection(SensorType::Iat, *m_iatBoostAdderMap);
216 if (iatBoostAdder.has_value()) {
217 if (result.has_value()) {
218 result.value() += iatBoostAdder.value();
219 } else {
220 result = iatBoostAdder;
221 }
222 }
223 return result;
224}
const ValueProvider2D * m_iatBoostAdderMap
const ValueProvider2D * m_cltBoostAdderMap

Referenced by getSetpoint().

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

◆ getBoostTemperatureCorrection()

std::optional< float > BoostController::getBoostTemperatureCorrection ( const SensorType  sensorType,
const ValueProvider2D correctionCurve 
) const
private

Definition at line 226 of file boost_control.cpp.

229 {
230 const SensorResult temperature = Sensor::get(sensorType);
231 if (temperature.Valid) {
232 const std::optional<float> boostCorrection = correctionCurve.getValue(temperature.Value);
233 if (boostCorrection.has_value()) {
234 return std::make_optional<float>(boostCorrection.value());
235 }
236 }
237 return {};
238}
virtual SensorResult get() const =0
virtual std::optional< float > getValue(float x) const =0
expected< float > SensorResult
Definition sensor.h:46

Referenced by getBoostControlDutyCycleWithTemperatureCorrections(), and getBoostControlTargetTemperatureAdder().

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

◆ getClosedLoop()

expected< percent_t > BoostController::getClosedLoop ( float  target,
float  manifoldPressure 
)
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 241 of file boost_control.cpp.

241 {
242 boostControllerClosedLoopPart = getClosedLoopImpl(target, manifoldPressure);
243
245
246 boostControlTarget = target;
247
248 return (float)boostControllerClosedLoopPart;
249}
percent_t getClosedLoopImpl(float target, float manifoldPressure)
TunerStudioOutputChannels outputChannels
Definition engine.h:109
void postState(pid_status_s &pidStatus) const
Definition efi_pid.cpp:144
static EngineAccessor engine
Definition engine.h:413
scaled_channel< int16_t, 30, 1 > boostControlTarget
scaled_channel< int8_t, 2, 1 > boostControllerClosedLoopPart
Here is the call graph for this function:

◆ getClosedLoopImpl()

percent_t BoostController::getClosedLoopImpl ( float  target,
float  manifoldPressure 
)
private

Definition at line 167 of file boost_control.cpp.

167 {
168 // If we're in open loop only mode, make no closed loop correction.
170 if (isNotClosedLoop) {
171 return 0;
172 }
173
174 // Reset PID if requested
175 if (m_shouldResetPid) {
176 m_pid.reset();
177 m_shouldResetPid = false;
178 }
179
180 // If the engine isn't running, don't correct.
182 if (isZeroRpm) {
183 m_pid.reset();
184 return 0;
185 }
186
189 // We're below the CL threshold, inhibit CL for now
190 m_pid.reset();
191 return 0;
192 }
193
194 return m_pid.getOutput(target, manifoldPressure, FAST_CALLBACK_PERIOD_MS / 1000.0f);
195}
virtual void reset()
Definition efi_pid.cpp:103
float getOutput(float target, float input)
Definition efi_pid.cpp:56
static float getOrZero(SensorType type)
Definition sensor.h:83
static constexpr engine_configuration_s * engineConfiguration

Referenced by getClosedLoop().

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

◆ getOpenLoop()

expected< percent_t > BoostController::getOpenLoop ( float  target)
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 125 of file boost_control.cpp.

125 {
126 // Boost control open loop doesn't care about target - only TPS/RPM
127 UNUSED(target);
128
131
132 isTpsInvalid = !driverIntent.Valid;
133
134 if (isTpsInvalid) {
135 return unexpected;
136 }
137
138 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_openLoopMap != nullptr, "boost open loop", unexpected);
139 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_cltBoostCorrMap != nullptr, "boost CLT multiplier", unexpected);
140 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_iatBoostCorrMap != nullptr, "boost IAT multiplier", unexpected);
141
143
144#if EFI_ENGINE_CONTROL
145 // Add any blends if configured
146 for (size_t i = 0; i < efi::size(config->boostOpenLoopBlends); i++) {
147 auto result = calculateBlend(config->boostOpenLoopBlends[i], rpm, driverIntent.Value);
148
149 engine->outputChannels.boostOpenLoopBlendParameter[i] = result.BlendParameter;
152 engine->outputChannels.boostOpenLoopBlendYAxis[i] = result.TableYAxis;
153
154 openLoop += result.Value;
155 }
156#endif // EFI_ENGINE_CONTROL
157
158 // Add gear-based adder
160 float gearAdder = engineConfiguration->gearBasedOpenLoopBoostAdder[static_cast<int>(gear) + 1];
161 openLoop += gearAdder;
162
163 openLoopPart = openLoop;
164 return openLoop;
165}
float getBoostControlDutyCycleWithTemperatureCorrections(const float rpm, const float driverIntent) const
static constexpr persistent_config_s * config
BlendResult calculateBlend(blend_table_s &cfg, float rpm, float load)
expected< float > readGppwmChannel(gppwm_channel_e channel)
UNUSED(samplingTimeSeconds)
@ OBD_PCM_Processor_Fault
float percent_t
scaled_channel< int8_t, 2, 1 > gearBasedOpenLoopBoostAdder[TCU_GEAR_COUNT]
scaled_channel< int16_t, 10, 1 > boostOpenLoopBlendParameter[BOOST_BLEND_COUNT]
scaled_channel< uint8_t, 2, 1 > boostOpenLoopBlendBias[BOOST_BLEND_COUNT]
int8_t boostOpenLoopBlendOutput[BOOST_BLEND_COUNT]
scaled_channel< int16_t, 10, 1 > boostOpenLoopBlendYAxis[BOOST_BLEND_COUNT]
Here is the call graph for this function:

◆ getSetpoint()

expected< float > BoostController::getSetpoint ( )
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 81 of file boost_control.cpp.

81 {
82 // If we're in open loop only mode, disregard any target computation.
83 // Open loop needs to work even in case of invalid closed loop config
85 if (isNotClosedLoop) {
88 }
89
91
94
95 if (isTpsInvalid) {
96 return unexpected;
97 }
98
99 efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_closedLoopTargetMap != nullptr, "boost closed loop target", unexpected);
100
101 float target = m_closedLoopTargetMap->getValue(rpm, driverIntent.Value);
102#if EFI_ENGINE_CONTROL
103 // Add any blends if configured
104 for (size_t i = 0; i < efi::size(config->boostClosedLoopBlends); i++) {
105 auto result = calculateBlend(config->boostClosedLoopBlends[i], rpm, driverIntent.Value);
106
107 engine->outputChannels.boostClosedLoopBlendParameter[i] = result.BlendParameter;
110 engine->outputChannels.boostClosedLoopBlendYAxis[i] = result.TableYAxis;
111
112 target += result.Value;
113 }
114#endif //EFI_ENGINE_CONTROL
115
116 target *= luaTargetMult;
117 target += luaTargetAdd;
118 const std::optional<float> temperatureAdder = getBoostControlTargetTemperatureAdder();
119 if (temperatureAdder.has_value()) {
120 target += temperatureAdder.value();
121 }
122 return target;
123}
const ValueProvider3D * m_closedLoopTargetMap
std::optional< float > getBoostControlTargetTemperatureAdder() const
@ DriverThrottleIntent
scaled_channel< int16_t, 2, 1 > luaTargetAdd
scaled_channel< int16_t, 10, 1 > boostClosedLoopBlendYAxis[BOOST_BLEND_COUNT]
scaled_channel< int16_t, 10, 1 > boostClosedLoopBlendParameter[BOOST_BLEND_COUNT]
scaled_channel< uint8_t, 2, 1 > boostClosedLoopBlendBias[BOOST_BLEND_COUNT]
scaled_channel< int16_t, 10, 1 > boostClosedLoopBlendOutput[BOOST_BLEND_COUNT]
Here is the call graph for this function:

◆ init()

void BoostController::init ( IPwm *const  pmw,
const ValueProvider3D *const  openLoopMap,
const ValueProvider3D *const  closedLoopTargetMap,
const ValueProvider2D cltMultiplierProvider,
const ValueProvider2D iatMultiplierProvider,
const ValueProvider2D cltAdderProvider,
const ValueProvider2D iatAdderProvider,
pid_s *const  pidParams 
)

Definition at line 31 of file boost_control.cpp.

40 {
41 m_pwm = pwm;
42 m_openLoopMap = openLoopMap;
43 m_closedLoopTargetMap = closedLoopTargetMap;
44 m_cltBoostCorrMap = &cltMultiplierProvider;
45 m_iatBoostCorrMap = &iatMultiplierProvider;
46 m_cltBoostAdderMap = &cltAdderProvider;
47 m_iatBoostAdderMap = &iatAdderProvider;
48
49 m_pid.initPidClass(pidParams);
50 resetLua();
51
52 hasInitBoost = true;
53}
void initPidClass(pid_s *parameters)
Definition efi_pid.cpp:24

Referenced by initBoostCtrl().

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

◆ observePlant()

expected< float > BoostController::observePlant ( )
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 71 of file boost_control.cpp.

71 {
72 expected<float> map = Sensor::get(SensorType::Map);
73 if (!map.Valid && engineConfiguration->boostType != CLOSED_LOOP) {
74 // if we're in open loop only let's somewhat operate even without valid Map sensor
75 map = 0;
76 }
77 isPlantValid = map.Valid;
78 return map;
79}
Here is the call graph for this function:

◆ onConfigurationChange()

void BoostController::onConfigurationChange ( engine_configuration_s const *  previousConfig)
overridevirtual

Reimplemented from EngineModule.

Definition at line 61 of file boost_control.cpp.

61 {
62#if EFI_PROD_CODE
64#endif
65
66 if (!previousConfig || !m_pid.isSame(&previousConfig->boostPid)) {
67 m_shouldResetPid = true;
68 }
69}
void initBoostCtrl()
bool isSame(const pid_s *parameters) const
Definition efi_pid.cpp:39
Here is the call graph for this function:

◆ onFastCallback()

void BoostController::onFastCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 277 of file boost_control.cpp.

277 {
278 if (!hasInitBoost) {
279 return;
280 }
281
282 m_pid.iTermMin = -20;
283 m_pid.iTermMax = 20;
284
288
290
291 if (!isBoostControlled) {
292 // Passing unexpected will use the safe duty cycle configured by the user
293 setOutput(unexpected);
294 } else {
296 }
297}
void setOutput(expected< percent_t > outputValue) override
float iTermMax
Definition efi_pid.h:69
float iTermMin
Definition efi_pid.h:68
Here is the call graph for this function:

◆ resetLua()

void BoostController::resetLua ( )

Definition at line 55 of file boost_control.cpp.

55 {
56 luaTargetAdd = 0;
57 luaTargetMult = 1;
59}

Referenced by init().

Here is the caller graph for this function:

◆ setDefaultConfiguration()

void BoostController::setDefaultConfiguration ( )
overridevirtual

◆ setOutput()

void BoostController::setOutput ( expected< percent_t outputValue)
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 255 of file boost_control.cpp.

255 {
256 // this clamping is just for happier gauge #6339
257 boostOutput = clampPercentValue(output.value_or(engineConfiguration->boostControlSafeDutyCycle));
258
260 // If not enabled, force 0% output
261 boostOutput = 0;
262 }
263
264 float duty = PERCENT_TO_DUTY(boostOutput);
265
268 } else {
269#if EFI_ELECTRONIC_THROTTLE_BODY
270 // inject wastegate position into DC controllers, pretty weird workflow to be honest
271 // todo: should it be DC controller pulling?
273#endif // EFI_ELECTRONIC_THROTTLE_BODY
274 }
275}
bool isBoostControlSolenoidMode()
void setEtbWastegatePosition(percent_t pos)
virtual void setSimplePwmDutyCycle(float dutyCycle)=0
scaled_channel< int16_t, 100, 1 > boostOutput
static float duty

Referenced by onFastCallback().

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

Field Documentation

◆ m_closedLoopTargetMap

const ValueProvider3D* BoostController::m_closedLoopTargetMap = nullptr
private

Definition at line 60 of file boost_control.h.

Referenced by getSetpoint(), and init().

◆ m_cltBoostAdderMap

const ValueProvider2D* BoostController::m_cltBoostAdderMap = nullptr
private

Definition at line 63 of file boost_control.h.

Referenced by getBoostControlTargetTemperatureAdder(), and init().

◆ m_cltBoostCorrMap

const ValueProvider2D* BoostController::m_cltBoostCorrMap = nullptr
private

◆ m_iatBoostAdderMap

const ValueProvider2D* BoostController::m_iatBoostAdderMap = nullptr
private

Definition at line 64 of file boost_control.h.

Referenced by getBoostControlTargetTemperatureAdder(), and init().

◆ m_iatBoostCorrMap

const ValueProvider2D* BoostController::m_iatBoostCorrMap = nullptr
private

◆ m_openLoopMap

const ValueProvider3D* BoostController::m_openLoopMap = nullptr
private

◆ m_pid

Pid BoostController::m_pid
private

◆ m_pwm

IPwm* BoostController::m_pwm = nullptr
private

Definition at line 65 of file boost_control.h.

Referenced by init(), and setOutput().


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