From d571f99ef00b0b5e2a1412af2f8e17a2c04e6e32 Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Mon, 15 Jan 2024 16:04:50 +0000 Subject: [PATCH 1/4] modified probing for better precision - modified probing for better precision with option to update/check in realtime - modified probing stopping to controlled stop --- uCNC/src/core/interpolator.c | 4 ++++ uCNC/src/core/io_control.c | 11 ++++++++--- uCNC/src/core/motion_control.c | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/uCNC/src/core/interpolator.c b/uCNC/src/core/interpolator.c index 321ae259..09d0758f 100644 --- a/uCNC/src/core/interpolator.c +++ b/uCNC/src/core/interpolator.c @@ -897,6 +897,10 @@ MCU_CALLBACK void mcu_step_cb(void) return; } +#ifdef ENABLE_RT_PROBE_CHECKING + mcu_probe_changed_cb(); +#endif + uint8_t new_stepbits = stepbits; uint8_t dirs = 0; diff --git a/uCNC/src/core/io_control.c b/uCNC/src/core/io_control.c index 85b66c2a..c5540f95 100644 --- a/uCNC/src/core/io_control.c +++ b/uCNC/src/core/io_control.c @@ -208,10 +208,15 @@ MCU_IO_CALLBACK void mcu_probe_changed_cb(void) io_last_probe = probe; - // stops the machine - itp_stop(); // stores rt position - parser_sync_probe(); + __ATOMIC__ + { + parser_sync_probe(); + } + + // instead of stopping the machine does a controlled stop (hold) + // itp_stop(); + cnc_set_exec_state(EXEC_HOLD); #endif } diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index 65765275..b8a2ef0b 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -912,17 +912,22 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) // enable the probe io_enable_probe(); - mcu_probe_changed_cb(); mc_line(target, block_data); do { if (io_get_probe() ^ (flags & 0x01)) { +#ifndef ENABLE_RT_PROBE_CHECKING mcu_probe_changed_cb(); +#endif break; } - } while (cnc_dotasks() && cnc_get_exec_state(EXEC_RUN)); + } while (cnc_dotasks()); + + // waits for the motion to stop(); + itp_sync(); + cnc_clear_exec_state(EXEC_HOLD); // disables the probe io_disable_probe(); From 6aa438d1f95e54866dbeb10ca44881c90af73542 Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Tue, 16 Jan 2024 22:51:55 +0000 Subject: [PATCH 2/4] prevent HOLD command to interrupt probing - prevent HOLD command to interrupt probing (midway) - moved HOLD cleaning to prevent HOLD unlock --- uCNC/src/core/motion_control.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index b8a2ef0b..a7cc1f19 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -914,8 +914,13 @@ 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 do { + if (cnc_dotasks() != STATUS_OK) + { + break; + } if (io_get_probe() ^ (flags & 0x01)) { #ifndef ENABLE_RT_PROBE_CHECKING @@ -923,21 +928,18 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) #endif break; } - } while (cnc_dotasks()); - - // waits for the motion to stop(); - itp_sync(); - cnc_clear_exec_state(EXEC_HOLD); + } while (!itp_is_empty() || !planner_buffer_is_empty()); // disables the probe io_disable_probe(); - // clears HALT state if possible cnc_unlock(true); - itp_clear(); planner_clear(); + // clears hold + cnc_clear_exec_state(EXEC_HOLD); parser_update_probe_pos(); + // sync the position of the motion control mc_sync_position(); // HALT could not be cleared. Something is wrong From 2d0669f6221f7baaee888ae230a73d00dc6ca988 Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Wed, 17 Jan 2024 12:00:08 +0000 Subject: [PATCH 3/4] fixed probing loop - fixed probing loop condition on system failure - remove cnc unlocking that masks other alarm conditions (like soft reset). Since the stop is now controlled via hold this is no longer necessary. --- uCNC/src/core/motion_control.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index a7cc1f19..3daf91a1 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -917,7 +917,7 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) //similar to itp_sync do { - if (cnc_dotasks() != STATUS_OK) + if (!cnc_dotasks()) { break; } @@ -932,8 +932,6 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) // disables the probe io_disable_probe(); - // clears HALT state if possible - cnc_unlock(true); itp_clear(); planner_clear(); // clears hold From 47278ba8f215d84eba580a8bd02933c33ebc3af0 Mon Sep 17 00:00:00 2001 From: Paciente8159 Date: Wed, 17 Jan 2024 12:43:35 +0000 Subject: [PATCH 4/4] updated conditions for probe position update - updated conditions for probe position update - probe position updated also on failure - other probing actions like G39 and Plasma don't affect last probing result (independent) --- uCNC/src/cnc_hal_config_helper.h | 6 ++++++ uCNC/src/core/motion_control.c | 11 +++-------- uCNC/src/core/parser.c | 8 ++++++++ uCNC/src/core/parser.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/uCNC/src/cnc_hal_config_helper.h b/uCNC/src/cnc_hal_config_helper.h index 714420bb..8e6e6275 100644 --- a/uCNC/src/cnc_hal_config_helper.h +++ b/uCNC/src/cnc_hal_config_helper.h @@ -195,6 +195,12 @@ extern "C" #define PROBE_PULLUP #endif +#ifdef ENABLE_RT_PROBE_CHECKING +#ifdef PROBE_ISR +#undef PROBE_ISR +#endif +#endif + #ifdef ESTOP_PULLUP_ENABLE #define ESTOP_PULLUP #endif diff --git a/uCNC/src/core/motion_control.c b/uCNC/src/core/motion_control.c index 3daf91a1..f599ad51 100644 --- a/uCNC/src/core/motion_control.c +++ b/uCNC/src/core/motion_control.c @@ -930,21 +930,17 @@ 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)); // disables the probe io_disable_probe(); itp_clear(); planner_clear(); // clears hold cnc_clear_exec_state(EXEC_HOLD); - parser_update_probe_pos(); // sync the position of the motion control mc_sync_position(); - // HALT could not be cleared. Something is wrong - if (cnc_get_exec_state(EXEC_UNHOMED)) - { - return STATUS_CRITICAL_FAIL; - } cnc_delay_ms(g_settings.debounce_ms); // adds a delay before reading io pin (debounce) probe_ok = io_get_probe(); @@ -957,7 +953,6 @@ uint8_t mc_probe(float *target, uint8_t flags, motion_data_t *block_data) } return STATUS_OK; } - #endif return STATUS_PROBE_SUCCESS; @@ -1133,7 +1128,7 @@ uint8_t mc_build_hmap(float *target, float *offset, float retract_h, motion_data // store position int32_t probe_position[STEPPER_COUNT]; - itp_get_rt_position(probe_position); + parser_get_probe(probe_position); kinematics_steps_to_coordinates(probe_position, position); hmap_offsets[i + H_MAPING_GRID_FACTOR * j] = position[AXIS_TOOL]; protocol_send_probe_result(1); diff --git a/uCNC/src/core/parser.c b/uCNC/src/core/parser.c index 279ad439..9ae0ce79 100644 --- a/uCNC/src/core/parser.c +++ b/uCNC/src/core/parser.c @@ -291,6 +291,10 @@ void parser_sync_probe(void) itp_get_rt_position(rt_probe_step_pos); } +void parser_get_probe(int32_t *position){ + memcpy(position, rt_probe_step_pos, sizeof(rt_probe_step_pos)); +} + void parser_update_probe_pos(void) { kinematics_steps_to_coordinates(rt_probe_step_pos, parser_parameters.last_probe_position); @@ -1711,8 +1715,12 @@ uint8_t parser_exec_command(parser_state_t *new_state, parser_words_t *words, pa } else { + // failed at this position + parser_sync_probe(); parser_parameters.last_probe_ok = 0; } + // sync probe position + parser_update_probe_pos(); if (error == STATUS_OK) { diff --git a/uCNC/src/core/parser.h b/uCNC/src/core/parser.h index 28aafa3a..9d55004f 100644 --- a/uCNC/src/core/parser.h +++ b/uCNC/src/core/parser.h @@ -301,6 +301,7 @@ extern "C" void parser_get_coordsys(uint8_t system_num, float *axis); bool parser_get_wco(float *axis); void parser_sync_probe(void); + void parser_get_probe(int32_t *position); void parser_update_probe_pos(void); uint8_t parser_get_probe_result(void); void parser_parameters_load(void);