From 5967839ab38f8e984a384db1f64e781cffb9e739 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Tue, 1 Aug 2017 10:27:42 -0600 Subject: [PATCH] Improved fix for rare lowering feed/rapid override bug. [fix] In the previous hot fix, there was still (rarer) potential for very small floating point errors incorrectly handle an override deceleration and crash Grbl. Re-factored the if-then statement in terms of speed changes, rather than distance, to completely eliminate the issue. --- doc/log/commit_log_v1.1.txt | 8 ++++++++ grbl/grbl.h | 2 +- grbl/stepper.c | 9 ++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/log/commit_log_v1.1.txt b/doc/log/commit_log_v1.1.txt index b4d13b46..0717f62c 100644 --- a/doc/log/commit_log_v1.1.txt +++ b/doc/log/commit_log_v1.1.txt @@ -1,3 +1,11 @@ +---------------- +Date: 2017-07-31 +Author: Sonny Jeon +Subject: Hot fix for rare lowering feed override bug. + +[fix] Squashed a very rare bug when lowering the feedrate (or rapid) override. When in the very strict set of circumstances with acceleration settings, override step size, and current speed, an internal calculation would cause Grbl to crash. The fix was an overlooked equality statement that should have been a less than or equal, not a less than. + + ---------------- Date: 2017-07-17 Author: Sonny Jeon diff --git a/grbl/grbl.h b/grbl/grbl.h index f4eb0dda..33b51453 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20170731" +#define GRBL_VERSION_BUILD "20170801" // Define standard libraries used by Grbl. #include diff --git a/grbl/stepper.c b/grbl/stepper.c index 2f6b18be..3bfccd49 100644 --- a/grbl/stepper.c +++ b/grbl/stepper.c @@ -734,7 +734,7 @@ void st_prep_buffer() } else { // Decelerate to cruise or cruise-decelerate types. Guaranteed to intersect updated plan. - prep.decelerate_after = inv_2_accel*(nominal_speed_sqr-exit_speed_sqr); + prep.decelerate_after = inv_2_accel*(nominal_speed_sqr-exit_speed_sqr); // Should always be >= 0.0 due to planner reinit. prep.maximum_speed = nominal_speed; prep.ramp_type = RAMP_DECEL_OVERRIDE; } @@ -806,15 +806,14 @@ void st_prep_buffer() switch (prep.ramp_type) { case RAMP_DECEL_OVERRIDE: speed_var = pl_block->acceleration*time_var; - mm_var = time_var*(prep.current_speed - 0.5*speed_var); - mm_remaining -= mm_var; - if ((mm_remaining <= prep.accelerate_until) || (mm_var <= 0.0)) { + if (prep.current_speed-prep.maximum_speed <= speed_var) { // Cruise or cruise-deceleration types only for deceleration override. - mm_remaining = prep.accelerate_until; // NOTE: 0.0 at EOB + mm_remaining = prep.accelerate_until; time_var = 2.0*(pl_block->millimeters-mm_remaining)/(prep.current_speed+prep.maximum_speed); prep.ramp_type = RAMP_CRUISE; prep.current_speed = prep.maximum_speed; } else { // Mid-deceleration override ramp. + mm_remaining -= time_var*(prep.current_speed - 0.5*speed_var); prep.current_speed -= speed_var; } break;