pytec plot: update legend, rm debug add pid_output

This commit is contained in:
Astro 2020-09-30 19:13:50 +02:00
parent 445cde6ae8
commit 4b75c6147d
2 changed files with 9 additions and 16 deletions

View File

@ -28,6 +28,7 @@ series = {
'sens': Series(0.0001), 'sens': Series(0.0001),
'temperature': Series(), 'temperature': Series(),
'i_set': Series(), 'i_set': Series(),
'pid_output': Series(),
'vref': Series(), 'vref': Series(),
'dac_feedback': Series(), 'dac_feedback': Series(),
'i_tec': Series(), 'i_tec': Series(),
@ -39,7 +40,6 @@ series_lock = Lock()
quit = False quit = False
def recv_data(tec): def recv_data(tec):
print("reporting")
for data in tec.report_mode(): for data in tec.report_mode():
if data['channel'] == 0: if data['channel'] == 0:
series_lock.acquire() series_lock.acquire()
@ -56,7 +56,6 @@ def recv_data(tec):
break break
tec = Client() tec = Client()
print("connected")
thread = Thread(target=recv_data, args=(tec,)) thread = Thread(target=recv_data, args=(tec,))
thread.start() thread.start()
@ -64,15 +63,17 @@ fig, ax = plt.subplots()
for k, s in series.iteritems(): for k, s in series.iteritems():
s.plot, = ax.plot([], [], label=k) s.plot, = ax.plot([], [], label=k)
ax.legend() legend = ax.legend()
def animate(i): def animate(i):
min_x, max_x, min_y, max_y = None, None, None, None min_x, max_x, min_y, max_y = None, None, None, None
series_lock.acquire() series_lock.acquire()
try: try:
for s in series.itervalues(): for k, s in series.iteritems():
s.plot.set_data(s.x_data, s.y_data) 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: if len(s.x_data) > 0:
min_x_ = min(s.x_data) min_x_ = min(s.x_data)
@ -107,21 +108,13 @@ def animate(i):
ax.set_xlim(min_x, max_x) ax.set_xlim(min_x, max_x)
ax.set_ylim(min_y - margin_y, max_y + margin_y) ax.set_ylim(min_y - margin_y, max_y + margin_y)
global legend
legend.remove()
legend = ax.legend()
ani = animation.FuncAnimation( ani = animation.FuncAnimation(
fig, animate, interval=1, blit=False, save_count=50) fig, animate, interval=1, blit=False, save_count=50)
# To save the animation, use e.g.
#
# ani.save("movie.mp4")
#
# or
#
# writer = animation.FFMpegWriter(
# fps=15, metadata=dict(artist='Me'), bitrate=1800)
# ani.save("movie.mp4", writer=writer)
print("show")
plt.show() plt.show()
quit = True quit = True
thread.join() thread.join()

View File

@ -4,7 +4,7 @@ use crate::usb;
pub fn init_log() { pub fn init_log() {
static USB_LOGGER: usb::Logger = usb::Logger; static USB_LOGGER: usb::Logger = usb::Logger;
let _ = log::set_logger(&USB_LOGGER); let _ = log::set_logger(&USB_LOGGER);
log::set_max_level(log::LevelFilter::Info); log::set_max_level(log::LevelFilter::Trace);
} }
#[cfg(feature = "semihosting")] #[cfg(feature = "semihosting")]