|
@@ -93,8 +93,8 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_
|
93
|
93
|
|
94
|
94
|
static bool check_endstops = true;
|
95
|
95
|
|
96
|
|
-volatile long count_position[NUM_AXIS] = { 0 };
|
97
|
|
-volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
|
|
96
|
+volatile long count_position[NUM_AXIS] = { 0 }; // Positions of stepper motors, in step units
|
|
97
|
+volatile signed char count_direction[NUM_AXIS] = { 1 };
|
98
|
98
|
|
99
|
99
|
|
100
|
100
|
//===========================================================================
|
|
@@ -286,9 +286,17 @@ void checkHitEndstops() {
|
286
|
286
|
}
|
287
|
287
|
}
|
288
|
288
|
|
|
289
|
+#if ENABLED(COREXY) || ENABLED(COREXZ)
|
|
290
|
+ #if ENABLED(COREXY)
|
|
291
|
+ #define CORE_AXIS_2 B_AXIS
|
|
292
|
+ #else
|
|
293
|
+ #define CORE_AXIS_2 C_AXIS
|
|
294
|
+ #endif
|
|
295
|
+#endif
|
|
296
|
+
|
289
|
297
|
void enable_endstops(bool check) { check_endstops = check; }
|
290
|
298
|
|
291
|
|
-// Check endstops
|
|
299
|
+// Check endstops - called from ISR!
|
292
|
300
|
inline void update_endstops() {
|
293
|
301
|
|
294
|
302
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
@@ -311,23 +319,36 @@ inline void update_endstops() {
|
311
|
319
|
// TEST_ENDSTOP: test the old and the current status of an endstop
|
312
|
320
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP))
|
313
|
321
|
|
314
|
|
- #define UPDATE_ENDSTOP(AXIS,MINMAX) \
|
315
|
|
- SET_ENDSTOP_BIT(AXIS, MINMAX); \
|
316
|
|
- if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
|
317
|
|
- endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
|
318
|
|
- _ENDSTOP_HIT(AXIS); \
|
319
|
|
- step_events_completed = current_block->step_event_count; \
|
320
|
|
- }
|
|
322
|
+ #if ENABLED(COREXY) || ENABLED(COREXZ)
|
321
|
323
|
|
322
|
|
- #if ENABLED(COREXY)
|
323
|
|
- // Head direction in -X axis for CoreXY bots.
|
324
|
|
- // If DeltaX == -DeltaY, the movement is only in Y axis
|
325
|
|
- if ((current_block->steps[A_AXIS] != current_block->steps[B_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, B_AXIS))) {
|
326
|
|
- if (TEST(out_bits, X_HEAD))
|
327
|
|
- #elif ENABLED(COREXZ)
|
328
|
|
- // Head direction in -X axis for CoreXZ bots.
|
329
|
|
- // If DeltaX == -DeltaZ, the movement is only in Z axis
|
330
|
|
- if ((current_block->steps[A_AXIS] != current_block->steps[C_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, C_AXIS))) {
|
|
324
|
+ #define _SET_TRIGSTEPS(AXIS) do { \
|
|
325
|
+ float axis_pos = count_position[_AXIS(AXIS)]; \
|
|
326
|
+ if (_AXIS(AXIS) == A_AXIS) \
|
|
327
|
+ axis_pos = (axis_pos + count_position[CORE_AXIS_2]) / 2; \
|
|
328
|
+ else if (_AXIS(AXIS) == CORE_AXIS_2) \
|
|
329
|
+ axis_pos = (count_position[A_AXIS] - axis_pos) / 2; \
|
|
330
|
+ endstops_trigsteps[_AXIS(AXIS)] = axis_pos; \
|
|
331
|
+ } while(0)
|
|
332
|
+
|
|
333
|
+ #else
|
|
334
|
+
|
|
335
|
+ #define _SET_TRIGSTEPS(AXIS) endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]
|
|
336
|
+
|
|
337
|
+ #endif // COREXY || COREXZ
|
|
338
|
+
|
|
339
|
+ #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
|
|
340
|
+ SET_ENDSTOP_BIT(AXIS, MINMAX); \
|
|
341
|
+ if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && current_block->steps[_AXIS(AXIS)] > 0) { \
|
|
342
|
+ _SET_TRIGSTEPS(AXIS); \
|
|
343
|
+ _ENDSTOP_HIT(AXIS); \
|
|
344
|
+ step_events_completed = current_block->step_event_count; \
|
|
345
|
+ } \
|
|
346
|
+ } while(0)
|
|
347
|
+
|
|
348
|
+ #if ENABLED(COREXY) || ENABLED(COREXZ)
|
|
349
|
+ // Head direction in -X axis for CoreXY and CoreXZ bots.
|
|
350
|
+ // If Delta1 == -Delta2, the movement is only in Y or Z axis
|
|
351
|
+ if ((current_block->steps[A_AXIS] != current_block->steps[CORE_AXIS_2]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, CORE_AXIS_2))) {
|
331
|
352
|
if (TEST(out_bits, X_HEAD))
|
332
|
353
|
#else
|
333
|
354
|
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) {
|
1087
|
1108
|
}
|
1088
|
1109
|
|
1089
|
1110
|
long st_get_position(uint8_t axis) {
|
1090
|
|
- long count_pos;
|
1091
|
1111
|
CRITICAL_SECTION_START;
|
1092
|
|
- count_pos = count_position[axis];
|
|
1112
|
+ long count_pos = count_position[axis];
|
1093
|
1113
|
CRITICAL_SECTION_END;
|
1094
|
1114
|
return count_pos;
|
1095
|
1115
|
}
|
1096
|
1116
|
|
1097
|
|
-float st_get_position_mm(AxisEnum axis) { return st_get_position(axis) / axis_steps_per_unit[axis]; }
|
|
1117
|
+float st_get_axis_position_mm(AxisEnum axis) {
|
|
1118
|
+ float axis_pos;
|
|
1119
|
+ #if ENABLED(COREXY) | ENABLED(COREXZ)
|
|
1120
|
+ if (axis == X_AXIS || axis == CORE_AXIS_2) {
|
|
1121
|
+ CRITICAL_SECTION_START;
|
|
1122
|
+ long pos1 = count_position[A_AXIS],
|
|
1123
|
+ pos2 = count_position[CORE_AXIS_2];
|
|
1124
|
+ CRITICAL_SECTION_END;
|
|
1125
|
+ // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
|
|
1126
|
+ // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
|
|
1127
|
+ axis_pos = (pos1 + ((axis == X_AXIS) ? pos2 : -pos2)) / 2.0f;
|
|
1128
|
+ }
|
|
1129
|
+ else
|
|
1130
|
+ axis_pos = st_get_position(axis);
|
|
1131
|
+ #else
|
|
1132
|
+ axis_pos = st_get_position(axis);
|
|
1133
|
+ #endif
|
|
1134
|
+ return axis_pos / axis_steps_per_unit[axis];
|
|
1135
|
+}
|
1098
|
1136
|
|
1099
|
1137
|
void finishAndDisableSteppers() {
|
1100
|
1138
|
st_synchronize();
|