forked from M-Labs/thermostat
Compare commits
5 Commits
ee094241bb
...
36d80ebdff
Author | SHA1 | Date | |
---|---|---|---|
36d80ebdff | |||
09300b5d44 | |||
9743dca775 | |||
11131deda2 | |||
764774fbce |
16
README.md
16
README.md
@ -239,6 +239,22 @@ of channel 0 to the PID algorithm:
|
|||||||
output 0 pid
|
output 0 pid
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### PID output clamping
|
||||||
|
|
||||||
|
It is possible to clamp the PID algorithm output independently of channel output limits. This is desirable when e.g. there is a need to keep the current value above a certain threshold in closed-loop mode.
|
||||||
|
|
||||||
|
Note that the actual output will still ultimately be limited by the `max_i_pos` and `max_i_neg` values.
|
||||||
|
|
||||||
|
Set PID maximum output of channel 0 to 1.5 A.
|
||||||
|
```
|
||||||
|
pid 0 output_max 1.5
|
||||||
|
```
|
||||||
|
|
||||||
|
Set PID minimum output of channel 0 to 0.1 A.
|
||||||
|
```
|
||||||
|
pid 0 output_min 0.1
|
||||||
|
```
|
||||||
|
|
||||||
## LED indicators
|
## LED indicators
|
||||||
|
|
||||||
| Name | Color | Meaning |
|
| Name | Color | Meaning |
|
||||||
|
@ -13,7 +13,7 @@ When tuning Thermostat PID parameters, it is helpful to view the temperature, PI
|
|||||||
To use the Python real-time plotting utility, run
|
To use the Python real-time plotting utility, run
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
python pythermostat/plot.py
|
python pythermostat/pythermostat/plot.py
|
||||||
```
|
```
|
||||||
|
|
||||||
![default view](./assets/default%20view.png)
|
![default view](./assets/default%20view.png)
|
||||||
@ -49,7 +49,7 @@ A PID auto tuning utility is provided in the PyThermostat library. The auto tuni
|
|||||||
To run the auto tuning utility, run
|
To run the auto tuning utility, run
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
python pythermostat/autotune.py
|
python pythermostat/pythermostat/autotune.py
|
||||||
```
|
```
|
||||||
|
|
||||||
After some time, the auto tuning utility will output the auto tuning results, below is a sample output
|
After some time, the auto tuning utility will output the auto tuning results, below is a sample output
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
import time
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import matplotlib.animation as animation
|
|
||||||
from threading import Thread, Lock
|
|
||||||
from pythermostat.client import Client
|
|
||||||
|
|
||||||
TIME_WINDOW = 300.0
|
|
||||||
|
|
||||||
tec = Client()
|
|
||||||
target_temperature = tec.get_pid()[0]['target']
|
|
||||||
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
|
||||||
|
|
||||||
class Series:
|
|
||||||
def __init__(self, conv=lambda x: x):
|
|
||||||
self.conv = conv
|
|
||||||
self.x_data = []
|
|
||||||
self.y_data = []
|
|
||||||
|
|
||||||
def append(self, x, y):
|
|
||||||
self.x_data.append(x)
|
|
||||||
self.y_data.append(self.conv(y))
|
|
||||||
|
|
||||||
def clip(self, min_x):
|
|
||||||
drop = 0
|
|
||||||
while drop < len(self.x_data) and self.x_data[drop] < min_x:
|
|
||||||
drop += 1
|
|
||||||
self.x_data = self.x_data[drop:]
|
|
||||||
self.y_data = self.y_data[drop:]
|
|
||||||
|
|
||||||
series = {
|
|
||||||
# 'adc': Series(),
|
|
||||||
# 'sens': Series(lambda x: x * 0.0001),
|
|
||||||
'temperature': Series(),
|
|
||||||
# 'i_set': Series(),
|
|
||||||
'pid_output': Series(),
|
|
||||||
# 'vref': Series(),
|
|
||||||
# 'dac_value': Series(),
|
|
||||||
# 'dac_feedback': Series(),
|
|
||||||
# 'i_tec': Series(),
|
|
||||||
'tec_i': Series(),
|
|
||||||
'tec_u_meas': Series(),
|
|
||||||
# 'interval': Series(),
|
|
||||||
}
|
|
||||||
series_lock = Lock()
|
|
||||||
|
|
||||||
quit = False
|
|
||||||
|
|
||||||
def recv_data(tec):
|
|
||||||
global last_packet_time
|
|
||||||
while True:
|
|
||||||
data = tec.get_report()
|
|
||||||
ch0 = data[0]
|
|
||||||
series_lock.acquire()
|
|
||||||
try:
|
|
||||||
for k, s in series.items():
|
|
||||||
if k in ch0:
|
|
||||||
v = ch0[k]
|
|
||||||
if type(v) is float:
|
|
||||||
s.append(ch0['time'], v)
|
|
||||||
finally:
|
|
||||||
series_lock.release()
|
|
||||||
|
|
||||||
if quit:
|
|
||||||
break
|
|
||||||
time.sleep(0.05)
|
|
||||||
|
|
||||||
thread = Thread(target=recv_data, args=(tec,))
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
fig, ax = plt.subplots()
|
|
||||||
|
|
||||||
for k, s in series.items():
|
|
||||||
s.plot, = ax.plot([], [], label=k)
|
|
||||||
legend = ax.legend()
|
|
||||||
|
|
||||||
def animate(i):
|
|
||||||
min_x, max_x, min_y, max_y = None, None, None, None
|
|
||||||
|
|
||||||
series_lock.acquire()
|
|
||||||
try:
|
|
||||||
for k, s in series.items():
|
|
||||||
s.plot.set_data(s.x_data, s.y_data)
|
|
||||||
if len(s.y_data) > 0:
|
|
||||||
s.plot.set_label("{}: {:.3f}".format(k, s.y_data[-1]))
|
|
||||||
|
|
||||||
if len(s.x_data) > 0:
|
|
||||||
min_x_ = min(s.x_data)
|
|
||||||
if min_x is None:
|
|
||||||
min_x = min_x_
|
|
||||||
else:
|
|
||||||
min_x = min(min_x, min_x_)
|
|
||||||
max_x_ = max(s.x_data)
|
|
||||||
if max_x is None:
|
|
||||||
max_x = max_x_
|
|
||||||
else:
|
|
||||||
max_x = max(max_x, max_x_)
|
|
||||||
if len(s.y_data) > 0:
|
|
||||||
min_y_ = min(s.y_data)
|
|
||||||
if min_y is None:
|
|
||||||
min_y = min_y_
|
|
||||||
else:
|
|
||||||
min_y = min(min_y, min_y_)
|
|
||||||
max_y_ = max(s.y_data)
|
|
||||||
if max_y is None:
|
|
||||||
max_y = max_y_
|
|
||||||
else:
|
|
||||||
max_y = max(max_y, max_y_)
|
|
||||||
|
|
||||||
if min_x and max_x - TIME_WINDOW > min_x:
|
|
||||||
for s in series.values():
|
|
||||||
s.clip(max_x - TIME_WINDOW)
|
|
||||||
finally:
|
|
||||||
series_lock.release()
|
|
||||||
|
|
||||||
if min_x != max_x:
|
|
||||||
ax.set_xlim(min_x, max_x)
|
|
||||||
if min_y != max_y:
|
|
||||||
margin_y = 0.01 * (max_y - min_y)
|
|
||||||
ax.set_ylim(min_y - margin_y, max_y + margin_y)
|
|
||||||
|
|
||||||
global legend
|
|
||||||
legend.remove()
|
|
||||||
legend = ax.legend()
|
|
||||||
|
|
||||||
ani = animation.FuncAnimation(
|
|
||||||
fig, animate, interval=1, blit=False, save_count=50)
|
|
||||||
|
|
||||||
plt.show()
|
|
||||||
quit = True
|
|
||||||
thread.join()
|
|
@ -1,5 +1,6 @@
|
|||||||
import math
|
import math
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
from collections import deque, namedtuple
|
from collections import deque, namedtuple
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
@ -236,13 +237,14 @@ def main():
|
|||||||
|
|
||||||
tec = Client()
|
tec = Client()
|
||||||
|
|
||||||
data = next(tec.report_mode())
|
data = tec.get_report()
|
||||||
ch = data[channel]
|
ch = data[channel]
|
||||||
|
|
||||||
tuner = PIDAutotune(target_temperature, output_step,
|
tuner = PIDAutotune(target_temperature, output_step,
|
||||||
lookback, noiseband, ch['interval'])
|
lookback, noiseband, ch['interval'])
|
||||||
|
|
||||||
for data in tec.report_mode():
|
while True:
|
||||||
|
data = tec.get_report()
|
||||||
|
|
||||||
ch = data[channel]
|
ch = data[channel]
|
||||||
|
|
||||||
@ -255,6 +257,8 @@ def main():
|
|||||||
|
|
||||||
tec.set_param("output", channel, "i_set", tuner_out)
|
tec.set_param("output", channel, "i_set", tuner_out)
|
||||||
|
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
tec.set_param("output", channel, "i_set", 0)
|
tec.set_param("output", channel, "i_set", 0)
|
||||||
|
|
||||||
|
|
137
pythermostat/pythermostat/plot.py
Normal file
137
pythermostat/pythermostat/plot.py
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
import time
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.animation as animation
|
||||||
|
from threading import Thread, Lock
|
||||||
|
from pythermostat.client import Client
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
TIME_WINDOW = 300.0
|
||||||
|
|
||||||
|
tec = Client()
|
||||||
|
target_temperature = tec.get_pid()[0]['target']
|
||||||
|
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
||||||
|
|
||||||
|
class Series:
|
||||||
|
def __init__(self, conv=lambda x: x):
|
||||||
|
self.conv = conv
|
||||||
|
self.x_data = []
|
||||||
|
self.y_data = []
|
||||||
|
|
||||||
|
def append(self, x, y):
|
||||||
|
self.x_data.append(x)
|
||||||
|
self.y_data.append(self.conv(y))
|
||||||
|
|
||||||
|
def clip(self, min_x):
|
||||||
|
drop = 0
|
||||||
|
while drop < len(self.x_data) and self.x_data[drop] < min_x:
|
||||||
|
drop += 1
|
||||||
|
self.x_data = self.x_data[drop:]
|
||||||
|
self.y_data = self.y_data[drop:]
|
||||||
|
|
||||||
|
series = {
|
||||||
|
# 'adc': Series(),
|
||||||
|
# 'sens': Series(lambda x: x * 0.0001),
|
||||||
|
'temperature': Series(),
|
||||||
|
# 'i_set': Series(),
|
||||||
|
'pid_output': Series(),
|
||||||
|
# 'vref': Series(),
|
||||||
|
# 'dac_value': Series(),
|
||||||
|
# 'dac_feedback': Series(),
|
||||||
|
# 'i_tec': Series(),
|
||||||
|
'tec_i': Series(),
|
||||||
|
'tec_u_meas': Series(),
|
||||||
|
# 'interval': Series(),
|
||||||
|
}
|
||||||
|
series_lock = Lock()
|
||||||
|
|
||||||
|
quit = False
|
||||||
|
|
||||||
|
def recv_data(tec):
|
||||||
|
global last_packet_time
|
||||||
|
while True:
|
||||||
|
data = tec.get_report()
|
||||||
|
ch0 = data[0]
|
||||||
|
series_lock.acquire()
|
||||||
|
try:
|
||||||
|
for k, s in series.items():
|
||||||
|
if k in ch0:
|
||||||
|
v = ch0[k]
|
||||||
|
if type(v) is float:
|
||||||
|
s.append(ch0['time'], v)
|
||||||
|
finally:
|
||||||
|
series_lock.release()
|
||||||
|
|
||||||
|
if quit:
|
||||||
|
break
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
thread = Thread(target=recv_data, args=(tec,))
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
|
for k, s in series.items():
|
||||||
|
s.plot, = ax.plot([], [], label=k)
|
||||||
|
legend = ax.legend()
|
||||||
|
|
||||||
|
def animate(i):
|
||||||
|
min_x, max_x, min_y, max_y = None, None, None, None
|
||||||
|
|
||||||
|
series_lock.acquire()
|
||||||
|
try:
|
||||||
|
for k, s in series.items():
|
||||||
|
s.plot.set_data(s.x_data, s.y_data)
|
||||||
|
if len(s.y_data) > 0:
|
||||||
|
s.plot.set_label("{}: {:.3f}".format(k, s.y_data[-1]))
|
||||||
|
|
||||||
|
if len(s.x_data) > 0:
|
||||||
|
min_x_ = min(s.x_data)
|
||||||
|
if min_x is None:
|
||||||
|
min_x = min_x_
|
||||||
|
else:
|
||||||
|
min_x = min(min_x, min_x_)
|
||||||
|
max_x_ = max(s.x_data)
|
||||||
|
if max_x is None:
|
||||||
|
max_x = max_x_
|
||||||
|
else:
|
||||||
|
max_x = max(max_x, max_x_)
|
||||||
|
if len(s.y_data) > 0:
|
||||||
|
min_y_ = min(s.y_data)
|
||||||
|
if min_y is None:
|
||||||
|
min_y = min_y_
|
||||||
|
else:
|
||||||
|
min_y = min(min_y, min_y_)
|
||||||
|
max_y_ = max(s.y_data)
|
||||||
|
if max_y is None:
|
||||||
|
max_y = max_y_
|
||||||
|
else:
|
||||||
|
max_y = max(max_y, max_y_)
|
||||||
|
|
||||||
|
if min_x and max_x - TIME_WINDOW > min_x:
|
||||||
|
for s in series.values():
|
||||||
|
s.clip(max_x - TIME_WINDOW)
|
||||||
|
finally:
|
||||||
|
series_lock.release()
|
||||||
|
|
||||||
|
if min_x != max_x:
|
||||||
|
ax.set_xlim(min_x, max_x)
|
||||||
|
if min_y != max_y:
|
||||||
|
margin_y = 0.01 * (max_y - min_y)
|
||||||
|
ax.set_ylim(min_y - margin_y, max_y + margin_y)
|
||||||
|
|
||||||
|
nonlocal legend
|
||||||
|
legend.remove()
|
||||||
|
legend = ax.legend()
|
||||||
|
|
||||||
|
ani = animation.FuncAnimation(
|
||||||
|
fig, animate, interval=1, blit=False, save_count=50)
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
quit = True
|
||||||
|
thread.join()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -9,4 +9,13 @@ setup(
|
|||||||
license="GPLv3",
|
license="GPLv3",
|
||||||
install_requires=["setuptools"],
|
install_requires=["setuptools"],
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
entry_points={
|
||||||
|
"gui_scripts": [
|
||||||
|
"thermostat_plot = pythermostat.plot:main",
|
||||||
|
],
|
||||||
|
"console_scripts": [
|
||||||
|
"thermostat_autotune = pythermostat.autotune:main",
|
||||||
|
"thermostat_test = pythermostat.test:main",
|
||||||
|
]
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user