Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redesigned M2/M30 to match LinuxCNC #786

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ uint8_t cnc_unlock(bool force)

io_set_steps(g_settings.step_invert_mask);
io_enable_steppers(g_settings.step_enable_invert);
parser_reset(true); // reset stop group only
parser_reset(false); // reset parser

// hard reset
// if homing not enabled run startup blocks
Expand Down
51 changes: 34 additions & 17 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void parser_init(void)
#endif
memset(parser_last_pos, 0, sizeof(parser_last_pos));
parser_parameters_load();
parser_reset(false);
parser_reset(true);
}

uint8_t parser_read_command(void)
Expand Down Expand Up @@ -1296,10 +1296,12 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo
// stoping from previous command M2 or M30 command
if (new_state->groups.stopping && !CHECKFLAG(cmd->groups, GCODE_GROUP_STOPPING))
{
#ifndef DISABLE_ENDPROGRAM_LOCK
if (new_state->groups.stopping == 3 || new_state->groups.stopping == 4)
{
return STATUS_PROGRAM_ENDED;
}
#endif

new_state->groups.stopping = 0;
}
Expand Down Expand Up @@ -1973,16 +1975,18 @@ static uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *wo
break;
case 3: // M2
case 4: // M30 (pallet change has no effect)
#ifndef DISABLE_ENDPROGRAM_LOCK
hold = true;
resetparser = true;
#endif
break;
}

if (hold && !mc_get_checkmode())
{
#ifndef DISABLE_ENDPROGRAM_LOCK
mc_pause();
#else
itp_sync();
#endif
if (resetparser)
{
cnc_stop();
Expand Down Expand Up @@ -2067,6 +2071,12 @@ static uint8_t parser_gcode_command(bool is_jogging)
#endif
// if everything went ok updates the parser modal groups and position
memcpy(&parser_state, &next_state, sizeof(parser_state_t));
#ifdef DISABLE_ENDPROGRAM_LOCK
if (next_state.groups.stopping == 3 || next_state.groups.stopping == 4)
{
parser_reset(false);
}
#endif
}

return result;
Expand Down Expand Up @@ -2775,13 +2785,11 @@ void parser_discard_command(void)
#endif
}

void parser_reset(bool stopgroup_only)
void parser_reset(bool fullreset)
{
parser_state.groups.stopping = 0; // resets all stopping commands (M0,M1,M2,M30,M60)
if (stopgroup_only)
{
return;
}
// modified based on https://linuxcnc.org/docs/html/gcode/m-code.html#mcode:m2-m30

parser_state.groups.stopping = 0; // resets all stopping commands (M0,M1,M2,M30,M60)
parser_state.groups.coord_system = G54; // G54
parser_state.groups.plane = G17; // G17
parser_state.groups.feed_speed_override = M48; // M48
Expand All @@ -2792,16 +2800,10 @@ void parser_reset(bool stopgroup_only)
#if TOOL_COUNT > 0
parser_state.groups.coolant = M9; // M9
parser_state.groups.spindle_turning = M5; // M5
parser_state.groups.tool_change = 1;
#if TOOL_COUNT > 1
parser_state.tool_index = g_settings.default_tool;
#endif
parser_state.groups.path_mode = G61;
#endif
parser_state.groups.motion = G1; // G1
parser_state.groups.units = G21; // G21
memset(parser_parameters.g92_offset, 0, sizeof(parser_parameters.g92_offset)); // G92.2
parser_parameters.tool_length_offset = 0;
parser_state.groups.motion = G1; // G1
parser_state.groups.units = G21; // G21
parser_wco_counter = 0;
#ifdef ENABLE_G39_H_MAPPING
parser_state.groups.height_map_active = 0;
Expand All @@ -2810,6 +2812,21 @@ void parser_reset(bool stopgroup_only)
#ifdef ENABLE_PARSER_MODULES
EVENT_INVOKE(parser_reset, &parser_state);
#endif

if (!fullreset)
{
return;
}

// extra reset stuff out of the M2/M30 scope
memset(parser_parameters.g92_offset, 0, sizeof(parser_parameters.g92_offset)); // G92.2
parser_parameters.tool_length_offset = 0;
#if TOOL_COUNT > 0
parser_state.groups.tool_change = 1;
#endif
#if TOOL_COUNT > 1
parser_state.tool_index = g_settings.default_tool;
#endif
}

/**
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ extern "C"
void parser_parameters_reset(void);
void parser_parameters_save(void);
void parser_sync_position(void);
void parser_reset(bool stopgroup_only);
void parser_reset(bool fullreset);
void parser_machine_to_work(float *axis);
uint8_t parser_get_float(float *value);
void parser_discard_command(void);
Expand Down
Loading