boost fixes (#2230)

* fix boost pin reinit

* call boost from periodic slow

* ui

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-01-18 04:04:14 -08:00 committed by GitHub
parent 84cacc86bd
commit fa30efbc94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 38 deletions

View File

@ -40,21 +40,12 @@ void BoostController::init(SimplePwm* pwm, const ValueProvider3D* openLoopMap, c
m_pid.initPidClass(pidParams); m_pid.initPidClass(pidParams);
} }
void BoostController::reset() {
m_shouldResetPid = true;
}
void BoostController::onConfigurationChange(pid_s* previousConfiguration) { void BoostController::onConfigurationChange(pid_s* previousConfiguration) {
if (!m_pid.isSame(previousConfiguration)) { if (!m_pid.isSame(previousConfiguration)) {
m_shouldResetPid = true; m_shouldResetPid = true;
} }
} }
int BoostController::getPeriodMs() {
return GET_PERIOD_LIMITED(&engineConfiguration->boostPid);
}
expected<float> BoostController::observePlant() const { expected<float> BoostController::observePlant() const {
return Sensor::get(SensorType::Map); return Sensor::get(SensorType::Map);
} }
@ -125,7 +116,7 @@ expected<percent_t> BoostController::getClosedLoop(float target, float manifoldP
return 0; return 0;
} }
float closedLoop = m_pid.getOutput(target, manifoldPressure); float closedLoop = m_pid.getOutput(target, manifoldPressure, SLOW_CALLBACK_PERIOD_MS / 1000.0f);
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
if (engineConfiguration->debugMode == DBG_BOOST) { if (engineConfiguration->debugMode == DBG_BOOST) {
@ -149,23 +140,29 @@ void BoostController::setOutput(expected<float> output) {
setEtbWastegatePosition(percent PASS_ENGINE_PARAMETER_SUFFIX); setEtbWastegatePosition(percent PASS_ENGINE_PARAMETER_SUFFIX);
} }
void BoostController::PeriodicTask() { void BoostController::update() {
m_pid.iTermMin = -50; m_pid.iTermMin = -50;
m_pid.iTermMax = 50; m_pid.iTermMax = 50;
update(); ClosedLoopController::update();
} }
BoostController boostController; static BoostController boostController;
static bool hasInitBoost = false;
void updateBoostControl() {
if (hasInitBoost) {
boostController.update();
}
}
void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) { void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->boostPwmFrequency = 55; engineConfiguration->boostPwmFrequency = 33;
engineConfiguration->boostPid.offset = 0; engineConfiguration->boostPid.offset = 0;
engineConfiguration->boostPid.pFactor = 0.5; engineConfiguration->boostPid.pFactor = 0.5;
engineConfiguration->boostPid.iFactor = 0.3; engineConfiguration->boostPid.iFactor = 0.3;
engineConfiguration->boostPid.periodMs = 100; engineConfiguration->boostPid.maxValue = 20;
engineConfiguration->boostPid.maxValue = 99; engineConfiguration->boostPid.minValue = -20;
engineConfiguration->boostPid.minValue = -99;
engineConfiguration->boostControlPin = GPIO_UNASSIGNED; engineConfiguration->boostControlPin = GPIO_UNASSIGNED;
engineConfiguration->boostControlPinMode = OM_DEFAULT; engineConfiguration->boostControlPinMode = OM_DEFAULT;
@ -203,12 +200,6 @@ void startBoostPin() {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
} }
void stopBoostPin() {
#if !EFI_UNIT_TEST
efiSetPadUnused(activeConfiguration.boostControlPin);
#endif /* EFI_UNIT_TEST */
}
void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration) { void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration) {
boostController.onConfigurationChange(&previousConfiguration->boostPid); boostController.onConfigurationChange(&previousConfiguration->boostPid);
} }
@ -242,7 +233,7 @@ void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
startBoostPin(); startBoostPin();
boostController.Start(); hasInitBoost = true;
#endif #endif
} }

View File

@ -13,16 +13,12 @@
class SimplePwm; class SimplePwm;
class BoostController : public ClosedLoopController<float, percent_t>, public PeriodicTimerController { class BoostController : public ClosedLoopController<float, percent_t> {
public: public:
DECLARE_ENGINE_PTR; DECLARE_ENGINE_PTR;
void init(SimplePwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams); void init(SimplePwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams);
void update();
// PeriodicTimerController implementation
int getPeriodMs() override;
void PeriodicTask() override;
void reset();
// Called when the configuration may have changed. Controller will // Called when the configuration may have changed. Controller will
// reset if necessary. // reset if necessary.
@ -47,7 +43,8 @@ private:
}; };
void startBoostPin(); void startBoostPin();
void stopBoostPin();
void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE); void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration); void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration);
void updateBoostControl();

View File

@ -33,6 +33,7 @@
#include "gppwm.h" #include "gppwm.h"
#include "tachometer.h" #include "tachometer.h"
#include "dynoview.h" #include "dynoview.h"
#include "boost_control.h"
#if EFI_MC33816 #if EFI_MC33816
#include "mc33816.h" #include "mc33816.h"
#endif // EFI_MC33816 #endif // EFI_MC33816
@ -193,6 +194,10 @@ void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
updateIdleControl(); updateIdleControl();
#if EFI_BOOST_CONTROL
updateBoostControl();
#endif // EFI_BOOST_CONTROL
cylinderCleanupControl(PASS_ENGINE_PARAMETER_SIGNATURE); cylinderCleanupControl(PASS_ENGINE_PARAMETER_SIGNATURE);
standardAirCharge = getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE); standardAirCharge = getStandardAirCharge(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -379,9 +379,6 @@ void applyNewHardwareSettings(void) {
stopHD44780_pins(); stopHD44780_pins();
#endif /* #if EFI_HD44780_LCD */ #endif /* #if EFI_HD44780_LCD */
#if EFI_BOOST_CONTROL
stopBoostPin();
#endif
if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) { if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) {
efiSetPadUnused(activeConfiguration.clutchUpPin); efiSetPadUnused(activeConfiguration.clutchUpPin);
} }

View File

@ -3171,9 +3171,8 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
field = "P Gain", boostPid_pFactor, { isBoostControlEnabled && boostType == 1 } field = "P Gain", boostPid_pFactor, { isBoostControlEnabled && boostType == 1 }
field = "I Gain", boostPid_iFactor, { isBoostControlEnabled && boostType == 1 } field = "I Gain", boostPid_iFactor, { isBoostControlEnabled && boostType == 1 }
field = "D Gain", boostPid_dFactor, { isBoostControlEnabled && boostType == 1 } field = "D Gain", boostPid_dFactor, { isBoostControlEnabled && boostType == 1 }
field = "Control Period", boostPid_periodMs, { isBoostControlEnabled && boostType == 1 } field = "Min adjustment", boostPid_minValue, { isBoostControlEnabled && boostType == 1 }
field = "Min Duty", boostPid_minValue, { isBoostControlEnabled && boostType == 1 } field = "Max adjustment", boostPid_maxValue, { isBoostControlEnabled && boostType == 1 }
field = "Max Duty", boostPid_maxValue, { isBoostControlEnabled && boostType == 1 }
dialog = boostTableDialog, "", card dialog = boostTableDialog, "", card
panel = boostTable2Tbl panel = boostTable2Tbl