Skip to content

Commit

Permalink
Merge pull request #734 from Paciente8159/stepper-timeout
Browse files Browse the repository at this point in the history
implemented stepper timeout option $1
  • Loading branch information
Paciente8159 committed Aug 16, 2024
2 parents a8cc420 + e828bfa commit c3f7030
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 94 deletions.
11 changes: 11 additions & 0 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,17 @@ extern "C"

#define S_CURVE_ACCELERATION_LEVEL 0

/**
*
* Enables steppers to go idle after some amount of time not moving.
* This implements Grbl setting $1
* Unlike Grbl this accepts a 16bit value so a timeout up 30 seconds can be defined. A value of 0 will disable it.
* Warning: This can and will cause steppers to loose position.
*
* */

// #define ENABLE_STEPPERS_DISABLE_TIMEOUT

/**
* Forces pin pooling for all limits and control pins (with or without
* interrupts)
Expand Down
20 changes: 20 additions & 0 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,26 @@ static void cnc_io_dotasks(void)
#ifdef ENABLE_MAIN_LOOP_MODULES
EVENT_INVOKE(cnc_io_dotasks, NULL);
#endif

#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
static uint32_t stepper_timeout = 0;

if (g_settings.step_disable_timeout)
{
// is idle check the timeout
if (cnc_get_exec_state(EXEC_RUN | EXEC_HOLD) == EXEC_IDLE)
{
if (stepper_timeout < mcu_millis())
{
io_enable_steppers(~g_settings.step_enable_invert); // disables steppers after idle timeout
stepper_timeout = UINT32_MAX;
}
}
else{
stepper_timeout = mcu_millis() + g_settings.step_disable_timeout;
}
}
#endif
}

void cnc_run_startup_blocks(void)
Expand Down
4 changes: 4 additions & 0 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ static uint8_t mc_line_segment(int32_t *step_new_pos, motion_data_t *block_data)
EVENT_INVOKE(mc_line_segment, block_data);
#endif

#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
io_enable_steppers(g_settings.step_enable_invert); // re-enable steppers for motion
#endif

planner_add_line(block_data);
// dwell should only execute on the first request
block_data->dwell = 0;
Expand Down
10 changes: 7 additions & 3 deletions uCNC/src/interface/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,14 @@ void protocol_send_cnc_settings(void)
{
protocol_busy = true;
protocol_send_gcode_setting_line_flt(0, (1000000.0f / g_settings.max_step_rate));
#if EMULATE_GRBL_STARTUP > 0
// just adds this for compatibility
// this setting is not used
#if EMULATE_GRBL_STARTUP > 0 || defined(NABLE_STEPPERS_DISABLE_TIMEOUT)
// just adds this for compatibility
// this setting is not used
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
protocol_send_gcode_setting_line_int(1, g_settings.step_disable_timeout);
#else
protocol_send_gcode_setting_line_int(1, 0);
#endif
#endif
protocol_send_gcode_setting_line_int(2, g_settings.step_invert_mask);
protocol_send_gcode_setting_line_int(3, g_settings.dir_invert_mask);
Expand Down
187 changes: 96 additions & 91 deletions uCNC/src/interface/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,47 @@

// if settings struct is changed this version should change too
#define SETTINGS_VERSION \
{ \
'V', '0', '6' \
}
{ \
'V', '0', '7'}

settings_t g_settings;

#ifndef CRC_WITHOUT_LOOKUP_TABLE

const uint8_t __rom__ crc7_table[256] =
{
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77,
0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26,
0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e,
0x32, 0x3b, 0x20, 0x29, 0x16, 0x1f, 0x04, 0x0d,
0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45,
0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14,
0x63, 0x6a, 0x71, 0x78, 0x47, 0x4e, 0x55, 0x5c,
0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b,
0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13,
0x7d, 0x74, 0x6f, 0x66, 0x59, 0x50, 0x4b, 0x42,
0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a,
0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69,
0x1e, 0x17, 0x0c, 0x05, 0x3a, 0x33, 0x28, 0x21,
0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70,
0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38,
0x41, 0x48, 0x53, 0x5a, 0x65, 0x6c, 0x77, 0x7e,
0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36,
0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67,
0x10, 0x19, 0x02, 0x0b, 0x34, 0x3d, 0x26, 0x2f,
0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c,
0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04,
0x6a, 0x63, 0x78, 0x71, 0x4e, 0x47, 0x5c, 0x55,
0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d,
0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a,
0x6d, 0x64, 0x7f, 0x76, 0x49, 0x40, 0x5b, 0x52,
0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03,
0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b,
0x17, 0x1e, 0x05, 0x0c, 0x33, 0x3a, 0x21, 0x28,
0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60,
0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31,
0x46, 0x4f, 0x54, 0x5d, 0x62, 0x6b, 0x70, 0x79};
{
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77,
0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26,
0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e,
0x32, 0x3b, 0x20, 0x29, 0x16, 0x1f, 0x04, 0x0d,
0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45,
0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14,
0x63, 0x6a, 0x71, 0x78, 0x47, 0x4e, 0x55, 0x5c,
0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b,
0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13,
0x7d, 0x74, 0x6f, 0x66, 0x59, 0x50, 0x4b, 0x42,
0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a,
0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69,
0x1e, 0x17, 0x0c, 0x05, 0x3a, 0x33, 0x28, 0x21,
0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70,
0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38,
0x41, 0x48, 0x53, 0x5a, 0x65, 0x6c, 0x77, 0x7e,
0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36,
0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67,
0x10, 0x19, 0x02, 0x0b, 0x34, 0x3d, 0x26, 0x2f,
0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c,
0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04,
0x6a, 0x63, 0x78, 0x71, 0x4e, 0x47, 0x5c, 0x55,
0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d,
0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a,
0x6d, 0x64, 0x7f, 0x76, 0x49, 0x40, 0x5b, 0x52,
0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03,
0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b,
0x17, 0x1e, 0x05, 0x0c, 0x33, 0x3a, 0x21, 0x28,
0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60,
0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31,
0x46, 0x4f, 0x54, 0x5d, 0x62, 0x6b, 0x70, 0x79};

#define crc7(x, y) rom_read_byte(&crc7_table[x ^ y])
#else
Expand All @@ -87,79 +86,82 @@ static uint8_t crc7(uint8_t c, uint8_t crc)
#endif

const settings_t __rom__ default_settings =
{
.version = SETTINGS_VERSION,
.max_step_rate = F_STEP_MAX,
.step_invert_mask = DEFAULT_STEP_INV_MASK,
.dir_invert_mask = DEFAULT_DIR_INV_MASK,
.step_enable_invert = DEFAULT_STEP_ENA_INV,
.limits_invert_mask = DEFAULT_LIMIT_INV_MASK,
.probe_invert_mask = DEFAULT_PROBE_INV_MASK,
.status_report_mask = DEFAULT_STATUS_MASK,
.control_invert_mask = DEFAULT_CONTROL_INV_MASK,
.g64_angle_factor = DEFAULT_G64_FACTOR,
.arc_tolerance = DEFAULT_ARC_TOLERANCE,
.report_inches = DEFAULT_REPORT_INCHES,
{
.version = SETTINGS_VERSION,
.max_step_rate = F_STEP_MAX,
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
.step_disable_timeout = 0,
#endif
.step_invert_mask = DEFAULT_STEP_INV_MASK,
.dir_invert_mask = DEFAULT_DIR_INV_MASK,
.step_enable_invert = DEFAULT_STEP_ENA_INV,
.limits_invert_mask = DEFAULT_LIMIT_INV_MASK,
.probe_invert_mask = DEFAULT_PROBE_INV_MASK,
.status_report_mask = DEFAULT_STATUS_MASK,
.control_invert_mask = DEFAULT_CONTROL_INV_MASK,
.g64_angle_factor = DEFAULT_G64_FACTOR,
.arc_tolerance = DEFAULT_ARC_TOLERANCE,
.report_inches = DEFAULT_REPORT_INCHES,
#if S_CURVE_ACCELERATION_LEVEL == -1
.s_curve_profile = 0,
#endif
.soft_limits_enabled = DEFAULT_SOFT_LIMITS_ENABLED,
.hard_limits_enabled = DEFAULT_HARD_LIMITS_ENABLED,
.homing_enabled = DEFAULT_HOMING_ENABLED,
.debounce_ms = DEFAULT_DEBOUNCE_MS,
.homing_dir_invert_mask = DEFAULT_HOMING_DIR_INV_MASK,
.homing_fast_feed_rate = DEFAULT_HOMING_FAST,
.homing_slow_feed_rate = DEFAULT_HOMING_SLOW,
.homing_offset = DEFAULT_HOMING_OFFSET,
.spindle_max_rpm = DEFAULT_SPINDLE_MAX_RPM,
.spindle_min_rpm = DEFAULT_SPINDLE_MIN_RPM,
.laser_mode = 0,
.s_curve_profile = 0,
#endif
.soft_limits_enabled = DEFAULT_SOFT_LIMITS_ENABLED,
.hard_limits_enabled = DEFAULT_HARD_LIMITS_ENABLED,
.homing_enabled = DEFAULT_HOMING_ENABLED,
.debounce_ms = DEFAULT_DEBOUNCE_MS,
.homing_dir_invert_mask = DEFAULT_HOMING_DIR_INV_MASK,
.homing_fast_feed_rate = DEFAULT_HOMING_FAST,
.homing_slow_feed_rate = DEFAULT_HOMING_SLOW,
.homing_offset = DEFAULT_HOMING_OFFSET,
.spindle_max_rpm = DEFAULT_SPINDLE_MAX_RPM,
.spindle_min_rpm = DEFAULT_SPINDLE_MIN_RPM,
.laser_mode = 0,
#ifdef ENABLE_LASER_PPI
.laser_ppi = DEFAULT_LASER_PPI,
.laser_ppi_uswidth = DEFAULT_LASER_PPI_USWIDTH,
.laser_ppi_mixmode_ppi = 0.25,
.laser_ppi_mixmode_uswidth = 0.75,
#endif
.step_per_mm = DEFAULT_STEP_PER_MM_PER_AXIS,
.max_feed_rate = DEFAULT_MAX_FEED_PER_AXIS,
.acceleration = DEFAULT_ACCEL_PER_AXIS,
.max_distance = DEFAULT_MAX_DIST_PER_AXIS,
.laser_ppi = DEFAULT_LASER_PPI,
.laser_ppi_uswidth = DEFAULT_LASER_PPI_USWIDTH,
.laser_ppi_mixmode_ppi = 0.25,
.laser_ppi_mixmode_uswidth = 0.75,
#endif
.step_per_mm = DEFAULT_STEP_PER_MM_PER_AXIS,
.max_feed_rate = DEFAULT_MAX_FEED_PER_AXIS,
.acceleration = DEFAULT_ACCEL_PER_AXIS,
.max_distance = DEFAULT_MAX_DIST_PER_AXIS,
#if TOOL_COUNT > 0
#if TOOL_COUNT > 1
.default_tool = DEFAULT_STARTUP_TOOL,
.default_tool = DEFAULT_STARTUP_TOOL,
#endif
.tool_length_offset = DEFAULT_ARRAY(TOOL_COUNT, 0),
.tool_length_offset = DEFAULT_ARRAY(TOOL_COUNT, 0),
#endif
#if (KINEMATIC == KINEMATIC_LINEAR_DELTA)
.delta_arm_length = DEFAULT_LIN_DELTA_ARM_LENGTH,
.delta_armbase_radius = DEFAULT_LIN_DELTA_BASE_RADIUS,
.delta_arm_length = DEFAULT_LIN_DELTA_ARM_LENGTH,
.delta_armbase_radius = DEFAULT_LIN_DELTA_BASE_RADIUS,
// float delta_efector_height;
#elif (KINEMATIC == KINEMATIC_DELTA)
.delta_base_radius = DEFAULT_DELTA_BASE_RADIUS,
.delta_effector_radius = DEFAULT_DELTA_EFFECTOR_RADIUS,
.delta_bicep_length = DEFAULT_DELTA_BICEP_LENGTH,
.delta_forearm_length = DEFAULT_DELTA_FOREARM_LENGTH,
.delta_bicep_homing_angle = DEFAULT_DELTA_BICEP_HOMING_ANGLE,
.delta_base_radius = DEFAULT_DELTA_BASE_RADIUS,
.delta_effector_radius = DEFAULT_DELTA_EFFECTOR_RADIUS,
.delta_bicep_length = DEFAULT_DELTA_BICEP_LENGTH,
.delta_forearm_length = DEFAULT_DELTA_FOREARM_LENGTH,
.delta_bicep_homing_angle = DEFAULT_DELTA_BICEP_HOMING_ANGLE,
#elif (KINEMATIC == KINEMATIC_SCARA)
.scara_arm_length = DEFAULT_SCARA_ARM_LENGTH,
.scara_forearm_length = DEFAULT_SCARA_FOREARM_LENGTH,
.scara_arm_homing_angle = DEFAULT_SCARA_ARM_HOMING_ANGLE,
.scara_forearm_homing_angle = DEFAULT_SCARA_FOREARM_HOMING_ANGLE,
.scara_arm_length = DEFAULT_SCARA_ARM_LENGTH,
.scara_forearm_length = DEFAULT_SCARA_FOREARM_LENGTH,
.scara_arm_homing_angle = DEFAULT_SCARA_ARM_HOMING_ANGLE,
.scara_forearm_homing_angle = DEFAULT_SCARA_FOREARM_HOMING_ANGLE,
#endif

#ifdef ENABLE_BACKLASH_COMPENSATION
.backlash_steps = DEFAULT_ARRAY(AXIS_TO_STEPPERS, 0),
.backlash_steps = DEFAULT_ARRAY(AXIS_TO_STEPPERS, 0),
#endif
#ifdef ENABLE_SKEW_COMPENSATION
.skew_xy_factor = 0,
.skew_xy_factor = 0,
#ifndef SKEW_COMPENSATION_XY_ONLY
.skew_xz_factor = 0,
.skew_yz_factor = 0,
.skew_xz_factor = 0,
.skew_yz_factor = 0,
#endif
#endif
#if ENCODERS > 0
.encoders_pulse_invert_mask = 0,
.encoders_dir_invert_mask = 0,
.encoders_pulse_invert_mask = 0,
.encoders_dir_invert_mask = 0,
#endif
};

Expand Down Expand Up @@ -419,10 +421,13 @@ uint8_t settings_change(setting_offset_t id, float value)
}
g_settings.max_step_rate = value;
break;
#if EMULATE_GRBL_STARTUP > 0
#if EMULATE_GRBL_STARTUP > 0 || defined(ENABLE_STEPPERS_DISABLE_TIMEOUT)
// just adds this for compatibility
// this setting is not used
case 1:
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
g_settings.step_disable_timeout = value16;
#endif
break;
#endif
case 2:
Expand Down
3 changes: 3 additions & 0 deletions uCNC/src/interface/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ extern "C"
uint8_t version[3];
float max_step_rate;
// step delay not used
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
uint16_t step_disable_timeout;
#endif
uint8_t step_invert_mask;
uint8_t dir_invert_mask;
uint8_t step_enable_invert;
Expand Down
1 change: 1 addition & 0 deletions uCNC/src/modules/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern "C"
#define STR_LIMITS_INV "Limits inv:"
#define STR_PROBE_INV "Probe inv:"
#define STR_CONTROL_INV "Control inv:"
#define STR_STEPPER_TIMEOUT "Stepper disable timeout:"
#define STR_SOFTLIMITS "Soft-limits:"
#define STR_HARDLIMITS "Hard-limits:"
#define STR_ENABLE_HOMING "Enable homing:"
Expand Down
3 changes: 3 additions & 0 deletions uCNC/src/modules/system_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ DECL_MODULE(system_menu)
DECL_MENU_VAR(6, s8, STR_ENC_P_INV, &g_settings.encoders_pulse_invert_mask, VAR_TYPE_UINT8);
DECL_MENU_VAR(6, s9, STR_ENC_D_INV, &g_settings.encoders_dir_invert_mask, VAR_TYPE_UINT8);
#endif
#ifdef ENABLE_STEPPERS_DISABLE_TIMEOUT
DECL_MENU_VAR(6, s10, STR_STEPPER_TIMEOUT, &g_settings.step_disable_timeout, VAR_TYPE_UINT16);
#endif

// append homing settings menu
DECL_MENU(3, SYSTEM_MENU_ID_SETTINGS, STR_HOMING);
Expand Down

0 comments on commit c3f7030

Please sign in to comment.