@@ -33,7 +33,7 @@ LOGISTIC_TEMP_CRITICAL=75
3333LOGISTIC_a=1
3434LOGISTIC_b=10
3535# uncomment and edit PID_THERMAL_IDEAL to set a fixed IDEAL temperature for the PID controller;
36- # otherwise, the initial temperature after startup (+3°C) is used as reference.
36+ # otherwise, the initial temperature after startup is used as reference.
3737# PID_THERMAL_IDEAL=45
3838# https://en.wikipedia.org/wiki/PID_controller#Loop_tuning
3939PID_Kp=$(( DEFAULT_PERIOD/ 200 ))
@@ -283,7 +283,7 @@ function_pid () {
283283controller_pid () {
284284 # i_error cannot be local to be cumulative since it was first declared.
285285 local p_error d_error model duty_cycle
286- p_error=" $(( ${TEMPS[-1]} - ${PID_THERMAL_IDEAL:- $((THERMAL_INITIAL+3 ))} )) "
286+ p_error=" $(( ${TEMPS[-1]} - ${PID_THERMAL_IDEAL:- $((THERMAL_INITIAL))} )) "
287287 i_error=" $(( ${i_error:- 0} + p_error)) "
288288 d_error=" $(( ${TEMPS[-1]} - ${TEMPS[-2]} )) "
289289 # TODO: Kp, Ki, and Kd could be auto tunned here; currently, they are not declared and PID_ vars are used.
@@ -293,8 +293,12 @@ controller_pid () {
293293 # bound to duty cycle thresholds first in case model-based value is outside the valid range
294294 if [[ $(( duty_cycle+ model)) -lt " ${DC_ABS_THRESH[0]} " ]]; then
295295 echo " ${DC_ABS_THRESH[0]} " 2> /dev/null > " $CHANNEL_FOLDER " ' duty_cycle'
296+ # reset i_error to prevent from acumulating further
297+ i_error=0
296298 elif [[ $(( duty_cycle+ model)) -gt " ${DC_ABS_THRESH[-1]} " ]]; then
297299 echo " ${DC_ABS_THRESH[-1]} " 2> /dev/null > " $CHANNEL_FOLDER " ' duty_cycle'
300+ # reset i_error to prevent from acumulating further
301+ i_error=0
298302 else
299303 echo $(( duty_cycle+ model)) 2> /dev/null > " $CHANNEL_FOLDER " ' duty_cycle'
300304 fi
0 commit comments