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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-02-25 12:54:55 -05:00
parent d86bf0b927
commit acd165cbea
4 changed files with 105 additions and 31 deletions

View file

@ -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)