From 725165787224e386c05f80a66a73d212a65712d2 Mon Sep 17 00:00:00 2001 From: chamnit Date: Mon, 25 Jul 2016 11:11:27 -0600 Subject: [PATCH 1/2] CoreXY homing fix attempt. --- grbl/config.h | 2 +- grbl/limits.c | 40 +++++++++++++++++++++++++++++----------- grbl/planner.c | 8 ++++---- grbl/system.c | 23 ++++++++++++++++++----- grbl/system.h | 3 +++ 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index bd9c0d6..d524796 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -149,7 +149,7 @@ // defined at (http://corexy.com/theory.html). Motors are assumed to positioned and wired exactly as // described, if not, motions may move in strange directions. Grbl assumes the CoreXY A and B motors // have the same steps per mm internally. -// #define COREXY // Default disabled. Uncomment to enable. +#define COREXY // Default disabled. Uncomment to enable. // Inverts pin logic of the control command pins. This essentially means when this option is enabled // you can use normally-closed switches, rather than the default normally-open switches. diff --git a/grbl/limits.c b/grbl/limits.c index 6cd1cd9..947a6ed 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -184,7 +184,21 @@ void limits_go_home(uint8_t cycle_mask) // Set target location for active axes and setup computation for homing rate. if (bit_istrue(cycle_mask,bit(idx))) { n_active_axis++; - sys.position[idx] = 0; + #ifdef COREXY + int32_t axis_position; + if (idx == X_AXIS) { + axis_position = system_convert_corexy_to_x_axis_steps(sys.position); + sys.position[A_MOTOR] = axis_position; + sys.position[B_MOTOR] = -axis_position; + } else if (idx == Y_AXIS) { + axis_position = system_convert_corexy_to_y_axis_steps(sys.position); + sys.position[A_MOTOR] = sys.position[B_MOTOR] = axis_position; + } else { + sys.position[Z_AXIS] = 0; + } + #else + sys.position[idx] = 0; + #endif // Set target direction based on cycle mask and homing cycle approach state. // NOTE: This happens to compile smaller than any other implementation tried. if (bit_istrue(settings.homing_dir_mask,bit(idx))) { @@ -219,7 +233,14 @@ void limits_go_home(uint8_t cycle_mask) limit_state = limits_get_state(); for (idx=0; idx Date: Mon, 25 Jul 2016 13:50:08 -0600 Subject: [PATCH 2/2] CoreXY homing bug fix attempt 2. --- grbl/config.h | 4 ++-- grbl/limits.c | 7 +++---- grbl/planner.c | 4 ++-- grbl/system.c | 3 +-- grbl/system.h | 1 + 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/grbl/config.h b/grbl/config.h index d524796..f01935b 100644 --- a/grbl/config.h +++ b/grbl/config.h @@ -72,8 +72,8 @@ // on separate pin, but homed in one cycle. Also, it should be noted that the function of hard limits // will not be affected by pin sharing. // NOTE: Defaults are set for a traditional 3-axis CNC machine. Z-axis first to clear, followed by X & Y. -#define HOMING_CYCLE_0 (1<step_event_count = max(block->step_event_count, block->steps[idx]); if (idx == A_MOTOR) { - delta_mm = ((target_steps[X_AXIS]-pl.position[X_AXIS]) + (target_steps[Y_AXIS]-pl.position[Y_AXIS]))/settings.steps_per_mm[idx]; + delta_mm = (target_steps[X_AXIS]-pl.position[X_AXIS] + target_steps[Y_AXIS]-pl.position[Y_AXIS])/settings.steps_per_mm[idx]; } else if (idx == B_MOTOR) { - delta_mm = ((target_steps[X_AXIS]-pl.position[X_AXIS]) - (target_steps[Y_AXIS]-pl.position[Y_AXIS]))/settings.steps_per_mm[idx]; + delta_mm = (target_steps[X_AXIS]-pl.position[X_AXIS] - target_steps[Y_AXIS]+pl.position[Y_AXIS])/settings.steps_per_mm[idx]; } else { delta_mm = (target_steps[idx] - pl.position[idx])/settings.steps_per_mm[idx]; } diff --git a/grbl/system.c b/grbl/system.c index ff678f7..f16b8e8 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -288,12 +288,11 @@ void system_convert_array_steps_to_mpos(float *position, int32_t *steps) } +// CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps. int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps) { return( (steps[A_MOTOR] + steps[B_MOTOR])/2 ); } - - int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps) { return( (steps[A_MOTOR] - steps[B_MOTOR])/2 ); diff --git a/grbl/system.h b/grbl/system.h index 6774d54..09a3171 100644 --- a/grbl/system.h +++ b/grbl/system.h @@ -106,6 +106,7 @@ float system_convert_axis_steps_to_mpos(int32_t *steps, uint8_t idx); // Updates a machine 'position' array based on the 'step' array sent. void system_convert_array_steps_to_mpos(float *position, int32_t *steps); +// CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps. int32_t system_convert_corexy_to_x_axis_steps(int32_t *steps); int32_t system_convert_corexy_to_y_axis_steps(int32_t *steps);