Commit e6e9ea42 authored by Oleg Nikulin's avatar Oleg Nikulin

Исправление в PID регуляторе

parent 66da6c04
......@@ -167,7 +167,7 @@ uint32_t lastRpmCheck = 0;
float errorIntegral[3] = {};
float prevError[3] = {};
float k_p = -40;
float k_p = 30;
float k_i = 0.005;
float k_d = 0;
......@@ -340,9 +340,9 @@ void rpm_control() {
float error = controls[group].target_temperature - controls[group].temperature;
//чтобы i не накапливалась
if (controls[group].dutyCycle < controls[group].max_duty_cycle && controls[group].dutyCycle < ON_DUTY_CYCLE)
errorIntegral[group] += error * deltaTime;
float max_i = 255 / k_i;
errorIntegral[group] += error * deltaTime;
errorIntegral[group] = constrain(errorIntegral[group], -max_i, 0); //чтобы i не накапливалась
float errorChangeRate = (error - prevError[group]) / deltaTime;
prevError[group] = error;
......@@ -352,6 +352,7 @@ void rpm_control() {
float d = k_d * errorChangeRate;
pwmDutyCycle = p + i + d;
pwmDutyCycle = -pwmDutyCycle;
}
set_duty_cycle(controls[group], round(pwmDutyCycle));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment