From 85b0c7a8b48e68fe0c4a5e8b2d8cb24a0789a231 Mon Sep 17 00:00:00 2001 From: Sonny Jeon Date: Wed, 25 Feb 2015 08:29:56 -0700 Subject: [PATCH] G91.1 support. Fixed a config.h option. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - G91.1 support added. This g-code sets the arc IJK distance mode to incremental, which is the default already. This simply helps reduce parsing errors with certain CAM programs that output this command. - Max step rate checks weren’t being compiled in if the option was enabled. Fixed now. - Alarm codes were not displaying correctly when GUI reporting mode was enabled. Due to unsigned int problem. Changed codes to positive values since they aren’t shared with other codes. --- README.md | 1 + grbl/gcode.c | 13 ++++++++++--- grbl/gcode.h | 20 ++++++++++++-------- grbl/report.c | 9 +++++---- grbl/report.h | 14 +++++++------- grbl/settings.c | 8 ++++++-- 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 3e69e23..962d932 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ List of Supported G-Codes in Grbl v0.9 - Feed Rate Modes: G93, G94 - Unit Modes: G20, G21 - Distance Modes: G90, G91 + - Arc IJK Distance Modes: G91.1 - Plane Select Modes: G17, G18, G19 - Tool Length Offset Modes: G43.1, G49 - Cutter Compensation Modes: G40 diff --git a/grbl/gcode.c b/grbl/gcode.c index b915e48..37f9ff9 100644 --- a/grbl/gcode.c +++ b/grbl/gcode.c @@ -213,9 +213,16 @@ uint8_t gc_execute_line(char *line) } break; case 90: case 91: - word_bit = MODAL_GROUP_G3; - if (int_value == 90) { gc_block.modal.distance = DISTANCE_MODE_ABSOLUTE; } // G90 - else { gc_block.modal.distance = DISTANCE_MODE_INCREMENTAL; } // G91 + if (mantissa == 0) { + word_bit = MODAL_GROUP_G3; + if (int_value == 90) { gc_block.modal.distance = DISTANCE_MODE_ABSOLUTE; } // G90 + else { gc_block.modal.distance = DISTANCE_MODE_INCREMENTAL; } // G91 + } else { + word_bit = MODAL_GROUP_G4; + if (mantissa != 10) { FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); } // [G90.1 not supported] + mantissa = 0; // Set to zero to indicate valid non-integer G command. + // Otherwise, arc IJK incremental mode is default. G91.1 does nothing. + } break; case 93: case 94: word_bit = MODAL_GROUP_G5; diff --git a/grbl/gcode.h b/grbl/gcode.h index 0b478d0..46df351 100644 --- a/grbl/gcode.h +++ b/grbl/gcode.h @@ -33,15 +33,16 @@ #define MODAL_GROUP_G1 1 // [G0,G1,G2,G3,G38.2,G80] Motion #define MODAL_GROUP_G2 2 // [G17,G18,G19] Plane selection #define MODAL_GROUP_G3 3 // [G90,G91] Distance mode -#define MODAL_GROUP_G5 4 // [G93,G94] Feed rate mode -#define MODAL_GROUP_G6 5 // [G20,G21] Units -#define MODAL_GROUP_G7 6 // [G40] Cutter radius compensation mode. G41/42 NOT SUPPORTED. -#define MODAL_GROUP_G8 7 // [G43,G43.1,G49] Tool length offset -#define MODAL_GROUP_G12 8 // [G54,G55,G56,G57,G58,G59] Coordinate system selection +#define MODAL_GROUP_G4 4 // [G90.1,G91.1] Arc IJK distance mode +#define MODAL_GROUP_G5 5 // [G93,G94] Feed rate mode +#define MODAL_GROUP_G6 6 // [G20,G21] Units +#define MODAL_GROUP_G7 7 // [G40] Cutter radius compensation mode. G41/42 NOT SUPPORTED. +#define MODAL_GROUP_G8 8 // [G43,G43.1,G49] Tool length offset +#define MODAL_GROUP_G12 9 // [G54,G55,G56,G57,G58,G59] Coordinate system selection -#define MODAL_GROUP_M4 9 // [M0,M1,M2,M30] Stopping -#define MODAL_GROUP_M7 10 // [M3,M4,M5] Spindle turning -#define MODAL_GROUP_M8 11 // [M7,M8,M9] Coolant control +#define MODAL_GROUP_M4 10 // [M0,M1,M2,M30] Stopping +#define MODAL_GROUP_M7 11 // [M3,M4,M5] Spindle turning +#define MODAL_GROUP_M8 12 // [M7,M8,M9] Coolant control #define OTHER_INPUT_F 12 #define OTHER_INPUT_S 13 @@ -82,6 +83,9 @@ #define DISTANCE_MODE_ABSOLUTE 0 // G90 (Default: Must be zero) #define DISTANCE_MODE_INCREMENTAL 1 // G91 +// Modal Group G4: Arc IJK distance mode +#define DISTANCE_ARC_MODE_INCREMENTAL 0 // G91.1 (Default: Must be zero) + // Modal Group M4: Program flow #define PROGRAM_FLOW_RUNNING 0 // (Default: Must be zero) #define PROGRAM_FLOW_PAUSED 1 // M0, M1 diff --git a/grbl/report.c b/grbl/report.c index eae6995..9460f6a 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -68,10 +68,11 @@ void report_status_message(uint8_t status_code) case STATUS_SOFT_LIMIT_ERROR: printPgmString(PSTR("Homing not enabled")); break; case STATUS_OVERFLOW: - printPgmString(PSTR("Line overflow")); break; - // case STATUS_MAX_STEP_RATE_EXCEEDED: - // printPgmString(PSTR("Step rate > 30kHz")); break; - + printPgmString(PSTR("Line overflow")); break; + #ifdef MAX_STEP_RATE_HZ + case STATUS_MAX_STEP_RATE_EXCEEDED: + printPgmString(PSTR("Step rate > 30kHz")); break; + #endif // Common g-code parser errors. case STATUS_GCODE_MODAL_GROUP_VIOLATION: printPgmString(PSTR("Modal group violation")); break; diff --git a/grbl/report.h b/grbl/report.h index cfd0d8b..e21df42 100644 --- a/grbl/report.h +++ b/grbl/report.h @@ -33,7 +33,7 @@ #define STATUS_ALARM_LOCK 9 #define STATUS_SOFT_LIMIT_ERROR 10 #define STATUS_OVERFLOW 11 -// #define STATUS_MAX_STEP_RATE_EXCEEDED 12 +#define STATUS_MAX_STEP_RATE_EXCEEDED 12 #define STATUS_GCODE_UNSUPPORTED_COMMAND 20 #define STATUS_GCODE_MODAL_GROUP_VIOLATION 21 @@ -54,12 +54,12 @@ #define STATUS_GCODE_UNUSED_WORDS 36 #define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37 -// Define Grbl alarm codes. Less than zero to distinguish alarm error from status error. -#define ALARM_HARD_LIMIT_ERROR -1 -#define ALARM_SOFT_LIMIT_ERROR -2 -#define ALARM_ABORT_CYCLE -3 -#define ALARM_PROBE_FAIL -4 -#define ALARM_HOMING_FAIL -5 +// Define Grbl alarm codes. +#define ALARM_HARD_LIMIT_ERROR 1 +#define ALARM_SOFT_LIMIT_ERROR 2 +#define ALARM_ABORT_CYCLE 3 +#define ALARM_PROBE_FAIL 4 +#define ALARM_HOMING_FAIL 5 // Define Grbl feedback message codes. #define MESSAGE_CRITICAL_EVENT 1 diff --git a/grbl/settings.c b/grbl/settings.c index 956cb02..87535d5 100644 --- a/grbl/settings.c +++ b/grbl/settings.c @@ -189,11 +189,15 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { // Valid axis setting found. switch (set_idx) { case 0: - // if (value*settings.max_rate[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } + #ifdef MAX_STEP_RATE_HZ + if (value*settings.max_rate[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } + #endif settings.steps_per_mm[parameter] = value; break; case 1: - // if (value*settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } + #ifdef MAX_STEP_RATE_HZ + if (value*settings.steps_per_mm[parameter] > (MAX_STEP_RATE_HZ*60.0)) { return(STATUS_MAX_STEP_RATE_EXCEEDED); } + #endif settings.max_rate[parameter] = value; break; case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use.