From acd165cbea2f48812b7fd96c28b81622e5c13665 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 25 Feb 2020 12:54:55 -0500 Subject: stepcompress: Implement a step+dir+step filter Some stepper motor drivers do not respond well to rapid "step + direction change + step" events. In particular, it is believed this can cause "over current" events on the tmc2208 drivers when they are in "stealthchop" mode. Detect these events and remove them from the generated step times. Signed-off-by: Kevin O'Connor --- klippy/chelper/itersolve.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'klippy/chelper/itersolve.c') diff --git a/klippy/chelper/itersolve.c b/klippy/chelper/itersolve.c index 1094e5f3..9cae55fd 100644 --- a/klippy/chelper/itersolve.c +++ b/klippy/chelper/itersolve.c @@ -13,6 +13,11 @@ #include "stepcompress.h" // queue_append_start #include "trapq.h" // struct move + +/**************************************************************** + * Main iterative solver + ****************************************************************/ + struct timepos { double time, position; }; @@ -66,7 +71,7 @@ itersolve_gen_steps_range(struct stepper_kinematics *sk, struct move *m double start = move_start - m->print_time, end = move_end - m->print_time; struct timepos last = { start, sk->commanded_pos }, low = last, high = last; double seek_time_delta = SEEK_TIME_RESET; - int sdir = !!stepcompress_get_step_dir(sk->sc), is_dir_change = 0; + int sdir = stepcompress_get_step_dir(sk->sc), is_dir_change = 0; for (;;) { double diff = high.position - last.position, dist = sdir ? diff : -diff; if (dist >= half_step) { @@ -90,6 +95,9 @@ itersolve_gen_steps_range(struct stepper_kinematics *sk, struct move *m if (low.time < high.time) // The existing search range is still valid continue; + } else if (dist > 0.) { + // Avoid rollback if stepper fully reaches target position + stepcompress_commit(sk->sc); } else if (unlikely(dist < -(half_step + .000000001))) { // Found direction change is_dir_change = 1; @@ -127,6 +135,11 @@ itersolve_gen_steps_range(struct stepper_kinematics *sk, struct move *m return 0; } + +/**************************************************************** + * Interface functions + ****************************************************************/ + // Check if a move is likely to cause movement on a stepper static inline int check_active(struct stepper_kinematics *sk, struct move *m) -- cgit v1.2.3-70-g09d2