Skip to content

Commit

Permalink
Improved fix for rare lowering feed/rapid override bug.
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
chamnit committed Aug 1, 2017
1 parent 477a94c commit 5967839
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions doc/log/commit_log_v1.1.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion grbl/grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <avr/io.h>
Expand Down
9 changes: 4 additions & 5 deletions grbl/stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5967839

Please sign in to comment.