pytec: revert changes to example.py and plot.py, save changes for other PR

This commit is contained in:
topquark12 2021-01-05 12:42:50 +08:00
parent 9f872c0113
commit 14a027c0f0
2 changed files with 118 additions and 122 deletions

View File

@ -1,13 +1,11 @@
if __name__ == "__main__":
from pytec.client import Client
from pytec.client import Client
tec = Client() #(host="localhost", port=6667)
tec.set_param("s-h", 1, "t0", 20)
print(tec.get_pwm())
print(tec.get_pid())
print(tec.get_pwm())
print(tec.get_postfilter())
print(tec.get_steinhart_hart())
for data in tec.report_mode():
tec = Client() #(host="localhost", port=6667)
tec.set_param("s-h", 1, "t0", 20)
print(tec.get_pwm())
print(tec.get_pid())
print(tec.get_pwm())
print(tec.get_postfilter())
print(tec.get_steinhart_hart())
for data in tec.report_mode():
print(data)

View File

@ -4,15 +4,13 @@ import matplotlib.animation as animation
from threading import Thread, Lock
from pytec.client import Client
if __name__ == "__main__":
TIME_WINDOW = 300.0
TIME_WINDOW = 300.0
tec = Client()
target_temperature = tec.get_pid()[0]['target']
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
tec = Client()
target_temperature = tec.get_pid()[0]['target']
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
class Series:
class Series:
def __init__(self, conv=lambda x: x):
self.conv = conv
self.x_data = []
@ -29,10 +27,10 @@ if __name__ == "__main__":
self.x_data = self.x_data[drop:]
self.y_data = self.y_data[drop:]
series = {
series = {
'adc': Series(),
'sens': Series(lambda x: x * 0.0001),
'temperature': Series(),
'temperature': Series(lambda t: t - target_temperature),
'i_set': Series(),
'pid_output': Series(),
'vref': Series(),
@ -42,12 +40,12 @@ if __name__ == "__main__":
'tec_i': Series(),
'tec_u_meas': Series(),
'interval': Series(),
}
series_lock = Lock()
}
series_lock = Lock()
quit = False
quit = False
def recv_data(tec):
def recv_data(tec):
global last_packet_time
for data in tec.report_mode():
ch0 = data[0]
@ -64,16 +62,16 @@ if __name__ == "__main__":
if quit:
break
thread = Thread(target=recv_data, args=(tec,))
thread.start()
thread = Thread(target=recv_data, args=(tec,))
thread.start()
fig, ax = plt.subplots()
fig, ax = plt.subplots()
for k, s in series.items():
for k, s in series.items():
s.plot, = ax.plot([], [], label=k)
legend = ax.legend()
legend = ax.legend()
def animate(i):
def animate(i):
min_x, max_x, min_y, max_y = None, None, None, None
series_lock.acquire()
@ -122,9 +120,9 @@ if __name__ == "__main__":
legend.remove()
legend = ax.legend()
ani = animation.FuncAnimation(
ani = animation.FuncAnimation(
fig, animate, interval=1, blit=False, save_count=50)
plt.show()
quit = True
thread.join()
plt.show()
quit = True
thread.join()