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

added motion control incremental jog command #594

Merged
merged 2 commits into from
Jan 22, 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
35 changes: 33 additions & 2 deletions uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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();
Expand Down Expand Up @@ -967,6 +968,36 @@ 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];
uint8_t state = cnc_get_exec_state(EXEC_ALLACTIVE);

if ((state & ~EXEC_JOG) || cnc_has_alarm()) // if any other than idle or jog discards the command
{
return STATUS_IDLE_ERROR;
}

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)
Expand Down
2 changes: 2 additions & 0 deletions uCNC/src/core/motion_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down