From dabffcc22c84c92878bbd680a57e23874ded757d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 14 Dec 2019 10:30:25 -0500 Subject: kin_extruder: Convert pressure advance to use "weighted average" Signed-off-by: Kevin O'Connor --- scripts/graph_extruder.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/graph_extruder.py b/scripts/graph_extruder.py index 6223bb11..5c0fb5cf 100755 --- a/scripts/graph_extruder.py +++ b/scripts/graph_extruder.py @@ -67,13 +67,16 @@ def calc_pa_raw(t, positions): i = time_to_index(t) return positions[i] + pa * (positions[i+1] - positions[i]) -def calc_pa_smooth(t, positions): +def calc_pa_weighted(t, positions): + base_index = time_to_index(t) start_index = time_to_index(t - PA_HALF_SMOOTH_T) + 1 end_index = time_to_index(t + PA_HALF_SMOOTH_T) + diff = .5 * (end_index - start_index) pa = PRESSURE_ADVANCE * INV_SEG_TIME - pa_data = [positions[i] + pa * (positions[i+1] - positions[i]) + pa_data = [(positions[i] + pa * (positions[i+1] - positions[i])) + * (diff - abs(i-base_index)) for i in range(start_index, end_index)] - return sum(pa_data) / (end_index - start_index) + return sum(pa_data) / diff**2 ###################################################################### @@ -92,7 +95,7 @@ def plot_motion(): pa_positions = [calc_pa_raw(t, positions) for t in times] pa_velocities = gen_deriv(pa_positions) # Smoothed motion - sm_positions = [calc_pa_smooth(t, positions) for t in times] + sm_positions = [calc_pa_weighted(t, positions) for t in times] sm_velocities = gen_deriv(sm_positions) # Build plot shift_times = [t - MARGIN_TIME for t in times] -- cgit v1.2.3-70-g09d2