diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-11-08 13:31:47 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-11-08 14:17:35 -0500 |
commit | bdc7383e51ca37ec87c20fdbc14154ff1417a9dc (patch) | |
tree | f5ce1681efa159430769ba687d28e0141e20ed43 /klippy | |
parent | 0bfb655f665c2f29efa14c28d4dc5c47f151d09a (diff) | |
download | kutter-bdc7383e51ca37ec87c20fdbc14154ff1417a9dc.tar.gz kutter-bdc7383e51ca37ec87c20fdbc14154ff1417a9dc.tar.xz kutter-bdc7383e51ca37ec87c20fdbc14154ff1417a9dc.zip |
itersolve: Improve numerical stability of itersolve_generate_steps() loop
Minor rework of the loop to reduce the chance that numerical stability
could cause an infinite loop.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/chelper/itersolve.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/klippy/chelper/itersolve.c b/klippy/chelper/itersolve.c index c86b35e3..8f7905c3 100644 --- a/klippy/chelper/itersolve.c +++ b/klippy/chelper/itersolve.c @@ -147,20 +147,17 @@ itersolve_generate_steps(struct stepper_kinematics *sk, double flush_time) if (!sk->tq || list_empty(&sk->tq->moves)) return 0; struct move *m = list_first_entry(&sk->tq->moves, struct move, node); + while (last_flush_time >= m->print_time + m->move_t) { + if (list_is_last(&m->node, &sk->tq->moves)) + return 0; + m = list_next_entry(m, node); + } for (;;) { - double move_print_time = m->print_time; - double move_end_time = move_print_time + m->move_t; - if (last_flush_time >= move_end_time) { - if (list_is_last(&m->node, &sk->tq->moves)) - break; - m = list_next_entry(m, node); - continue; - } - double start = move_print_time, end = move_end_time; + double start = m->print_time, end = start + m->move_t; if (start < last_flush_time) start = last_flush_time; if (start >= flush_time) - break; + return 0; if (end > flush_time) end = flush_time; if (check_active(sk, m)) { @@ -169,8 +166,10 @@ itersolve_generate_steps(struct stepper_kinematics *sk, double flush_time) return ret; } last_flush_time = end; + if (list_is_last(&m->node, &sk->tq->moves)) + return 0; + m = list_next_entry(m, node); } - return 0; } // Check if the given stepper is likely to be active in the given time range |