Skip to content

Commit

Permalink
Merge pull request #631 from Paciente8159/fix-rt-spindle-toggle
Browse files Browse the repository at this point in the history
fixed spindle toogle realtime command
  • Loading branch information
Paciente8159 committed Feb 19, 2024
2 parents 901f32b + 2ef6d34 commit 2ebef83
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
19 changes: 8 additions & 11 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,10 @@ void cnc_clear_exec_state(uint8_t statemask)
// if releasing from a HOLD state with and active delay in exec
if (CHECKFLAG(statemask, EXEC_HOLD) && cnc_get_exec_state(EXEC_HOLD))
{
CLEARFLAG(cnc_state.exec_state, EXEC_HOLD);
// remove the flag to prevent ITP to restart
// CLEARFLAG(cnc_state.exec_state, EXEC_HOLD);
#if TOOL_COUNT > 0
planner_spindle_ovr_reset();
// updated the coolant pins
tool_set_coolant(planner_get_coolant());
#if (DELAY_ON_RESUME_COOLANT > 0)
Expand All @@ -577,6 +579,7 @@ void cnc_clear_exec_state(uint8_t statemask)
#if (DELAY_ON_RESUME_SPINDLE > 0)
if (!g_settings.laser_mode)
{
protocol_send_feedback(MSG_FEEDBACK_10);
if (!planner_buffer_is_empty())
{
cnc_delay_ms(DELAY_ON_RESUME_SPINDLE * 1000);
Expand Down Expand Up @@ -819,10 +822,8 @@ void cnc_exec_rt_commands(void)
if (cnc_get_exec_state(EXEC_HOLD | EXEC_DOOR | EXEC_RUN) == EXEC_HOLD) // only available if a TRUE hold is active
{
// toogle state
if (tool_get_speed())
{
update_tools = false;
tool_set_speed(0);
if(planner_spindle_ovr_toggle()){
protocol_send_feedback(MSG_FEEDBACK_10);
}
}
break;
Expand Down Expand Up @@ -854,17 +855,13 @@ void cnc_exec_rt_commands(void)
#endif
}
#endif

if (update_tools)
{
itp_update();
if (planner_buffer_is_empty())
{
motion_data_t block = {0};
#if TOOL_COUNT > 0
block.motion_flags.bit.coolant = planner_get_previous_coolant();
block.spindle = planner_get_previous_spindle_speed();
#endif
mc_update_tools(&block);
mc_update_tools(NULL);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ uint8_t mc_update_tools(motion_data_t *block_data)
return STATUS_CRITICAL_FAIL;
}
// synchronizes the tools
planner_sync_tools(block_data);
if (block_data)
{
planner_sync_tools(block_data);
}
itp_sync_spindle();
}
#endif
Expand All @@ -734,7 +737,7 @@ uint8_t mc_home_axis(uint8_t axis_mask, uint8_t axis_limit)
motion_data_t block_data = {0};
uint8_t limits_flags;
uint8_t restore_step_mode __attribute__((__cleanup__(mc_restore_step_mode))) = itp_set_step_mode(ITP_STEP_MODE_REALTIME);

#ifdef ENABLE_MOTION_CONTROL_MODULES
homing_status_t homing_status __attribute__((__cleanup__(mc_home_axis_finalize))) = {axis_mask, axis_limit, STATUS_OK};
#endif
Expand Down
29 changes: 16 additions & 13 deletions uCNC/src/core/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ void planner_init(void)
planner_rapid_feed_ovr(100);
#if TOOL_COUNT > 0
planner_spindle_ovr(100);
planner_spindle_ovr_reset();
planner_coolant_ovr_reset();
#endif
}
Expand Down Expand Up @@ -408,9 +409,10 @@ float planner_get_block_top_speed(float exit_speed_sqr)
}

#if TOOL_COUNT > 0
static uint8_t spindle_override;
int16_t planner_get_spindle_speed(float scale)
{
if (g_planner_state.state_flags.bit.spindle_running)
if (g_planner_state.state_flags.bit.spindle_running ^ spindle_override)
{
float scaled_spindle = (float)g_planner_state.spindle_speed;
bool neg = (g_planner_state.state_flags.bit.spindle_running == 2);
Expand All @@ -432,16 +434,6 @@ int16_t planner_get_spindle_speed(float scale)

return 0;
}

float planner_get_previous_spindle_speed(void)
{
return (float)g_planner_state.spindle_speed;
}

uint8_t planner_get_previous_coolant(void)
{
return g_planner_state.state_flags.bit.coolant;
}
#endif

static void planner_recalculate(void)
Expand Down Expand Up @@ -518,7 +510,7 @@ void planner_sync_tools(motion_data_t *block_data)
void planner_feed_ovr(uint8_t value)
{
value = CLAMP(FEED_OVR_MIN, value, FEED_OVR_MAX);

if (value != g_planner_state.feed_override)
{
g_planner_state.feed_override = value;
Expand Down Expand Up @@ -551,6 +543,17 @@ void planner_spindle_ovr(uint8_t value)
}
}

uint8_t planner_spindle_ovr_toggle(void)
{
spindle_override ^= g_planner_state.state_flags.bit.spindle_running;
return (spindle_override ^ g_planner_state.state_flags.bit.spindle_running);
}

void planner_spindle_ovr_reset(void)
{
spindle_override = 0;
}

static uint8_t coolant_override;

uint8_t planner_get_coolant(void)
Expand All @@ -566,7 +569,7 @@ uint8_t planner_coolant_ovr_toggle(uint8_t value)

void planner_coolant_ovr_reset(void)
{
g_planner_state.state_flags.bit.coolant = 0;
// g_planner_state.state_flags.bit.coolant = 0;
coolant_override = 0;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/core/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ extern "C"
float planner_get_block_top_speed(float exit_speed_sqr);
#if TOOL_COUNT > 0
int16_t planner_get_spindle_speed(float scale);
float planner_get_previous_spindle_speed(void);
uint8_t planner_get_coolant(void);
uint8_t planner_get_previous_coolant(void);
#endif
void planner_discard_block(void);
void planner_add_line(motion_data_t *block_data);
Expand All @@ -102,6 +100,8 @@ extern "C"
void planner_rapid_feed_ovr(uint8_t value);
#if TOOL_COUNT > 0
void planner_spindle_ovr(uint8_t value);
uint8_t planner_spindle_ovr_toggle(void);
void planner_spindle_ovr_reset(void);
uint8_t planner_coolant_ovr_toggle(uint8_t value);
void planner_coolant_ovr_reset(void);
#endif
Expand Down

0 comments on commit 2ebef83

Please sign in to comment.