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

modified probing for better precision #586

Merged
merged 5 commits into from
Jan 17, 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
6 changes: 6 additions & 0 deletions uCNC/src/cnc_hal_config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 8 additions & 3 deletions uCNC/src/core/io_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
28 changes: 14 additions & 14 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,34 +912,35 @@ 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);

//similar to itp_sync
do
{
if (!cnc_dotasks())
{
break;
}
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 (!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();

// clears HALT state if possible
cnc_unlock(true);

itp_clear();
planner_clear();
parser_update_probe_pos();
// clears hold
cnc_clear_exec_state(EXEC_HOLD);

// 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();
Expand All @@ -952,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;
Expand Down Expand Up @@ -1128,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);
Expand Down
8 changes: 8 additions & 0 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions uCNC/src/core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down