From 812e7b48536f2d974fcac8bed9f3eb98f83c6e47 Mon Sep 17 00:00:00 2001 From: bdring Date: Fri, 27 Mar 2020 20:58:00 -0500 Subject: [PATCH] Parking Feature and Spindle Fix - The M56 parking feature override is now implemented - Fixed a typo in how the spindle got a PWM channel --- Grbl_Esp32/gcode.cpp | 31 ++++++++++++++++++++++++++++--- Grbl_Esp32/gcode.h | 13 ++++++++++++- Grbl_Esp32/motion_control.cpp | 9 +++++++++ Grbl_Esp32/motion_control.h | 3 +++ Grbl_Esp32/report.cpp | 9 +++++++++ Grbl_Esp32/spindle_control.cpp | 2 +- 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Grbl_Esp32/gcode.cpp b/Grbl_Esp32/gcode.cpp index dcf1a9ac..3c09b498 100644 --- a/Grbl_Esp32/gcode.cpp +++ b/Grbl_Esp32/gcode.cpp @@ -343,10 +343,14 @@ uint8_t gc_execute_line(char* line, uint8_t client) { case 9: gc_block.modal.coolant = COOLANT_DISABLE; break; - default: - FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported M command] } break; +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + case 56: + word_bit = MODAL_GROUP_M9; + gc_block.modal.override = OVERRIDE_PARKING_MOTION; + break; +#endif case 62: case 63: //grbl_sendf(CLIENT_SERIAL,"M%d...\r\n", int_value); @@ -580,6 +584,14 @@ uint8_t gc_execute_line(char* line, uint8_t client) { // [7. Spindle control ]: N/A // [8. Coolant control ]: N/A // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED. +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (bit_istrue(command_words, bit(MODAL_GROUP_M9))) { // Already set as enabled in parser. + if (bit_istrue(value_words, bit(WORD_P))) { + if (gc_block.values.p == 0.0) gc_block.modal.override = OVERRIDE_DISABLED; + bit_false(value_words, bit(WORD_P)); + } + } +#endif // [10. Dwell ]: P value missing. P is negative (done.) NOTE: See below. if (gc_block.non_modal_command == NON_MODAL_DWELL) { if (bit_isfalse(value_words, bit(WORD_P))) { @@ -1128,7 +1140,13 @@ uint8_t gc_execute_line(char* line, uint8_t client) { else FAIL(STATUS_P_PARAM_MAX_EXCEEDED); } - // [9. Enable/disable feed rate or spindle overrides ]: NOT SUPPORTED. Always enabled. + // [9. Override control ]: NOT SUPPORTED. Always enabled. Except for a Grbl-only parking control. +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (gc_state.modal.override != gc_block.modal.override) { + gc_state.modal.override = gc_block.modal.override; + mc_override_ctrl_update(gc_state.modal.override); + } +#endif // [10. Dwell ]: if (gc_block.non_modal_command == NON_MODAL_DWELL) mc_dwell(gc_block.values.p); @@ -1258,6 +1276,13 @@ uint8_t gc_execute_line(char* line, uint8_t client) { gc_state.modal.coord_select = 0; // G54 gc_state.modal.spindle = SPINDLE_DISABLE; gc_state.modal.coolant = COOLANT_DISABLE; +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL +#ifdef DEACTIVATE_PARKING_UPON_INIT + gc_state.modal.override = OVERRIDE_DISABLED; +#else + gc_state.modal.override = OVERRIDE_PARKING_MOTION; +#endif +#endif // gc_state.modal.override = OVERRIDE_DISABLE; // Not supported. #ifdef RESTORE_OVERRIDES_AFTER_PROGRAM_END sys.f_override = DEFAULT_FEED_OVERRIDE; diff --git a/Grbl_Esp32/gcode.h b/Grbl_Esp32/gcode.h index f2d9f7b9..2415155a 100644 --- a/Grbl_Esp32/gcode.h +++ b/Grbl_Esp32/gcode.h @@ -47,7 +47,8 @@ #define MODAL_GROUP_M6 14 // [M6] Tool change #define MODAL_GROUP_M7 12 // [M3,M4,M5] Spindle turning #define MODAL_GROUP_M8 13 // [M7,M8,M9] Coolant control -#define MODAL_GROUP_M10 14 // [M62, M63] User Defined http://linuxcnc.org/docs/html/gcode/overview.html#_modal_groups +#define MODAL_GROUP_M9 14 // [M56] Override control +#define MODAL_GROUP_M10 15 // [M62, M63] User Defined http://linuxcnc.org/docs/html/gcode/overview.html#_modal_groups // #define OTHER_INPUT_F 14 // #define OTHER_INPUT_S 15 @@ -126,6 +127,15 @@ #define COOLANT_FLOOD_ENABLE PL_COND_FLAG_COOLANT_FLOOD // M8 (NOTE: Uses planner condition bit flag) #define COOLANT_MIST_ENABLE PL_COND_FLAG_COOLANT_MIST // M7 (NOTE: Uses planner condition bit flag) +// Modal Group M9: Override control +#ifdef DEACTIVATE_PARKING_UPON_INIT + #define OVERRIDE_DISABLED 0 // (Default: Must be zero) + #define OVERRIDE_PARKING_MOTION 1 // M56 +#else + #define OVERRIDE_PARKING_MOTION 0 // M56 (Default: Must be zero) + #define OVERRIDE_DISABLED 1 // Parking disabled. +#endif + // modal Group M10: User I/O control #define NON_MODAL_IO_ENABLE 1 #define NON_MODAL_IO_DISABLE 2 @@ -203,6 +213,7 @@ typedef struct { uint8_t spindle; // {M3,M4,M5} uint8_t tool_change; // {M6} uint8_t io_control; // {M62, M63} + uint8_t override; // {M56} } gc_modal_t; typedef struct { diff --git a/Grbl_Esp32/motion_control.cpp b/Grbl_Esp32/motion_control.cpp index eab8e646..dba7b022 100644 --- a/Grbl_Esp32/motion_control.cpp +++ b/Grbl_Esp32/motion_control.cpp @@ -404,6 +404,15 @@ void mc_parking_motion(float* parking_target, plan_line_data_t* pl_data) { } } +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL +void mc_override_ctrl_update(uint8_t override_state) { + // Finish all queued commands before altering override control state + protocol_buffer_synchronize(); + if (sys.abort) return; + sys.override_ctrl = override_state; +} +#endif + // Method to ready the system to reset by setting the realtime reset command and killing any // active processes in the system. This also checks if a system reset is issued while Grbl diff --git a/Grbl_Esp32/motion_control.h b/Grbl_Esp32/motion_control.h index d1026200..24ea92dc 100644 --- a/Grbl_Esp32/motion_control.h +++ b/Grbl_Esp32/motion_control.h @@ -65,6 +65,9 @@ void mc_homing_cycle(uint8_t cycle_mask); // Perform tool length probe cycle. Requires probe switch. uint8_t mc_probe_cycle(float* target, plan_line_data_t* pl_data, uint8_t parser_flags); +// Handles updating the override control state. +void mc_override_ctrl_update(uint8_t override_state); + // Plans and executes the single special motion case for parking. Independent of main planner buffer. void mc_parking_motion(float* parking_target, plan_line_data_t* pl_data); diff --git a/Grbl_Esp32/report.cpp b/Grbl_Esp32/report.cpp index c64cf4b1..8476c839 100644 --- a/Grbl_Esp32/report.cpp +++ b/Grbl_Esp32/report.cpp @@ -458,6 +458,12 @@ void report_gcode_modes(uint8_t client) { if (gc_state.modal.coolant & PL_COND_FLAG_COOLANT_FLOOD) strcat(modes_rpt, " M8"); } else strcat(modes_rpt, " M9"); + +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + if (sys.override_ctrl == OVERRIDE_PARKING_MOTION) + strcat(modes_rpt, " M56"); +#endif + sprintf(temp, " T%d", gc_state.tool); strcat(modes_rpt, temp); if (bit_istrue(settings.flags, BITFLAG_REPORT_INCHES)) @@ -524,6 +530,9 @@ void report_build_info(char* line, uint8_t client) { #ifdef ENABLE_SD_CARD strcat(build_info, "S"); #endif +#ifdef ENABLE_PARKING_OVERRIDE_CONTROL + serial_write('R'); +#endif #if defined (ENABLE_WIFI) strcat(build_info, "W"); #endif diff --git a/Grbl_Esp32/spindle_control.cpp b/Grbl_Esp32/spindle_control.cpp index 5061db92..a7f0f7b2 100644 --- a/Grbl_Esp32/spindle_control.cpp +++ b/Grbl_Esp32/spindle_control.cpp @@ -56,7 +56,7 @@ void spindle_init() { pinMode(SPINDLE_DIR_PIN, OUTPUT); #endif // use the LED control feature to setup PWM https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/ledc.html - spindle_pwm_chan_num - sys_get_next_PWM_chan_num(); + spindle_pwm_chan_num = sys_get_next_PWM_chan_num(); ledcSetup(spindle_pwm_chan_num, (double)settings.spindle_pwm_freq, SPINDLE_PWM_BIT_PRECISION); // setup the channel ledcAttachPin(SPINDLE_PWM_PIN, spindle_pwm_chan_num); // attach the PWM to the pin // Start with spindle off off