From f0afb7b48dbb97272094c8b8b5e8bdbebaafa3ef Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Mon, 25 Nov 2024 15:09:01 +0000 Subject: [PATCH 1/2] fixed G10 and G92 offsets - fixed G10 offset when G91 is active and ignoring G92 coordinates - fixed G92 calculations relative to current coordinate system - making non modal commands sync (except G53) to prevent coordinate WCO to be applied ahead of time --- uCNC/src/core/parser.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/uCNC/src/core/parser.c b/uCNC/src/core/parser.c index f32794bf..18c8590e 100644 --- a/uCNC/src/core/parser.c +++ b/uCNC/src/core/parser.c @@ -1414,12 +1414,16 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo // 9. overrides block_data.motion_flags.bit.feed_override = new_state->groups.feed_speed_override ? 1 : 0; - // 10. dwell - if (new_state->groups.nonmodal == G4) + // 10. dwell (or if any other nonmodal command except G53 requires a sync motion) + if (new_state->groups.nonmodal != 0 && new_state->groups.nonmodal != G53) { - // calc dwell in milliseconds - block_data.dwell = MAX(block_data.dwell, (uint16_t)lroundf(MIN(words->p * 1000.0f, 65535))); - new_state->groups.nonmodal = 0; + itp_sync(); + if (new_state->groups.nonmodal == G4) + { + // calc dwell in milliseconds + block_data.dwell = MAX(block_data.dwell, (uint16_t)lroundf(MIN(words->p * 1000.0f, 65535))); + new_state->groups.nonmodal = 0; + } } // after all spindle, overrides, coolant and dwells are set @@ -1520,6 +1524,7 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo #ifndef DISABLE_COORD_SYS_SUPPORT if (CHECKFLAG(cmd->groups, GCODE_GROUP_COORDSYS)) { + itp_sync(); parser_parameters.coord_system_index = new_state->groups.coord_system; parser_coordinate_system_load(parser_parameters.coord_system_index, parser_parameters.coord_system_offset); parser_wco_counter = 0; @@ -1540,9 +1545,13 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo // 17. set distance mode (G90, G91) memcpy(target, parser_last_pos, sizeof(parser_last_pos)); + // absolute distances if distance mode is G90 + bool abspos = (new_state->groups.distance_mode == G90); + // or if any nonmodal command is active (execept G4 that auto clears itself) + abspos |= (new_state->groups.nonmodal != 0); + // or if any nonmodal command is active (execept G4 that auto clears itself) // for all not explicitly declared target retain their position or add offset - bool abspos = (new_state->groups.distance_mode == G90) | (new_state->groups.nonmodal == G53); #ifdef AXIS_X if (CHECKFLAG(cmd->words, GCODE_WORD_X)) { @@ -1700,7 +1709,7 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo { if (words->l == 20) { - coords[i] = -(target[i] - parser_last_pos[i] - parser_parameters.g92_offset[i]); + coords[i] = -(target[i] - parser_last_pos[i]); } else { @@ -1767,7 +1776,7 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo for (uint8_t i = AXIS_COUNT; i != 0;) { i--; - parser_parameters.g92_offset[i] = -(target[i] - parser_last_pos[i] - parser_parameters.g92_offset[i]); + parser_parameters.g92_offset[i] = -(target[i] - parser_last_pos[i] + parser_parameters.coord_system_offset[i]); } memcpy(g92permanentoffset, parser_parameters.g92_offset, sizeof(g92permanentoffset)); #ifdef G92_STORE_NONVOLATILE From fc0d9d3176f0e9538a62cc03de8a70abc2add520 Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Tue, 26 Nov 2024 11:21:28 +0000 Subject: [PATCH 2/2] unified G10 and G92 path - unified G10 and G92 processing path - fixed G92 offset macro - fixed P validation with homing disabled --- uCNC/src/core/parser.c | 146 ++++++++++++----------------- uCNC/src/interface/grbl_settings.h | 2 +- 2 files changed, 63 insertions(+), 85 deletions(-) diff --git a/uCNC/src/core/parser.c b/uCNC/src/core/parser.c index 18c8590e..5616660f 100644 --- a/uCNC/src/core/parser.c +++ b/uCNC/src/core/parser.c @@ -1000,8 +1000,10 @@ static uint8_t parser_validate_command(parser_state_t *new_state, parser_words_t { return STATUS_GCODE_UNSUPPORTED_COMMAND; } - // P is not between 1 and N of coord systems +// P is not between 1 and N of coord systems +#ifndef DISABLE_HOME_SUPPORT if (words->p != 28 && words->p != 30) +#endif { if (words->p < 0 || words->p > COORD_SYS_COUNT) { @@ -1640,6 +1642,9 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo } #endif break; + case G92: + index = G92OFFSET; + break; case G92_1: // G92.1 memset(g92permanentoffset, 0, sizeof(g92permanentoffset)); __FALL_THROUGH__ @@ -1654,45 +1659,46 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo parser_wco_counter = 0; new_state->groups.nonmodal = 0; // this command is compatible with motion commands break; + case G53: + index = 254; + break; } // check from were to read the previous values for the target array - if (index == 255) + float coords[AXIS_COUNT]; + bool relative_target = true; + float *relative_offset = NULL; + switch (index) { - switch (new_state->groups.nonmodal) + case 254: // G53 (passthrough) + break; + case 255: // No nonmodal + if ((new_state->groups.distance_mode == G90)) { - case G53: - // G28 and G30 make the planed motion (absolute or relative) - // case G28: - // case G30: - break; - default: - if ((new_state->groups.distance_mode == G90)) + for (uint8_t i = AXIS_COUNT; i != 0;) { - for (uint8_t i = AXIS_COUNT; i != 0;) + i--; + if (CHECKFLAG(cmd->words, (1 << i))) { - i--; - if (CHECKFLAG(cmd->words, (1 << i))) - { - target[i] += parser_parameters.coord_system_offset[i] + parser_parameters.g92_offset[i]; - } + target[i] += parser_parameters.coord_system_offset[i] + parser_parameters.g92_offset[i]; } + } #ifdef AXIS_TOOL - if (CHECKFLAG(cmd->words, (1 << AXIS_TOOL))) - { - target[AXIS_TOOL] += parser_parameters.tool_length_offset; - } -#endif + if (CHECKFLAG(cmd->words, (1 << AXIS_TOOL))) + { + target[AXIS_TOOL] += parser_parameters.tool_length_offset; } - break; +#endif } - } - -// stores G10 L2 command in the right address + break; + case G92OFFSET: + relative_offset = parser_parameters.coord_system_offset; + memcpy(coords, parser_parameters.g92_offset, sizeof(coords)); + break; #ifndef DISABLE_G10_SUPPORT - if (index <= G30HOME) - { - float coords[AXIS_COUNT]; + default: + relative_offset = parser_parameters.g92_offset; + relative_target = (words->l == 20); if (index == parser_parameters.coord_system_index) { memcpy(coords, parser_parameters.coord_system_offset, sizeof(coords)); @@ -1701,24 +1707,22 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo { parser_coordinate_system_load(index, coords); } + break; +#endif + } + if (index <= G92OFFSET) + { for (uint8_t i = AXIS_COUNT; i != 0;) { i--; if (CHECKFLAG(cmd->words, (1 << i))) { - if (words->l == 20) - { - coords[i] = -(target[i] - parser_last_pos[i]); - } - else - { - coords[i] = target[i]; - } + coords[i] = (relative_target) ? -(target[i] - parser_last_pos[i] + relative_offset[i]) : target[i]; } } #ifdef AXIS_TOOL - if (words->l == 20) + if (relative_target) { if (CHECKFLAG(cmd->words, (1 << AXIS_TOOL))) { @@ -1726,6 +1730,24 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo } } #endif + } + + // stores G10 or G92 command in the right address + switch (index) + { + case 254: + case 255: + break; + case G92OFFSET: + memcpy(parser_parameters.g92_offset, coords, sizeof(parser_parameters.g92_offset)); + memcpy(g92permanentoffset, parser_parameters.g92_offset, sizeof(g92permanentoffset)); +#ifdef G92_STORE_NONVOLATILE + settings_save(G92ADDRESS, (uint8_t *)&g92permanentoffset, PARSER_PARAM_SIZE); +#endif + parser_wco_counter = 0; + break; +#ifndef DISABLE_G10_SUPPORT + default: settings_save(SETTINGS_PARSER_PARAMETERS_ADDRESS_OFFSET + (index * PARSER_PARAM_ADDR_OFFSET), (uint8_t *)coords, PARSER_PARAM_SIZE); #ifndef DISABLE_COORDINATES_SYSTEM_RAM memcpy(&coordinate_systems[index], coords, PARSER_PARAM_SIZE); @@ -1735,60 +1757,16 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo memcpy(parser_parameters.coord_system_offset, coords, PARSER_PARAM_SIZE); } parser_wco_counter = 0; - } + break; #endif + } + // laser disabled in nonmodal moves if (g_settings.laser_mode && new_state->groups.nonmodal) { block_data.spindle = 0; } - switch (new_state->groups.nonmodal) - { -#ifndef DISABLE_HOME_SUPPORT - case G28: // G28 - case G30: // G30 - block_data.feed = FLT_MAX; - if (CHECKFLAG(cmd->words, GCODE_ALL_AXIS)) - { - error = mc_line(target, &block_data); - update_tools = false; - if (error) - { - return error; - } - } - - if (new_state->groups.nonmodal == G28) - { - parser_coordinate_system_load(G28HOME, target); - } - else - { - parser_coordinate_system_load(G30HOME, target); - } - error = mc_line((float *)&target, &block_data); - // saves position - memcpy(parser_last_pos, target, sizeof(parser_last_pos)); - break; -#endif - case G92: // G92 - for (uint8_t i = AXIS_COUNT; i != 0;) - { - i--; - parser_parameters.g92_offset[i] = -(target[i] - parser_last_pos[i] + parser_parameters.coord_system_offset[i]); - } - memcpy(g92permanentoffset, parser_parameters.g92_offset, sizeof(g92permanentoffset)); -#ifdef G92_STORE_NONVOLATILE - settings_save(G92ADDRESS, (uint8_t *)&g92permanentoffset, PARSER_PARAM_SIZE); -#endif - parser_wco_counter = 0; - break; - case G53: - new_state->groups.nonmodal = 0; // this command is compatible with motion commands - break; - } - // 20. perform motion (G0 to G3, G80 to G89), as modified (possibly) by G53. // G80 does no motion // G81 to G89 is executed in a separate function and uses G53,G0,G1 and G4 has building blocks diff --git a/uCNC/src/interface/grbl_settings.h b/uCNC/src/interface/grbl_settings.h index f6cb8b0f..7e31094a 100644 --- a/uCNC/src/interface/grbl_settings.h +++ b/uCNC/src/interface/grbl_settings.h @@ -138,7 +138,7 @@ extern "C" #define PARSER_PARAM_ADDR_OFFSET (PARSER_PARAM_SIZE + 1) // parser parameters array size + 1 crc byte #define G28HOME (COORD_SYS_COUNT) // G28 index #define G30HOME (COORD_SYS_COUNT + 1) // G30 index -#define G92OFFSET (COORD_SYS_COUNT + 2) // G92 index +#define G92OFFSET (COORD_SYS_COUNT + ADDITIONAL_COORDINATES) // G92 index #define PARSER_CORDSYS_ADDRESS (SETTINGS_PARSER_PARAMETERS_ADDRESS_OFFSET) // 1st coordinate system offset eeprom address (G54) #define G28ADDRESS (SETTINGS_PARSER_PARAMETERS_ADDRESS_OFFSET + (PARSER_PARAM_ADDR_OFFSET * G28HOME)) // G28 coordinate offset eeprom address #define G30ADDRESS (SETTINGS_PARSER_PARAMETERS_ADDRESS_OFFSET + (PARSER_PARAM_ADDR_OFFSET * G30HOME)) // G28 coordinate offset eeprom address