* boost is engine module

* only:idle leaves outputs

---------

Co-authored-by: Matthew Kennedy <matthewkennedy@outlook.com>
This commit is contained in:
rusefillc 2023-09-26 13:39:43 -04:00 committed by GitHub
parent 903d7c1025
commit e19204dd2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 33 deletions

View File

@ -55,7 +55,7 @@ const injector_model_s* getLiveData(size_t) {
template<> template<>
const boost_control_s* getLiveData(size_t) { const boost_control_s* getLiveData(size_t) {
#if EFI_BOOST_CONTROL #if EFI_BOOST_CONTROL
return &engine->boostController; return &engine->module<BoostController>().unmock();
#else #else
return nullptr; return nullptr;
#endif #endif

View File

@ -29,6 +29,8 @@ void BoostController::init(IPwm* pwm, const ValueProvider3D* openLoopMap, const
m_pid.initPidClass(pidParams); m_pid.initPidClass(pidParams);
resetLua(); resetLua();
hasInitBoost = true;
} }
void BoostController::resetLua() { void BoostController::resetLua() {
@ -37,8 +39,8 @@ void BoostController::resetLua() {
luaOpenLoopAdd = 0; luaOpenLoopAdd = 0;
} }
void BoostController::onConfigurationChange(pid_s* previousConfiguration) { void BoostController::onConfigurationChange(engine_configuration_s const * previousConfig) {
if (!m_pid.isSame(previousConfiguration)) { if (!m_pid.isSame(&previousConfig->boostPid)) {
m_shouldResetPid = true; m_shouldResetPid = true;
} }
} }
@ -179,7 +181,7 @@ void BoostController::setOutput(expected<float> output) {
setEtbWastegatePosition(boostOutput); setEtbWastegatePosition(boostOutput);
} }
void BoostController::update() { void BoostController::onFastCallback() {
if (!hasInitBoost) { if (!hasInitBoost) {
return; return;
} }
@ -242,10 +244,6 @@ void startBoostPin() {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
} }
void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration) {
engine->boostController.onConfigurationChange(&previousConfiguration->boostPid);
}
void initBoostCtrl() { void initBoostCtrl() {
// todo: why do we have 'isBoostControlEnabled' setting exactly? // todo: why do we have 'isBoostControlEnabled' setting exactly?
// 'initVvtActuators' is an example of a subsystem without explicit enable // 'initVvtActuators' is an example of a subsystem without explicit enable
@ -269,12 +267,11 @@ void initBoostCtrl() {
boostMapClosed.init(config->boostTableClosedLoop, config->boostTpsBins, config->boostRpmBins); boostMapClosed.init(config->boostTableClosedLoop, config->boostTpsBins, config->boostRpmBins);
// Set up boost controller instance // Set up boost controller instance
engine->boostController.init(&boostPwmControl, &boostMapOpen, &boostMapClosed, &engineConfiguration->boostPid); engine->module<BoostController>().unmock().init(&boostPwmControl, &boostMapOpen, &boostMapClosed, &engineConfiguration->boostPid);
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
startBoostPin(); startBoostPin();
#endif #endif
engine->boostController.hasInitBoost = true;
} }
#endif #endif

View File

@ -13,15 +13,16 @@
struct IPwm; struct IPwm;
class BoostController : public boost_control_s, public ClosedLoopController<float, percent_t> { class BoostController : public EngineModule, public boost_control_s, public ClosedLoopController<float, percent_t> {
public: public:
void init(IPwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams); void init(IPwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams);
void update();
void onFastCallback() override;
void resetLua(); void resetLua();
// Called when the configuration may have changed. Controller will // Called when the configuration may have changed. Controller will
// reset if necessary. // reset if necessary.
void onConfigurationChange(pid_s* previousConfiguration); void onConfigurationChange(engine_configuration_s const * previousConfig) override;
// Helpers for individual parts of boost control // Helpers for individual parts of boost control
expected<float> observePlant() const override; expected<float> observePlant() const override;
@ -45,4 +46,3 @@ private:
void startBoostPin(); void startBoostPin();
void initBoostCtrl(); void initBoostCtrl();
void setDefaultBoostParameters(); void setDefaultBoostParameters();
void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration);

View File

@ -306,7 +306,7 @@ void Engine::resetLua() {
engineState.lua.luaDisableEtb = false; engineState.lua.luaDisableEtb = false;
engineState.lua.luaIgnCut = false; engineState.lua.luaIgnCut = false;
#if EFI_BOOST_CONTROL #if EFI_BOOST_CONTROL
boostController.resetLua(); module<BoostController>().unmock().resetLua();
#endif // EFI_BOOST_CONTROL #endif // EFI_BOOST_CONTROL
ignitionState.luaTimingAdd = 0; ignitionState.luaTimingAdd = 0;
ignitionState.luaTimingMult = 1; ignitionState.luaTimingMult = 1;
@ -548,10 +548,6 @@ void Engine::periodicFastCallback() {
tachSignalCallback(); tachSignalCallback();
engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); }); engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); });
#if EFI_BOOST_CONTROL
engine->boostController.update();
#endif // EFI_BOOST_CONTROL
} }
EngineRotationState * getEngineRotationState() { EngineRotationState * getEngineRotationState() {

View File

@ -164,6 +164,9 @@ public:
VvtController3, VvtController3,
VvtController4, VvtController4,
#endif // EFI_VVT_PID #endif // EFI_VVT_PID
#if EFI_BOOST_CONTROL
BoostController,
#endif // EFI_BOOST_CONTROL
EngineModule // dummy placeholder so the previous entries can all have commas EngineModule // dummy placeholder so the previous entries can all have commas
> engineModules; > engineModules;
@ -198,10 +201,6 @@ public:
SoftSparkLimiter ALSsoftSparkLimiter; SoftSparkLimiter ALSsoftSparkLimiter;
#endif /* EFI_ANTILAG_SYSTEM */ #endif /* EFI_ANTILAG_SYSTEM */
#if EFI_BOOST_CONTROL
BoostController boostController;
#endif // EFI_BOOST_CONTROL
LambdaMonitor lambdaMonitor; LambdaMonitor lambdaMonitor;
IgnitionState ignitionState; IgnitionState ignitionState;

View File

@ -185,17 +185,11 @@ void incrementGlobalConfigurationVersion(const char * msg) {
boardOnConfigurationChange(&activeConfiguration); boardOnConfigurationChange(&activeConfiguration);
/**
* All these callbacks could be implemented as listeners, but these days I am saving RAM
*/
engine->preCalculate(); engine->preCalculate();
#if EFI_ALTERNATOR_CONTROL #if EFI_ALTERNATOR_CONTROL
onConfigurationChangeAlternatorCallback(&activeConfiguration); onConfigurationChangeAlternatorCallback(&activeConfiguration);
#endif /* EFI_ALTERNATOR_CONTROL */ #endif /* EFI_ALTERNATOR_CONTROL */
#if EFI_BOOST_CONTROL
onConfigurationChangeBoostCallback(&activeConfiguration);
#endif
#if EFI_ELECTRONIC_THROTTLE_BODY #if EFI_ELECTRONIC_THROTTLE_BODY
onConfigurationChangeElectronicThrottleCallback(&activeConfiguration); onConfigurationChangeElectronicThrottleCallback(&activeConfiguration);
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #endif /* EFI_ELECTRONIC_THROTTLE_BODY */

View File

@ -773,15 +773,15 @@ void configureRusefiLuaHooks(lua_State* l) {
#if EFI_BOOST_CONTROL #if EFI_BOOST_CONTROL
lua_register(l, "setBoostTargetAdd", [](lua_State* l) { lua_register(l, "setBoostTargetAdd", [](lua_State* l) {
engine->boostController.luaTargetAdd = luaL_checknumber(l, 1); engine->module<BoostController>().unmock().luaTargetAdd = luaL_checknumber(l, 1);
return 0; return 0;
}); });
lua_register(l, "setBoostTargetMult", [](lua_State* l) { lua_register(l, "setBoostTargetMult", [](lua_State* l) {
engine->boostController.luaTargetMult = luaL_checknumber(l, 1); engine->module<BoostController>().unmock().luaTargetMult = luaL_checknumber(l, 1);
return 0; return 0;
}); });
lua_register(l, "setBoostDutyAdd", [](lua_State* l) { lua_register(l, "setBoostDutyAdd", [](lua_State* l) {
engine->boostController.luaOpenLoopAdd = luaL_checknumber(l, 1); engine->module<BoostController>().unmock().luaOpenLoopAdd = luaL_checknumber(l, 1);
return 0; return 0;
}); });
#endif // EFI_BOOST_CONTROL #endif // EFI_BOOST_CONTROL

View File

@ -74,7 +74,8 @@ Usages:
folder: controllers/actuators folder: controllers/actuators
prepend: integration/rusefi_config_shared.txt prepend: integration/rusefi_config_shared.txt
output_name: boost output_name: boost
constexpr: "engine->boostController" constexpr: "___engine.module<BoostController>()"
isPtr: true
conditional_compilation: "EFI_BOOST_CONTROL" conditional_compilation: "EFI_BOOST_CONTROL"
- name: ac_control - name: ac_control