rusEFI
The most advanced open source ECU
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 *pmw, const ValueProvider3D *openLoopMap, const ValueProvider3D *closedLoopTargetMap, pid_s *pidParams)
 
void onFastCallback () override
 
void resetLua ()
 
void onConfigurationChange (engine_configuration_s const *previousConfig) override
 
expected< float > observePlant () override
 
expected< float > getSetpoint () 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 onSlowCallback ()
 
virtual void onIgnitionStateChanged (bool)
 
virtual bool needsDelayedShutoff ()
 
- Public Member Functions inherited from ClosedLoopController< float, percent_t >
expected< percent_tupdate ()
 

Private Member Functions

percent_t getClosedLoopImpl (float target, float manifoldPressure)
 

Private Attributes

Pid m_pid
 
const ValueProvider3Dm_openLoopMap = nullptr
 
const ValueProvider3Dm_closedLoopTargetMap = 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
 
scaled_channel< int16_t, 100, 1 > boostOutput = (int16_t)0
 
float luaTargetMult = (float)0
 
float openLoopPart = (float)0
 
float luaOpenLoopAdd = (float)0
 
scaled_channel< int8_t, 2, 1 > boostControllerClosedLoopPart = (int8_t)0
 
uint8_t alignmentFill_at_21 [1]
 
scaled_channel< int16_t, 30, 1 > boostControlTarget = (int16_t)0
 

Detailed Description

Definition at line 16 of file boost_control.h.

Member Function Documentation

◆ getClosedLoop()

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

Implements ClosedLoopController< float, percent_t >.

Definition at line 163 of file boost_control.cpp.

163  {
164  boostControllerClosedLoopPart = getClosedLoopImpl(target, manifoldPressure);
165 
167 
168  boostControlTarget = target;
169 
170  return (float)boostControllerClosedLoopPart;
171 }
percent_t getClosedLoopImpl(float target, float manifoldPressure)
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
void postState(pid_status_s &pidStatus) const
Definition: efi_pid.cpp:135
Engine * engine
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 133 of file boost_control.cpp.

133  {
134  // If we're in open loop only mode, make no closed loop correction.
136  if (isNotClosedLoop) {
137  return 0;
138  }
139 
140  // Reset PID if requested
141  if (m_shouldResetPid) {
142  m_pid.reset();
143  m_shouldResetPid = false;
144  }
145 
146  // If the engine isn't running, don't correct.
148  if (isZeroRpm) {
149  m_pid.reset();
150  return 0;
151  }
152 
155  // We're below the CL threshold, inhibit CL for now
156  m_pid.reset();
157  return 0;
158  }
159 
160  return m_pid.getOutput(target, manifoldPressure, FAST_CALLBACK_PERIOD_MS / 1000.0f);
161 }
virtual void reset()
Definition: efi_pid.cpp:94
float getOutput(float target, float input)
Definition: efi_pid.cpp:48
static float getOrZero(SensorType type)
Definition: sensor.h:92
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 94 of file boost_control.cpp.

94  {
95  // Boost control open loop doesn't care about target - only TPS/RPM
96  UNUSED(target);
97 
100 
101  isTpsInvalid = !driverIntent.Valid;
102 
103  if (isTpsInvalid) {
104  return unexpected;
105  }
106 
107  efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_openLoopMap != nullptr, "boost open loop", unexpected);
108 
109  percent_t openLoop = luaOpenLoopAdd + m_openLoopMap->getValue(rpm, driverIntent.Value);
110 
111 #if EFI_ENGINE_CONTROL
112  // Add any blends if configured
113  for (size_t i = 0; i < efi::size(config->boostOpenLoopBlends); i++) {
114  auto result = calculateBlend(config->boostOpenLoopBlends[i], rpm, driverIntent.Value);
115 
116  engine->outputChannels.boostOpenLoopBlendParameter[i] = result.BlendParameter;
117  engine->outputChannels.boostOpenLoopBlendBias[i] = result.Bias;
119 
120  openLoop += result.Value;
121  }
122 #endif // EFI_ENGINE_CONTROL
123 
124  // Add gear-based adder
126  float gearAdder = engineConfiguration->gearBasedOpenLoopBoostAdder[static_cast<int>(gear) + 1];
127  openLoop += gearAdder;
128 
129  openLoopPart = openLoop;
130  return openLoop;
131 }
const ValueProvider3D * m_openLoopMap
Definition: boost_control.h:41
virtual SensorResult get() const =0
virtual float getValue(float xColumn, float yRow) const =0
BlendResult calculateBlend(blend_table_s &cfg, float rpm, float load)
static ProxySensor driverIntent(SensorType::DriverThrottleIntent)
UNUSED(samplingTimeSeconds)
@ OBD_PCM_Processor_Fault
persistent_config_s * config
float percent_t
Definition: rusefi_types.h:73
@ DriverThrottleIntent
scaled_channel< uint8_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]
scaled_channel< int8_t, 1, 1 > boostOpenLoopBlendOutput[BOOST_BLEND_COUNT]
blend_table_s boostOpenLoopBlends[BOOST_BLEND_COUNT]
composite packet size
Here is the call graph for this function:

◆ getSetpoint()

expected< float > BoostController::getSetpoint ( )
overridevirtual

Implements ClosedLoopController< float, percent_t >.

Definition at line 57 of file boost_control.cpp.

57  {
58  // If we're in open loop only mode, disregard any target computation.
59  // Open loop needs to work even in case of invalid closed loop config
61  if (isNotClosedLoop) {
63  return (float)boostControllerClosedLoopPart;
64  }
65 
67 
69  isTpsInvalid = !driverIntent.Valid;
70 
71  if (isTpsInvalid) {
72  return unexpected;
73  }
74 
75  efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_closedLoopTargetMap != nullptr, "boost closed loop target", unexpected);
76 
77  float target = m_closedLoopTargetMap->getValue(rpm, driverIntent.Value);
78 #if EFI_ENGINE_CONTROL
79  // Add any blends if configured
80  for (size_t i = 0; i < efi::size(config->boostClosedLoopBlends); i++) {
81  auto result = calculateBlend(config->boostClosedLoopBlends[i], rpm, driverIntent.Value);
82 
83  engine->outputChannels.boostClosedLoopBlendParameter[i] = result.BlendParameter;
86 
87  target += result.Value;
88  }
89 #endif //EFI_ENGINE_CONTROL
90 
91  return target * luaTargetMult + luaTargetAdd;
92 }
const ValueProvider3D * m_closedLoopTargetMap
Definition: boost_control.h:42
scaled_channel< int16_t, 2, 1 > luaTargetAdd
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]
blend_table_s boostClosedLoopBlends[BOOST_BLEND_COUNT]
Here is the call graph for this function:

◆ init()

void BoostController::init ( IPwm pmw,
const ValueProvider3D openLoopMap,
const ValueProvider3D closedLoopTargetMap,
pid_s pidParams 
)

Definition at line 24 of file boost_control.cpp.

24  {
25  m_pwm = pwm;
26  m_openLoopMap = openLoopMap;
27  m_closedLoopTargetMap = closedLoopTargetMap;
28 
29  m_pid.initPidClass(pidParams);
30  resetLua();
31 
32  hasInitBoost = true;
33 }
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 47 of file boost_control.cpp.

47  {
48  expected<float> map = Sensor::get(SensorType::Map);
49  if (!map.Valid && engineConfiguration->boostType != CLOSED_LOOP) {
50  // if we're in open loop only let's somewhat operate even without valid Map sensor
51  map = 0;
52  }
53  isPlantValid = map.Valid;
54  return map;
55 }
Here is the call graph for this function:

◆ onConfigurationChange()

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

Reimplemented from EngineModule.

Definition at line 41 of file boost_control.cpp.

41  {
42  if (!previousConfig || !m_pid.isSame(&previousConfig->boostPid)) {
43  m_shouldResetPid = true;
44  }
45 }
bool isSame(const pid_s *parameters) const
Definition: efi_pid.cpp:31
Here is the call graph for this function:

◆ onFastCallback()

void BoostController::onFastCallback ( )
overridevirtual

Reimplemented from EngineModule.

Definition at line 195 of file boost_control.cpp.

195  {
196  if (!hasInitBoost) {
197  return;
198  }
199 
200  m_pid.iTermMin = -20;
201  m_pid.iTermMax = 20;
202 
206 
208 
209  if (!isBoostControlled) {
210  // Passing unexpected will use the safe duty cycle configured by the user
211  setOutput(unexpected);
212  } else {
214  }
215 }
void setOutput(expected< percent_t > outputValue) override
expected< TOutput > update()
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 35 of file boost_control.cpp.

35  {
36  luaTargetAdd = 0;
37  luaTargetMult = 1;
38  luaOpenLoopAdd = 0;
39 }

Referenced by init().

Here is the caller graph for this function:

◆ setOutput()

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

Implements ClosedLoopController< float, percent_t >.

Definition at line 173 of file boost_control.cpp.

173  {
174  // this clamping is just for happier gauge #6339
175  boostOutput = clampPercentValue(output.value_or(engineConfiguration->boostControlSafeDutyCycle));
176 
178  // If not enabled, force 0% output
179  boostOutput = 0;
180  }
181 
182  float duty = PERCENT_TO_DUTY(boostOutput);
183 
184  if (m_pwm) {
186  }
187 
188 #if EFI_ELECTRONIC_THROTTLE_BODY
189  // inject wastegate position into DC controllers, pretty weird workflow to be honest
190  // todo: should it be DC controller pulling?
192 #endif // EFI_ELECTRONIC_THROTTLE_BODY
193 }
void setEtbWastegatePosition(percent_t pos)
virtual void setSimplePwmDutyCycle(float dutyCycle)=0
scaled_channel< int16_t, 100, 1 > boostOutput
static float duty
Definition: tachometer.cpp:17

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 42 of file boost_control.h.

Referenced by getSetpoint(), and init().

◆ m_openLoopMap

const ValueProvider3D* BoostController::m_openLoopMap = nullptr
private

Definition at line 41 of file boost_control.h.

Referenced by getOpenLoop(), and init().

◆ m_pid

Pid BoostController::m_pid
private

◆ m_pwm

IPwm* BoostController::m_pwm = nullptr
private

Definition at line 43 of file boost_control.h.

Referenced by init(), and setOutput().


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