WOrking with ramp ref
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"""
|
||||
Minimal serial plotter for the HeaveOnly sketch.
|
||||
|
||||
Expects CSV lines at 2_000_000 baud: Front,Back,Avg,PWM,outputOn
|
||||
Expects CSV lines at 2_000_000 baud: Front,Back,Avg,ActiveRef,PWM,outputOn
|
||||
Key commands (focus the plot window):
|
||||
0 → output off
|
||||
1 → output on, PID
|
||||
@@ -61,6 +61,7 @@ def main():
|
||||
front = deque(maxlen=N)
|
||||
back = deque(maxlen=N)
|
||||
avg = deque(maxlen=N)
|
||||
aref = deque(maxlen=N)
|
||||
pwm = deque(maxlen=N)
|
||||
on_buf = deque(maxlen=N)
|
||||
|
||||
@@ -69,6 +70,8 @@ def main():
|
||||
l_front, = ax_mm.plot([], [], label='Front', color='tab:blue')
|
||||
l_back, = ax_mm.plot([], [], label='Back', color='tab:orange')
|
||||
l_avg, = ax_mm.plot([], [], label='Avg', color='k', lw=2)
|
||||
l_aref, = ax_mm.plot([], [], label='ActiveRef', color='tab:green',
|
||||
lw=1.2, ls='--')
|
||||
ax_mm.set_ylabel('Gap (mm)')
|
||||
ax_mm.grid(True, alpha=0.3)
|
||||
ax_mm.legend(loc='upper right')
|
||||
@@ -103,11 +106,11 @@ def main():
|
||||
fig.canvas.mpl_connect('key_press_event', on_key)
|
||||
|
||||
ax_ref = fig.add_axes([0.10, 0.04, 0.15, 0.05])
|
||||
tb_ref = TextBox(ax_ref, 'Ref (mm) ', initial='12.36')
|
||||
tb_ref = TextBox(ax_ref, 'Ref (mm) ', initial='12')
|
||||
ax_pid = fig.add_axes([0.50, 0.04, 0.30, 0.05])
|
||||
tb_pid = TextBox(ax_pid, 'PID (kp,ki,kd) ', initial='10,0,8')
|
||||
tb_pid = TextBox(ax_pid, 'PID (kp,ki,kd) ', initial='400,0,300')
|
||||
ax_ff = fig.add_axes([0.88, 0.03, 0.08, 0.07])
|
||||
cb_ff = CheckButtons(ax_ff, ['FF'], [True])
|
||||
cb_ff = CheckButtons(ax_ff, ['FF'], [False])
|
||||
|
||||
def on_ref(text):
|
||||
try:
|
||||
@@ -139,29 +142,31 @@ def main():
|
||||
raw = ser.readline()
|
||||
try:
|
||||
parts = raw.decode('ascii', 'ignore').strip().split(',')
|
||||
if len(parts) != 5:
|
||||
if len(parts) != 6:
|
||||
continue
|
||||
f, b, a = float(parts[0]), float(parts[1]), float(parts[2])
|
||||
p = int(parts[3])
|
||||
on = int(parts[4])
|
||||
f, b, a, r = (float(parts[0]), float(parts[1]),
|
||||
float(parts[2]), float(parts[3]))
|
||||
p = int(parts[4])
|
||||
on = int(parts[5])
|
||||
except ValueError:
|
||||
continue
|
||||
t_buf.append(time.time() - t0)
|
||||
front.append(f); back.append(b); avg.append(a)
|
||||
front.append(f); back.append(b); avg.append(a); aref.append(r)
|
||||
pwm.append(p); on_buf.append(on)
|
||||
|
||||
def update(_frame):
|
||||
poll_serial()
|
||||
if not t_buf:
|
||||
return l_front, l_back, l_avg, l_pwm, mode_txt
|
||||
return l_front, l_back, l_avg, l_aref, l_pwm, mode_txt
|
||||
xs = list(t_buf)
|
||||
l_front.set_data(xs, list(front))
|
||||
l_back .set_data(xs, list(back))
|
||||
l_avg .set_data(xs, list(avg))
|
||||
l_aref .set_data(xs, list(aref))
|
||||
l_pwm .set_data(xs, list(pwm))
|
||||
ax_mm.relim(); ax_mm.autoscale_view(scalex=True, scaley=True)
|
||||
ax_pwm.set_xlim(xs[0], max(xs[-1], xs[0] + 1e-3))
|
||||
return l_front, l_back, l_avg, l_pwm, mode_txt
|
||||
return l_front, l_back, l_avg, l_aref, l_pwm, mode_txt
|
||||
|
||||
ani = FuncAnimation(fig, update, interval=50, blit=False,
|
||||
cache_frame_data=False)
|
||||
|
||||
Reference in New Issue
Block a user