From fd3438da34c2adbb319dfe6e5d7251dffd15d3a3 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Wed, 29 Jan 2025 15:51:25 +0100 Subject: [PATCH] Added API call for overriding jerk settings, symbol for M201.3 gcode. --- changelog.md | 18 ++++++++++++++++++ gcode.c | 6 +++--- gcode.h | 1 + grbl.h | 2 +- settings.c | 36 +++++++++++++++++++++++++++++++++++- settings.h | 5 +++++ 6 files changed, 63 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 33306cd..3e946f6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,23 @@ ## grblHAL changelog +Build 20250129 + +Core: + +* Added API call for overriding jerk settings, symbol for `M201.3` gcode. + +Drivers: + +* ESP32, STM32F4xx and STM32F7xx: added workaround for FatFs corrupting allocated memory after a failed mount attempt. + +Plugins: + +* SD card: added workaround for FatFs corrupting allocated memory after a failed mount attempt. Ref. RP2040 issue [#112](https://github.com/grblHAL/RP2040/issues/112). + +* OpenPNP: added tentative support for setting jerk with `M201.3`. Not tested! + +--- + Build 20250128 Core: diff --git a/gcode.c b/gcode.c index e66a612..722020a 100644 --- a/gcode.c +++ b/gcode.c @@ -1279,7 +1279,7 @@ status_code_t gc_execute_block (char *block) continue; } - if(mantissa > 0) + if(int_value <= 99 && mantissa > 0) FAIL(Status_GcodeCommandValueNotInteger); // [No Mxx.x commands] user_mcode = UserMCode_Unsupported; @@ -1398,8 +1398,8 @@ status_code_t gc_execute_block (char *block) break; default: - if(grbl.user_mcode.check && (user_mcode = grbl.user_mcode.check((user_mcode_t)int_value))) { - gc_block.user_mcode = (user_mcode_t)int_value; + if(grbl.user_mcode.check && (user_mcode = grbl.user_mcode.check((user_mcode_t)(mantissa ? int_value * 100 + mantissa : int_value)))) { + gc_block.user_mcode = (user_mcode_t)(mantissa ? int_value * 100 + mantissa : int_value); word_bit.modal_group.M10 = On; } else FAIL(Status_GcodeUnsupportedCommand); // [Unsupported M command] diff --git a/gcode.h b/gcode.h index 89540d6..1c5491d 100644 --- a/gcode.h +++ b/gcode.h @@ -254,6 +254,7 @@ typedef enum { LaserPPI_Rate = 127, //!< 127 - M127 LaserPPI_PulseLength = 128, //!< 128 - M128 RGB_WriteLEDs = 150, //!< 150 - M150, Marlin format + OpenPNP_SetJerk = 20130, //!< 20130 - M201.3 OpenPNP_SetAcceleration = 204, //!< 204 - M204 SetFeedOverrides = 220, //!< 220 - M220, Marlin format PWMServo_SetPosition= 280, //!< 280 - M280, Marlin format diff --git a/grbl.h b/grbl.h index 4cd7907..a5914a8 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20250128 +#define GRBL_BUILD 20250129 #define GRBL_URL "https://github.com/grblHAL" diff --git a/settings.c b/settings.c index 0b069e9..64f19ec 100644 --- a/settings.c +++ b/settings.c @@ -454,6 +454,9 @@ static char axis_steps[9] = "step/mm"; static struct { bool valid; float acceleration[N_AXIS]; +#if ENABLE_JERK_ACCELERATION + float jerk[N_AXIS]; +#endif } override_backup = { .valid = false }; static void save_override_backup (void) @@ -463,6 +466,9 @@ static void save_override_backup (void) do { idx--; override_backup.acceleration[idx] = settings.axis[idx].acceleration; +#if ENABLE_JERK_ACCELERATION + override_backup.jerk[idx] = settings.axis[idx].jerk; +#endif } while(idx); override_backup.valid = true; @@ -475,6 +481,9 @@ static void restore_override_backup (void) if(override_backup.valid) do { idx--; settings.axis[idx].acceleration = override_backup.acceleration[idx]; +#if ENABLE_JERK_ACCELERATION + settings.axis[idx].jerk = override_backup.jerk[idx]; +#endif } while(idx); } @@ -499,6 +508,31 @@ bool settings_override_acceleration (uint8_t axis, float acceleration) return true; } +#if ENABLE_JERK_ACCELERATION + +// Temporarily override jerk, if 0 restore to setting value. +// Note: only allowed when current state is idle. +bool settings_override_jerk (uint8_t axis, float jerk) +{ + sys_state_t state = state_get(); + + if(!(state == STATE_IDLE || (state & (STATE_HOMING|STATE_ALARM)))) + return false; + + if(jerk <= 0.0f) { + if(override_backup.valid) + settings.axis[axis].jerk = override_backup.jerk[axis]; + } else { + if(!override_backup.valid) + save_override_backup(); + settings.axis[axis].jerk = jerk * 60.0f * 60.0f * 60.0f; // Limit max to setting value? + } + + return true; +} + +#endif // ENABLE_JERK_ACCELERATION + // --- static void homing_pulloff_init (float pulloff) @@ -1205,7 +1239,7 @@ static status_code_t set_axis_setting (setting_id_t setting, float value) #if ENABLE_JERK_ACCELERATION case Setting_AxisJerk: - settings.axis[idx].jerk = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for internal use. + settings.axis[idx].jerk = override_backup.jerk[idx] = value * 60.0f * 60.0f * 60.0f; // Convert to mm/min^3 for internal use. break; #endif diff --git a/settings.h b/settings.h index 4821e46..e65e1ad 100644 --- a/settings.h +++ b/settings.h @@ -1104,6 +1104,11 @@ bool settings_read_coord_data(coord_system_id_t id, float (*coord_data)[N_AXIS]) // Temporarily override acceleration, if 0 restore to configured setting value bool settings_override_acceleration (uint8_t axis, float acceleration); +#if ENABLE_JERK_ACCELERATION +// Temporarily override jerk, if 0 restore to configured setting value. +bool settings_override_jerk (uint8_t axis, float jerk); +#endif + void settings_register (setting_details_t *details); setting_details_t *settings_get_details (void); bool settings_is_group_available (setting_group_t group);