From ea2f6d672cf76120923f8ed5ea8219c45d694c6a Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Sun, 21 Jan 2024 09:21:18 +0000 Subject: [PATCH 1/2] added motion control incremental jog command --- uCNC/src/core/motion_control.c | 34 ++++++++++++++++++++++++++++++++-- uCNC/src/core/motion_control.h | 2 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index f579fed73..17cf7d922 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -910,7 +910,7 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) io_enable_probe(); mc_line(target, block_data); - //similar to itp_sync + // similar to itp_sync do { if (!cnc_dotasks()) @@ -927,7 +927,8 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) } while (!itp_is_empty() || !planner_buffer_is_empty()); // wait for a stop - while (cnc_dotasks() && cnc_get_exec_state(EXEC_RUN)); + while (cnc_dotasks() && cnc_get_exec_state(EXEC_RUN)) + ; // disables the probe io_disable_probe(); itp_clear(); @@ -967,6 +968,35 @@ void mc_sync_position(void) parser_sync_position(); } +uint8_t mc_incremental_jog(float *target_offset, motion_data_t *block_data) +{ + float new_target[AXIS_COUNT]; + + if (cnc_get_exec_state(~(EXEC_RUN | EXEC_HOLD)) || cnc_has_alarm()) // if any other than idle, run or hold discards the command + { + return STATUS_SYSTEM_GC_LOCK; + } + + cnc_set_exec_state(EXEC_JOG); + + // gets the previous machine position (transformed to calculate the direction vector and traveled distance) + memcpy(new_target, mc_last_target, sizeof(mc_last_target)); + for (uint8_t i = AXIS_COUNT; i != 0;) + { + i--; + new_target[i] += target_offset[i]; + } + + uint8_t error = mc_line(new_target, block_data); + + if (error == STATUS_OK) + { + parser_sync_position(); + } + + return error; +} + #ifdef ENABLE_G39_H_MAPPING void mc_print_hmap(void) diff --git a/uCNC/src/core/motion_control.h b/uCNC/src/core/motion_control.h index 4a88fad9d..825f9fefd 100644 --- a/uCNC/src/core/motion_control.h +++ b/uCNC/src/core/motion_control.h @@ -115,6 +115,8 @@ extern "C" void mc_get_position(float *target); void mc_sync_position(void); + uint8_t mc_incremental_jog(float *target_offset, motion_data_t *block_data); + #ifdef ENABLE_G39_H_MAPPING uint8_t mc_build_hmap(float *target, float *offset, float retract_h, motion_data_t *block_data); #endif From e6fec3fd80422cc13270932c1952d10560ce7eac Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Mon, 22 Jan 2024 16:14:39 +0000 Subject: [PATCH 2/2] fixed mc jog command conditional eval --- uCNC/src/core/motion_control.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index 17cf7d922..ced3e652e 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -971,10 +971,11 @@ void mc_sync_position(void) uint8_t mc_incremental_jog(float *target_offset, motion_data_t *block_data) { float new_target[AXIS_COUNT]; + uint8_t state = cnc_get_exec_state(EXEC_ALLACTIVE); - if (cnc_get_exec_state(~(EXEC_RUN | EXEC_HOLD)) || cnc_has_alarm()) // if any other than idle, run or hold discards the command + if ((state & ~EXEC_JOG) || cnc_has_alarm()) // if any other than idle or jog discards the command { - return STATUS_SYSTEM_GC_LOCK; + return STATUS_IDLE_ERROR; } cnc_set_exec_state(EXEC_JOG);