From fce9920936fb9c2cbc27caf2f4fa67f992df5f36 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Fri, 11 Feb 2022 18:50:21 +0100 Subject: [PATCH] Fixes for backlash compensation: no longer resets current direction on a soft reset/stop, added handling of backlash setting changes per axis. --- README.md | 4 ++-- changelog.md | 8 ++++++++ grbl.h | 2 +- grbllib.c | 4 +--- limits.c | 4 ++-- motion_control.c | 16 +++++++--------- motion_control.h | 4 ++-- planner.c | 9 +++++++-- settings.c | 17 ++++++++++------- state_machine.c | 3 --- 10 files changed, 40 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 9719cd4..c6d1ded 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20220131, see the [changelog](changelog.md) for details. +Latest build date is 20220210, see the [changelog](changelog.md) for details. __NOTE:__ A settings reset will be performed on an update for versions earlier than 20211122. Backup and restore of settings is recommended. __IMPORTANT!__ A new setting has been introduced for ganged axes motors in version 20211121. I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured. @@ -83,4 +83,4 @@ List of Supported G-Codes: Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes. --- -2022-01-23 +2022-02-10 diff --git a/changelog.md b/changelog.md index ac96ad4..fd014f5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ ## grblHAL changelog +Build 20220210: + +Core: + +* Fixes for backlash compensation: no longer resets current direction on a soft reset/stop, added handling of backlash setting changes per axis. + +--- + 20220209: Plugins: diff --git a/grbl.h b/grbl.h index 7acf8ed..21a83b8 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20220204 +#define GRBL_BUILD 20220210 // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/grbllib.c b/grbllib.c index 394e977..f3b827c 100644 --- a/grbllib.c +++ b/grbllib.c @@ -263,9 +263,7 @@ int grbl_enter (void) plan_reset(); // Clear block buffer and planner variables st_reset(); // Clear stepper subsystem variables. limits_set_homing_axes(); // Set axes to be homed from settings. -#ifdef ENABLE_BACKLASH_COMPENSATION - mc_backlash_init(); // Init backlash configuration. -#endif + // Sync cleared gcode and planner positions to current system position. sync_position(); diff --git a/limits.c b/limits.c index 32d14ad..5a26f0e 100644 --- a/limits.c +++ b/limits.c @@ -3,7 +3,7 @@ Part of grblHAL - Copyright (c) 2017-2021 Terje Io + Copyright (c) 2017-2022 Terje Io Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC Copyright (c) 2009-2011 Simen Svale Skogsrud @@ -454,7 +454,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar #endif #ifdef ENABLE_BACKLASH_COMPENSATION - mc_backlash_init(); + mc_backlash_init(cycle); #endif sys.step_control.flags = 0; // Return step control to normal operation. sys.homed.mask |= cycle.mask; diff --git a/motion_control.c b/motion_control.c index 3f8e1a7..9392c1b 100644 --- a/motion_control.c +++ b/motion_control.c @@ -59,22 +59,20 @@ #ifdef ENABLE_BACKLASH_COMPENSATION static float target_prev[N_AXIS]; -static axes_signals_t dir_negative, backlash_enabled; +static axes_signals_t dir_negative = {0}, backlash_enabled = {0}; -void mc_backlash_init (void) +void mc_backlash_init (axes_signals_t axes) { uint_fast8_t idx = N_AXIS; - backlash_enabled.mask = dir_negative.value = 0; - do { - if(settings.axis[--idx].backlash > 0.0001f) - backlash_enabled.mask |= bit(idx); - dir_negative.value |= bit(idx); + idx--; + if(bit_istrue(axes.mask, bit(idx))) { + BIT_SET(backlash_enabled.mask, bit(idx), settings.axis[idx].backlash > 0.0001f); + BIT_SET(dir_negative.mask, bit(idx), bit_isfalse(settings.homing.dir_mask.mask, bit(idx))); + } } while(idx); - dir_negative.value ^= settings.homing.dir_mask.value; - mc_sync_backlash_position(); } diff --git a/motion_control.h b/motion_control.h index f061f72..5652c9c 100644 --- a/motion_control.h +++ b/motion_control.h @@ -3,7 +3,7 @@ Part of grblHAL - Copyright (c) 2017-2019 Terje Io + Copyright (c) 2017-2022 Terje Io Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC Copyright (c) 2009-2011 Simen Svale Skogsrud @@ -75,7 +75,7 @@ void mc_cubic_b_spline(float *target, plan_line_data_t *pl_data, float *position void mc_reset (void); #ifdef ENABLE_BACKLASH_COMPENSATION -void mc_backlash_init (void); +void mc_backlash_init (axes_signals_t axes); void mc_sync_backlash_position (void); #endif diff --git a/planner.c b/planner.c index 294842c..f2ad813 100644 --- a/planner.c +++ b/planner.c @@ -3,7 +3,7 @@ Part of grblHAL - Copyright (c) 2017-2021 Terje Io + Copyright (c) 2017-2022 Terje Io Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC Copyright (c) 2009-2011 Simen Svale Skogsrud Copyright (c) 2011 Jens Geisler @@ -32,13 +32,15 @@ #ifdef KINEMATICS_API #include "kinematics.h" #endif - #ifndef MINIMUM_JUNCTION_SPEED #define MINIMUM_JUNCTION_SPEED 0.0f #endif #ifndef MINIMUM_FEED_RATE #define MINIMUM_FEED_RATE 1.0f #endif +#ifdef ENABLE_BACKLASH_COMPENSATION +void mc_sync_backlash_position (void); +#endif static plan_block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions static plan_block_t *block_buffer_tail = NULL; // Pointer to the block to process now @@ -542,6 +544,9 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) void plan_sync_position () { memcpy(pl.position, sys.position, sizeof(pl.position)); +#ifdef ENABLE_BACKLASH_COMPENSATION + mc_sync_backlash_position(); +#endif } diff --git a/settings.c b/settings.c index ffac814..b2f9733 100644 --- a/settings.c +++ b/settings.c @@ -1106,7 +1106,12 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) case Setting_AxisBacklash: #ifdef ENABLE_BACKLASH_COMPENSATION - settings.axis[idx].backlash = value; + if(settings.axis[idx].backlash != value) { + axes_signals_t axes; + axes.mask = bit(idx); + settings.axis[idx].backlash = value; + mc_backlash_init(axes); + } #else status = Status_SettingDisabled; #endif @@ -1619,7 +1624,9 @@ void settings_restore (settings_restore_t restore) settings.control_invert.mask &= hal.signals_cap.mask; settings.spindle.invert.ccw &= hal.driver_cap.spindle_dir; settings.spindle.invert.pwm &= hal.driver_cap.spindle_pwm_invert; - +#ifdef ENABLE_BACKLASH_COMPENSATION + mc_backlash_init((axes_signals_t){AXES_BITMASK}); +#endif settings_write_global(); } @@ -2153,10 +2160,6 @@ status_code_t settings_store_setting (setting_id_t id, char *svalue) if(set->save) set->save(); -#ifdef ENABLE_BACKLASH_COMPENSATION - mc_backlash_init(); -#endif - if(set->on_changed) set->on_changed(&settings); @@ -2191,7 +2194,7 @@ void settings_init (void) #endif report_init(); #ifdef ENABLE_BACKLASH_COMPENSATION - mc_backlash_init(); + mc_backlash_init((axes_signals_t){AXES_BITMASK}); #endif hal.settings_changed(&settings); diff --git a/state_machine.c b/state_machine.c index 56c3cac..88aa72a 100644 --- a/state_machine.c +++ b/state_machine.c @@ -363,9 +363,6 @@ static void state_await_motion_cancel (uint_fast16_t rt_exec) plan_reset(); st_reset(); sync_position(); -#ifdef ENABLE_BACKLASH_COMPENSATION - mc_sync_backlash_position(); -#endif sys.suspend = false; } state_set(pending_state);