mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 02:34:29 +05:00
feat: improved turbo mode
- added turbo factor parameter - implemented turbo mode for PID
This commit is contained in:
@@ -29,31 +29,9 @@ protected:
|
||||
#endif
|
||||
|
||||
void loop() {
|
||||
bool pidIntergralResetted = false;
|
||||
if (fabs(pidRegulator.Kp - settings.pid.p_factor) >= 0.0001f) {
|
||||
pidRegulator.Kp = settings.pid.p_factor;
|
||||
pidRegulator.integral = 0;
|
||||
pidIntergralResetted = true;
|
||||
}
|
||||
|
||||
if (fabs(pidRegulator.Ki - settings.pid.i_factor) >= 0.0001f) {
|
||||
pidRegulator.Ki = settings.pid.i_factor;
|
||||
pidRegulator.integral = 0;
|
||||
pidIntergralResetted = true;
|
||||
}
|
||||
|
||||
if (fabs(pidRegulator.Kd - settings.pid.d_factor) >= 0.0001f) {
|
||||
pidRegulator.Kd = settings.pid.d_factor;
|
||||
pidRegulator.integral = 0;
|
||||
pidIntergralResetted = true;
|
||||
}
|
||||
|
||||
if (!settings.pid.enable && fabs(pidRegulator.integral) > 0.01f) {
|
||||
pidRegulator.integral = 0.0f;
|
||||
pidIntergralResetted = true;
|
||||
}
|
||||
|
||||
if (pidIntergralResetted) {
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset"));
|
||||
}
|
||||
|
||||
@@ -61,10 +39,10 @@ protected:
|
||||
if (!settings.heating.enable || vars.states.emergency) {
|
||||
settings.heating.turbo = false;
|
||||
|
||||
} else if (settings.pid.enable) {
|
||||
settings.heating.turbo = false; // not implemented
|
||||
} else if (!settings.pid.enable && !settings.equitherm.enable) {
|
||||
settings.heating.turbo = false;
|
||||
|
||||
} else if (fabs(settings.heating.target - vars.temperatures.indoor) < 1.0f) {
|
||||
} else if (fabs(settings.heating.target - vars.temperatures.indoor) <= 1.0f) {
|
||||
settings.heating.turbo = false;
|
||||
}
|
||||
|
||||
@@ -125,7 +103,9 @@ protected:
|
||||
etRegulator.indoorTemp = 0;
|
||||
|
||||
} else {
|
||||
etRegulator.Kt = settings.heating.turbo ? 10.0f : settings.equitherm.t_factor;
|
||||
etRegulator.Kt = settings.heating.turbo
|
||||
? settings.equitherm.t_factor * settings.heating.turboFactor
|
||||
: settings.equitherm.t_factor;
|
||||
etRegulator.indoorTemp = indoorTemp;
|
||||
}
|
||||
|
||||
@@ -155,11 +135,24 @@ protected:
|
||||
if (settings.pid.enable) {
|
||||
//if (vars.parameters.heatingEnabled) {
|
||||
if (settings.heating.enable && vars.sensors.indoor.connected) {
|
||||
pidRegulator.Kp = settings.heating.turbo
|
||||
? settings.pid.p_factor * settings.heating.turboFactor
|
||||
: settings.pid.p_factor;
|
||||
pidRegulator.Kd = settings.pid.d_factor;
|
||||
|
||||
pidRegulator.setLimits(settings.pid.minTemp, settings.pid.maxTemp);
|
||||
pidRegulator.setDt(settings.pid.dt * 1000u);
|
||||
pidRegulator.input = vars.temperatures.indoor;
|
||||
pidRegulator.setpoint = settings.heating.target;
|
||||
|
||||
if (fabs(pidRegulator.Ki - settings.pid.i_factor) >= 0.0001f) {
|
||||
pidRegulator.Ki = settings.pid.i_factor;
|
||||
pidRegulator.integral = 0;
|
||||
pidRegulator.getResultNow();
|
||||
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset"));
|
||||
}
|
||||
|
||||
float pidResult = pidRegulator.getResultTimer();
|
||||
if (fabs(prevPidResult - pidResult) > 0.09f) {
|
||||
prevPidResult = pidResult;
|
||||
|
||||
@@ -95,6 +95,7 @@ struct Settings {
|
||||
bool turbo = false;
|
||||
float target = DEFAULT_HEATING_TARGET_TEMP;
|
||||
float hysteresis = 0.5f;
|
||||
float turboFactor = 3.0f;
|
||||
byte minTemp = DEFAULT_HEATING_MIN_TEMP;
|
||||
byte maxTemp = DEFAULT_HEATING_MAX_TEMP;
|
||||
} heating;
|
||||
@@ -108,9 +109,9 @@ struct Settings {
|
||||
|
||||
struct {
|
||||
bool enable = false;
|
||||
float p_factor = 2;
|
||||
float p_factor = 2.0f;
|
||||
float i_factor = 0.0055f;
|
||||
float d_factor = 0;
|
||||
float d_factor = 0.0f;
|
||||
unsigned short dt = 180;
|
||||
short minTemp = 0;
|
||||
short maxTemp = DEFAULT_HEATING_MAX_TEMP;
|
||||
|
||||
10
src/utils.h
10
src/utils.h
@@ -394,6 +394,7 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
|
||||
dst["heating"]["turbo"] = src.heating.turbo;
|
||||
dst["heating"]["target"] = roundd(src.heating.target, 2);
|
||||
dst["heating"]["hysteresis"] = roundd(src.heating.hysteresis, 2);
|
||||
dst["heating"]["turboFactor"] = roundd(src.heating.turboFactor, 2);
|
||||
dst["heating"]["minTemp"] = src.heating.minTemp;
|
||||
dst["heating"]["maxTemp"] = src.heating.maxTemp;
|
||||
|
||||
@@ -1106,6 +1107,15 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
|
||||
}
|
||||
}
|
||||
|
||||
if (!src["heating"]["turboFactor"].isNull()) {
|
||||
float value = src["heating"]["turboFactor"].as<float>();
|
||||
|
||||
if (value >= 1.5f && value <= 10.0f && fabs(value - dst.heating.turboFactor) > 0.0001f) {
|
||||
dst.heating.turboFactor = roundd(value, 2);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!src["heating"]["minTemp"].isNull()) {
|
||||
unsigned char value = src["heating"]["minTemp"].as<unsigned char>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user