|
|
@@ -377,11 +377,9 @@ class SetupDevice: |
|
|
|
and therefore allows the rest of the program to carry on whilst |
|
|
|
monitoring the temperature. |
|
|
|
|
|
|
|
The mechanism whereby temperature is regulate is simple: turn heater |
|
|
|
unit ON or OFF whenever the average temperature is below or above |
|
|
|
`target_temperature`. |
|
|
|
|
|
|
|
.. TODO:: Implement a more sophisticated algorithm. |
|
|
|
The temperature is controlled through a PID controller. Heating |
|
|
|
intensity is defined by the ratio between `current_temperature' and |
|
|
|
`target_temperature'. If the ratio is above 1, heating stops. |
|
|
|
|
|
|
|
Parameters |
|
|
|
---------- |
|
|
@@ -406,13 +404,14 @@ class SetupDevice: |
|
|
|
if stop_flag.is_set(): |
|
|
|
break |
|
|
|
|
|
|
|
# If current_temperature < target_temperature, heat up. |
|
|
|
if current_temperature.mean() < target_temperature - TEMPERATURE_TOLERANCE: |
|
|
|
self._heater.set_PWM_dutycycle(self._HEATER_PIN, MAX_POWER) |
|
|
|
elif target_temperature - TEMPERATURE_TOLERANCE <= current_temperature.mean() < target_temperature: |
|
|
|
self._heater.set_PWM_dutycycle(self._HEATER_PIN, int(MAX_POWER*0.7)) |
|
|
|
temperature_ratio = current_temperature.mean() / target_temperature |
|
|
|
if temperature_ratio <= 1: |
|
|
|
MOD_POWER = MAX_POWER * (1 - temperature_ratio)**0.125 |
|
|
|
else: |
|
|
|
self._heater.set_PWM_dutycycle(self._HEATER_PIN, 0) |
|
|
|
MOD_POWER = 0 |
|
|
|
self._heater.set_PWM_dutycycle(self._HEATER_PIN, int(MOD_POWER)) |
|
|
|
|
|
|
|
# Update temperature values. |
|
|
|
temperature = self.report_temperature() |
|
|
|
current_temperature = np.array(temperature) |
|
|
|
t.sleep(1+TEMPERATURE_SAMPLING_FREQ) |