|
@ -93,8 +93,8 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_ |
|
|
|
|
|
|
|
|
static bool check_endstops = true; |
|
|
static bool check_endstops = true; |
|
|
|
|
|
|
|
|
volatile long count_position[NUM_AXIS] = { 0 }; |
|
|
volatile long count_position[NUM_AXIS] = { 0 }; // Positions of stepper motors, in step units
|
|
|
volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; |
|
|
volatile signed char count_direction[NUM_AXIS] = { 1 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
//===========================================================================
|
|
@ -286,9 +286,17 @@ void checkHitEndstops() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(COREXY) || ENABLED(COREXZ) |
|
|
|
|
|
#if ENABLED(COREXY) |
|
|
|
|
|
#define CORE_AXIS_2 B_AXIS |
|
|
|
|
|
#else |
|
|
|
|
|
#define CORE_AXIS_2 C_AXIS |
|
|
|
|
|
#endif |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
void enable_endstops(bool check) { check_endstops = check; } |
|
|
void enable_endstops(bool check) { check_endstops = check; } |
|
|
|
|
|
|
|
|
// Check endstops
|
|
|
// Check endstops - called from ISR!
|
|
|
inline void update_endstops() { |
|
|
inline void update_endstops() { |
|
|
|
|
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
@ -311,23 +319,36 @@ inline void update_endstops() { |
|
|
// TEST_ENDSTOP: test the old and the current status of an endstop
|
|
|
// TEST_ENDSTOP: test the old and the current status of an endstop
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP)) |
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP)) |
|
|
|
|
|
|
|
|
#define UPDATE_ENDSTOP(AXIS,MINMAX) \ |
|
|
#if ENABLED(COREXY) || ENABLED(COREXZ) |
|
|
|
|
|
|
|
|
|
|
|
#define _SET_TRIGSTEPS(AXIS) do { \ |
|
|
|
|
|
float axis_pos = count_position[_AXIS(AXIS)]; \ |
|
|
|
|
|
if (_AXIS(AXIS) == A_AXIS) \ |
|
|
|
|
|
axis_pos = (axis_pos + count_position[CORE_AXIS_2]) / 2; \ |
|
|
|
|
|
else if (_AXIS(AXIS) == CORE_AXIS_2) \ |
|
|
|
|
|
axis_pos = (count_position[A_AXIS] - axis_pos) / 2; \ |
|
|
|
|
|
endstops_trigsteps[_AXIS(AXIS)] = axis_pos; \ |
|
|
|
|
|
} while(0) |
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
|
|
|
|
#define _SET_TRIGSTEPS(AXIS) endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)] |
|
|
|
|
|
|
|
|
|
|
|
#endif // COREXY || COREXZ
|
|
|
|
|
|
|
|
|
|
|
|
#define UPDATE_ENDSTOP(AXIS,MINMAX) do { \ |
|
|
SET_ENDSTOP_BIT(AXIS, MINMAX); \ |
|
|
SET_ENDSTOP_BIT(AXIS, MINMAX); \ |
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && (current_block->steps[_AXIS(AXIS)] > 0)) { \ |
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && current_block->steps[_AXIS(AXIS)] > 0) { \ |
|
|
endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \ |
|
|
_SET_TRIGSTEPS(AXIS); \ |
|
|
_ENDSTOP_HIT(AXIS); \ |
|
|
_ENDSTOP_HIT(AXIS); \ |
|
|
step_events_completed = current_block->step_event_count; \ |
|
|
step_events_completed = current_block->step_event_count; \ |
|
|
} |
|
|
} \ |
|
|
|
|
|
} while(0) |
|
|
|
|
|
|
|
|
#if ENABLED(COREXY) |
|
|
#if ENABLED(COREXY) || ENABLED(COREXZ) |
|
|
// Head direction in -X axis for CoreXY bots.
|
|
|
// Head direction in -X axis for CoreXY and CoreXZ bots.
|
|
|
// If DeltaX == -DeltaY, the movement is only in Y axis
|
|
|
// If Delta1 == -Delta2, the movement is only in Y or Z axis
|
|
|
if ((current_block->steps[A_AXIS] != current_block->steps[B_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS))) { |
|
|
if ((current_block->steps[A_AXIS] != current_block->steps[CORE_AXIS_2]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, CORE_AXIS_2))) { |
|
|
if (TEST(out_bits, X_HEAD)) |
|
|
|
|
|
#elif ENABLED(COREXZ) |
|
|
|
|
|
// Head direction in -X axis for CoreXZ bots.
|
|
|
|
|
|
// If DeltaX == -DeltaZ, the movement is only in Z axis
|
|
|
|
|
|
if ((current_block->steps[A_AXIS] != current_block->steps[C_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, C_AXIS))) { |
|
|
|
|
|
if (TEST(out_bits, X_HEAD)) |
|
|
if (TEST(out_bits, X_HEAD)) |
|
|
#else |
|
|
#else |
|
|
if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular Cartesian bot)
|
|
|
if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular Cartesian bot)
|
|
@ -1087,14 +1108,31 @@ void st_set_e_position(const long& e) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
long st_get_position(uint8_t axis) { |
|
|
long st_get_position(uint8_t axis) { |
|
|
long count_pos; |
|
|
|
|
|
CRITICAL_SECTION_START; |
|
|
CRITICAL_SECTION_START; |
|
|
count_pos = count_position[axis]; |
|
|
long count_pos = count_position[axis]; |
|
|
CRITICAL_SECTION_END; |
|
|
CRITICAL_SECTION_END; |
|
|
return count_pos; |
|
|
return count_pos; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
float st_get_position_mm(AxisEnum axis) { return st_get_position(axis) / axis_steps_per_unit[axis]; } |
|
|
float st_get_axis_position_mm(AxisEnum axis) { |
|
|
|
|
|
float axis_pos; |
|
|
|
|
|
#if ENABLED(COREXY) | ENABLED(COREXZ) |
|
|
|
|
|
if (axis == X_AXIS || axis == CORE_AXIS_2) { |
|
|
|
|
|
CRITICAL_SECTION_START; |
|
|
|
|
|
long pos1 = count_position[A_AXIS], |
|
|
|
|
|
pos2 = count_position[CORE_AXIS_2]; |
|
|
|
|
|
CRITICAL_SECTION_END; |
|
|
|
|
|
// ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
|
|
|
|
|
|
// ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
|
|
|
|
|
|
axis_pos = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
axis_pos = st_get_position(axis); |
|
|
|
|
|
#else |
|
|
|
|
|
axis_pos = st_get_position(axis); |
|
|
|
|
|
#endif |
|
|
|
|
|
return axis_pos / axis_steps_per_unit[axis]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void finishAndDisableSteppers() { |
|
|
void finishAndDisableSteppers() { |
|
|
st_synchronize(); |
|
|
st_synchronize(); |
|
|