Commit 93ab5dde authored by Stefan Steinmüller's avatar Stefan Steinmüller
Browse files

'realtime' plotting implemented

parent d72af769
......@@ -2,39 +2,78 @@ import serial
import matplotlib.pyplot as plt
import numpy as np
from collections import deque
from matplotlib.animation import FuncAnimation
fig, ax_1 = plt.subplots(1,1)
ax_2 = ax_1.twinx()
ax_3 = ax_1.twinx()
fig = plt.figure()
rect = [1,1,1,1]
ax_1 = fig.add_subplot(411)
ax_2 = fig.add_subplot(412)
ax_3 = fig.add_subplot(413)
ax_4 = fig.add_subplot(414)
x_range = deque([])
max_range = 0
ax_1.set_ylim([-100, 100])
ax_2.set_ylim([-100, 100])
ax_3.set_ylim([-100, 100])
plt.ion()
#ax_1.set_ylim([-100, 100])
ax_1.set_autoscaley_on(True)
#ax_2.set_ylim([-100, 100])
ax_2.set_autoscaley_on(True)
#ax_3.set_ylim([-100, 100])
ax_3.set_autoscaley_on(True)
#ax_4.set_ylim([-100, 100])
#ax_4.set_autoscaley_on(True)
ax_1_l, = ax_1.plot([],[], "ro")
ax_2_l, = ax_2.plot([],[], 'bo')
ax_3_l, = ax_3.plot([],[], 'go')
ax_4_l, = ax_4.plot([],[], 'yo')
try:
board = serial.Serial("/dev/ttyACM1")
board = serial.Serial("/dev/ttyACM1", 115200, timeout=0.1)
except Exception as e:
print("an error occured while opening the serial device\n{}".format(e))
exit()
print(board.readline())
#def add_points(a):
while board:
if True:
try:
# print(max_range, 'max_range')
pass
except:
max_range = 0
_txt = board.readline().strip('\r\n')
txt = _txt.split(",")
print(txt)
x_range.append(max_range+1)
max_range += 1
try:
ax_1.set_xlim([max_range-200, max_range+1])
ax_2.set_xlim([max_range-200, max_range+1])
ax_3.set_xlim([max_range-200, max_range+1])
ax_4.set_xlim([max_range-200, max_range+1])
plt.show()
ax_1.plot([max_range], [float(txt[0].strip())], 'ro')
ax_2.plot([max_range], [float(txt[1].strip())], 'bo')
ax_3.plot([max_range], [float(txt[2].strip())], 'go')
ax_4.plot([max_range], [float(txt[3].strip())], 'yo')
while(board):
_txt = board.readline()
txt = _txt.split(";").strip()
x_range.append(max_range+1)
max_range += 1
ax_1.set_xlim([max_range-200, max_range+1])
ax_1.plot([max_range], [txt[0]])
ax_2.plot([max_range], [txt[1]])
ax_2.plot([max_range], [txt[2]])
csv_cont = []
try:
with open('log_plot.csv', 'r') as csv:
csv_cont = csv.readlines()
except:
pass
with open('log_plot.csv', 'w') as csv:
csv_cont.append(_txt)
csv.writelines(csv_cont)
csv_cont = []
try:
with open('log_plot.csv', 'r') as csv:
csv_cont = csv.readlines()
except:
pass
with open('log_plot.csv', 'w') as csv:
csv_cont.append(_txt)
csv.writelines(csv_cont)
except:
pass
#ani = FuncAnimation(fig, add_points, frames=200)
plt.pause(0.05)
#plt.show()
plt.draw()
fig.canvas.draw()
fig.canvas.flush_events()
#ani = FuncAnimation(fig, add_points)
#plt.show()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment