boost format & cleanup (#1126)
This commit is contained in:
parent
9517da33c3
commit
20465107ed
|
@ -40,78 +40,67 @@ static SimplePwm boostPwmControl("boost");
|
|||
static pid_s *boostPidS = &persistentState.persistentConfiguration.engineConfiguration.boostPid;
|
||||
static Pid boostControlPid(boostPidS);
|
||||
|
||||
|
||||
static bool shouldResetPid = false;
|
||||
|
||||
#if EFI_TUNER_STUDIO
|
||||
extern TunerStudioOutputChannels tsOutputChannels;
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
|
||||
|
||||
static void pidReset(void) {
|
||||
boostControlPid.reset();
|
||||
}
|
||||
|
||||
|
||||
class BoostControl: public PeriodicTimerController {
|
||||
int getPeriodMs()
|
||||
override {
|
||||
int getPeriodMs() override {
|
||||
return GET_PERIOD_LIMITED(&engineConfiguration->boostPid);
|
||||
}
|
||||
|
||||
void PeriodicTask() override {
|
||||
if (shouldResetPid) {
|
||||
pidReset();
|
||||
shouldResetPid = false;
|
||||
}
|
||||
|
||||
#if EFI_TUNER_STUDIO
|
||||
boostControlPid.postState(&tsOutputChannels);
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
float rpm = GET_RPM_VALUE;
|
||||
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
if (!engineConfiguration->isBoostControlEnabled)
|
||||
return;
|
||||
bool enabledAtEngineRunning = rpm > engineConfiguration->cranking.rpm;
|
||||
if (!enabledAtEngineRunning) {
|
||||
boostControlPid.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
percent_t openLoopDuty = boostMapOpen.getValue(rpm / RPM_1_BYTE_PACKING_MULT, mapValue/ LOAD_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
|
||||
percent_t duty, closedLoopDuty = 0;
|
||||
|
||||
if (engineConfiguration->boostType == OPEN_LOOP) {
|
||||
duty = openLoopDuty;
|
||||
}
|
||||
else if (engineConfiguration->boostType == CLOSED_LOOP) {
|
||||
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
float targetBoost = boostMapClosed.getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps / TPS_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
|
||||
closedLoopDuty = openLoopDuty + boostControlPid.getOutput(targetBoost, mapValue);
|
||||
duty = closedLoopDuty;
|
||||
}
|
||||
|
||||
|
||||
boostControlPid.iTermMin = -50;
|
||||
boostControlPid.iTermMax = 50;
|
||||
|
||||
if (engineConfiguration->debugMode == DBG_BOOST) {
|
||||
#if EFI_TUNER_STUDIO
|
||||
tsOutputChannels.debugFloatField1 = openLoopDuty;
|
||||
tsOutputChannels.debugFloatField7 = closedLoopDuty;
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
}
|
||||
boostPwmControl.setSimplePwmDutyCycle(PERCENT_TO_DUTY(duty));
|
||||
|
||||
pidReset();
|
||||
shouldResetPid = false;
|
||||
}
|
||||
|
||||
float rpm = GET_RPM_VALUE;
|
||||
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
if (!engineConfiguration->isBoostControlEnabled)
|
||||
return;
|
||||
|
||||
bool engineRunning = rpm > engineConfiguration->cranking.rpm;
|
||||
if (!engineRunning) {
|
||||
boostControlPid.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
percent_t openLoopDuty = boostMapOpen.getValue(rpm / RPM_1_BYTE_PACKING_MULT, mapValue / LOAD_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
|
||||
percent_t closedLoopDuty = 0;
|
||||
percent_t duty = openLoopDuty;
|
||||
|
||||
if (engineConfiguration->boostType == CLOSED_LOOP) {
|
||||
float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
float targetBoost = boostMapClosed.getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps / TPS_1_BYTE_PACKING_MULT) * LOAD_1_BYTE_PACKING_MULT;
|
||||
closedLoopDuty = openLoopDuty + boostControlPid.getOutput(targetBoost, mapValue);
|
||||
duty += closedLoopDuty;
|
||||
}
|
||||
|
||||
boostControlPid.iTermMin = -50;
|
||||
boostControlPid.iTermMax = 50;
|
||||
|
||||
if (engineConfiguration->debugMode == DBG_BOOST) {
|
||||
#if EFI_TUNER_STUDIO
|
||||
boostControlPid.postState(&tsOutputChannels);
|
||||
tsOutputChannels.debugFloatField1 = openLoopDuty;
|
||||
tsOutputChannels.debugFloatField7 = closedLoopDuty;
|
||||
#endif /* EFI_TUNER_STUDIO */
|
||||
}
|
||||
|
||||
boostPwmControl.setSimplePwmDutyCycle(PERCENT_TO_DUTY(duty));
|
||||
}
|
||||
};
|
||||
|
||||
static BoostControl BoostController;
|
||||
|
||||
|
||||
void setBoostPFactor(float value) {
|
||||
engineConfiguration->boostPid.pFactor = value;
|
||||
boostControlPid.reset();
|
||||
|
@ -123,15 +112,12 @@ void setBoostIFactor(float value) {
|
|||
boostControlPid.reset();
|
||||
}
|
||||
|
||||
|
||||
void setBoostDFactor(float value) {
|
||||
engineConfiguration->boostPid.dFactor = value;
|
||||
boostControlPid.reset();
|
||||
}
|
||||
|
||||
void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
||||
|
||||
|
||||
engineConfiguration->isBoostControlEnabled = true;
|
||||
engineConfiguration->boostPwmFrequency = 55;
|
||||
engineConfiguration->boostPid.offset = 0;
|
||||
|
@ -146,33 +132,40 @@ void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
|
|||
setLinearCurve(config->boostRpmBins, 0, 8000 / RPM_1_BYTE_PACKING_MULT, 1);
|
||||
setLinearCurve(config->boostMapBins, 0, 300 / LOAD_1_BYTE_PACKING_MULT, 1);
|
||||
for (int loadIndex = 0;loadIndex<BOOST_LOAD_COUNT;loadIndex++) {
|
||||
for (int rpmIndex = 0;rpmIndex<BOOST_RPM_COUNT;rpmIndex++) {
|
||||
config->boostTableOpenLoop[loadIndex][rpmIndex] = config->boostMapBins[loadIndex];
|
||||
}
|
||||
for (int rpmIndex = 0;rpmIndex<BOOST_RPM_COUNT;rpmIndex++) {
|
||||
config->boostTableOpenLoop[loadIndex][rpmIndex] = config->boostMapBins[loadIndex];
|
||||
}
|
||||
}
|
||||
|
||||
setLinearCurve(config->boostTpsBins, 0, 100 / TPS_1_BYTE_PACKING_MULT, 1);
|
||||
for (int loadIndex = 0;loadIndex<BOOST_LOAD_COUNT;loadIndex++) {
|
||||
for (int rpmIndex = 0;rpmIndex<BOOST_RPM_COUNT;rpmIndex++) {
|
||||
config->boostTableClosedLoop[loadIndex][rpmIndex] = config->boostTpsBins[loadIndex];
|
||||
}
|
||||
}
|
||||
for (int loadIndex = 0;loadIndex<BOOST_LOAD_COUNT;loadIndex++) {
|
||||
for (int rpmIndex = 0;rpmIndex<BOOST_RPM_COUNT;rpmIndex++) {
|
||||
config->boostTableClosedLoop[loadIndex][rpmIndex] = config->boostTpsBins[loadIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void turnBoostPidOn() {
|
||||
if (CONFIG(boostControlPin) == GPIO_UNASSIGNED){
|
||||
return;
|
||||
}
|
||||
startSimplePwmExt(&boostPwmControl, "Boost", &engine->executor,
|
||||
CONFIG(boostControlPin), &enginePins.boostPin,
|
||||
engineConfiguration->boostPwmFrequency, 0.5f,
|
||||
(pwm_gen_callback*) applyPinState);
|
||||
|
||||
startSimplePwmExt(
|
||||
&boostPwmControl,
|
||||
"Boost",
|
||||
&engine->executor,
|
||||
CONFIG(boostControlPin),
|
||||
&enginePins.boostPin,
|
||||
engineConfiguration->boostPwmFrequency,
|
||||
0.5f,
|
||||
(pwm_gen_callback*) applyPinState
|
||||
);
|
||||
}
|
||||
|
||||
void startBoostPin(void) {
|
||||
|
||||
turnBoostPidOn();
|
||||
|
||||
}
|
||||
|
||||
void stopBoostPin(void) {
|
||||
brain_pin_markUnused(activeConfiguration.boostControlPin);
|
||||
}
|
||||
|
@ -181,14 +174,17 @@ void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfigur
|
|||
shouldResetPid = !boostControlPid.isSame(&previousConfiguration->boostPid);
|
||||
}
|
||||
|
||||
void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX){
|
||||
void initBoostCtrl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
if (CONFIG(boostControlPin) == GPIO_UNASSIGNED){
|
||||
return;
|
||||
}
|
||||
|
||||
logger = sharedLogger;
|
||||
boostMapOpen.init(config->boostTableOpenLoop, config->boostMapBins, config->boostRpmBins);
|
||||
boostMapClosed.init(config->boostTableClosedLoop, config->boostTpsBins, config->boostRpmBins);
|
||||
boostControlPid.reset();
|
||||
startBoostPin();
|
||||
BoostController.Start();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue