trapq: Store toolhead.set_position() updates in trapq history

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-07-23 12:46:14 -04:00
parent 45c232b2c7
commit 07f0ecb4d0
4 changed files with 24 additions and 1 deletions

View File

@ -83,6 +83,8 @@ defs_trapq = """
struct trapq *trapq_alloc(void); struct trapq *trapq_alloc(void);
void trapq_free(struct trapq *tq); void trapq_free(struct trapq *tq);
void trapq_finalize_moves(struct trapq *tq, double print_time); void trapq_finalize_moves(struct trapq *tq, double print_time);
void trapq_set_position(struct trapq *tq, double print_time
, double pos_x, double pos_y, double pos_z);
int trapq_extract_old(struct trapq *tq, struct pull_move *p, int max int trapq_extract_old(struct trapq *tq, struct pull_move *p, int max
, double start_time, double end_time); , double start_time, double end_time);
""" """

View File

@ -197,6 +197,23 @@ trapq_finalize_moves(struct trapq *tq, double print_time)
} }
} }
// Note a position change in the trapq history
void __visible
trapq_set_position(struct trapq *tq, double print_time
, double pos_x, double pos_y, double pos_z)
{
// Flush all moves from trapq
trapq_finalize_moves(tq, NEVER_TIME);
// Add a marker to the trapq history
struct move *m = move_alloc();
m->print_time = print_time;
m->start_pos.x = pos_x;
m->start_pos.y = pos_y;
m->start_pos.z = pos_z;
list_add_head(&m->node, &tq->history);
}
// Return history of movement queue // Return history of movement queue
int __visible int __visible
trapq_extract_old(struct trapq *tq, struct pull_move *p, int max trapq_extract_old(struct trapq *tq, struct pull_move *p, int max

View File

@ -44,6 +44,8 @@ void trapq_free(struct trapq *tq);
void trapq_check_sentinels(struct trapq *tq); void trapq_check_sentinels(struct trapq *tq);
void trapq_add_move(struct trapq *tq, struct move *m); void trapq_add_move(struct trapq *tq, struct move *m);
void trapq_finalize_moves(struct trapq *tq, double print_time); void trapq_finalize_moves(struct trapq *tq, double print_time);
void trapq_set_position(struct trapq *tq, double print_time
, double pos_x, double pos_y, double pos_z);
int trapq_extract_old(struct trapq *tq, struct pull_move *p, int max int trapq_extract_old(struct trapq *tq, struct pull_move *p, int max
, double start_time, double end_time); , double start_time, double end_time);

View File

@ -401,7 +401,9 @@ class ToolHead:
return list(self.commanded_pos) return list(self.commanded_pos)
def set_position(self, newpos, homing_axes=()): def set_position(self, newpos, homing_axes=()):
self.flush_step_generation() self.flush_step_generation()
self.trapq_finalize_moves(self.trapq, self.reactor.NEVER) ffi_main, ffi_lib = chelper.get_ffi()
ffi_lib.trapq_set_position(self.trapq, self.print_time,
newpos[0], newpos[1], newpos[2])
self.commanded_pos[:] = newpos self.commanded_pos[:] = newpos
self.kin.set_position(newpos, homing_axes) self.kin.set_position(newpos, homing_axes)
self.printer.send_event("toolhead:set_position") self.printer.send_event("toolhead:set_position")