temperature_fan: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
f13c5d4cdb
commit
0b095ddf47
|
@ -27,7 +27,8 @@ class TemperatureFan:
|
||||||
self.min_speed = config.getfloat('min_speed', 0.3, above=0., maxval=1.)
|
self.min_speed = config.getfloat('min_speed', 0.3, above=0., maxval=1.)
|
||||||
self.last_temp = 0.
|
self.last_temp = 0.
|
||||||
self.last_temp_time = 0.
|
self.last_temp_time = 0.
|
||||||
self.target_temp = config.getfloat('target_temp', 40. if self.max_temp > 40. else self.max_temp,
|
self.target_temp = config.getfloat(
|
||||||
|
'target_temp', 40. if self.max_temp > 40. else self.max_temp,
|
||||||
minval=self.min_temp, maxval=self.max_temp)
|
minval=self.min_temp, maxval=self.max_temp)
|
||||||
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
|
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
|
||||||
algo = config.getchoice('control', algos)
|
algo = config.getchoice('control', algos)
|
||||||
|
@ -63,14 +64,17 @@ class ControlBangBang:
|
||||||
self.max_delta = config.getfloat('max_delta', 2.0, above=0.)
|
self.max_delta = config.getfloat('max_delta', 2.0, above=0.)
|
||||||
self.heating = False
|
self.heating = False
|
||||||
def temperature_callback(self, read_time, temp):
|
def temperature_callback(self, read_time, temp):
|
||||||
if self.heating and temp >= self.temperature_fan.target_temp+self.max_delta:
|
if (self.heating
|
||||||
|
and temp >= self.temperature_fan.target_temp+self.max_delta):
|
||||||
self.heating = False
|
self.heating = False
|
||||||
elif not self.heating and temp <= self.temperature_fan.target_temp-self.max_delta:
|
elif (not self.heating
|
||||||
|
and temp <= self.temperature_fan.target_temp-self.max_delta):
|
||||||
self.heating = True
|
self.heating = True
|
||||||
if self.heating:
|
if self.heating:
|
||||||
self.temperature_fan.set_speed(read_time, 0.)
|
self.temperature_fan.set_speed(read_time, 0.)
|
||||||
else:
|
else:
|
||||||
self.temperature_fan.set_speed(read_time, self.temperature_fan.max_speed)
|
self.temperature_fan.set_speed(read_time,
|
||||||
|
self.temperature_fan.max_speed)
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Proportional Integral Derivative (PID) control algo
|
# Proportional Integral Derivative (PID) control algo
|
||||||
|
@ -86,7 +90,8 @@ class ControlPID:
|
||||||
self.Ki = config.getfloat('pid_Ki') / PID_PARAM_BASE
|
self.Ki = config.getfloat('pid_Ki') / PID_PARAM_BASE
|
||||||
self.Kd = config.getfloat('pid_Kd') / PID_PARAM_BASE
|
self.Kd = config.getfloat('pid_Kd') / PID_PARAM_BASE
|
||||||
self.min_deriv_time = config.getfloat('pid_deriv_time', 2., above=0.)
|
self.min_deriv_time = config.getfloat('pid_deriv_time', 2., above=0.)
|
||||||
imax = config.getfloat('pid_integral_max', temperature_fan.max_speed, minval=0.)
|
imax = config.getfloat('pid_integral_max', temperature_fan.max_speed,
|
||||||
|
minval=0.)
|
||||||
self.temp_integ_max = imax / self.Ki
|
self.temp_integ_max = imax / self.Ki
|
||||||
self.prev_temp = AMBIENT_TEMP
|
self.prev_temp = AMBIENT_TEMP
|
||||||
self.prev_temp_time = 0.
|
self.prev_temp_time = 0.
|
||||||
|
@ -108,7 +113,8 @@ class ControlPID:
|
||||||
# Calculate output
|
# Calculate output
|
||||||
co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv
|
co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv
|
||||||
bounded_co = max(0., min(self.temperature_fan.max_speed, co))
|
bounded_co = max(0., min(self.temperature_fan.max_speed, co))
|
||||||
self.temperature_fan.set_speed(read_time, self.temperature_fan.max_speed - bounded_co)
|
self.temperature_fan.set_speed(
|
||||||
|
read_time, self.temperature_fan.max_speed - bounded_co)
|
||||||
# Store state for next measurement
|
# Store state for next measurement
|
||||||
self.prev_temp = temp
|
self.prev_temp = temp
|
||||||
self.prev_temp_time = read_time
|
self.prev_temp_time = read_time
|
||||||
|
|
Loading…
Reference in New Issue