Skip to content

Commit

Permalink
Merge pull request #791 from Paciente8159/790-bug-behaviour-of-g10-l2…
Browse files Browse the repository at this point in the history
…-and-l20-in-incremental-mode

fixed G10 and G92 offsets
  • Loading branch information
Paciente8159 authored Nov 27, 2024
2 parents 721ded8 + fc0d9d3 commit 04ad6f7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 91 deletions.
167 changes: 77 additions & 90 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1414,12 +1416,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
Expand Down Expand Up @@ -1520,6 +1526,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;
Expand All @@ -1540,9 +1547,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))
{
Expand Down Expand Up @@ -1631,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__
Expand All @@ -1645,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));
Expand All @@ -1692,31 +1707,47 @@ 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] - parser_parameters.g92_offset[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)))
{
coords[AXIS_TOOL] += parser_parameters.tool_length_offset;
}
}
#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);
Expand All @@ -1726,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.g92_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
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/interface/grbl_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04ad6f7

Please sign in to comment.