Browse Source

Fixes for COREXY and COREXZ coordinates

Scott Lahteine 9 years ago
parent
commit
373e8a1ad4
3 changed files with 75 additions and 37 deletions
  1. 14
    14
      Marlin/Marlin_main.cpp
  2. 1
    1
      Marlin/planner.cpp
  3. 60
    22
      Marlin/stepper.cpp

+ 14
- 14
Marlin/Marlin_main.cpp View File

@@ -1321,7 +1321,7 @@ static void setup_for_endstop_move() {
1321 1321
       st_synchronize();
1322 1322
 
1323 1323
       // Tell the planner where we ended up - Get this from the stepper handler
1324
-      zPosition = st_get_position_mm(Z_AXIS);
1324
+      zPosition = st_get_axis_position_mm(Z_AXIS);
1325 1325
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS]);
1326 1326
 
1327 1327
       // move up the retract distance
@@ -1339,7 +1339,7 @@ static void setup_for_endstop_move() {
1339 1339
       endstops_hit_on_purpose(); // clear endstop hit flags
1340 1340
 
1341 1341
       // Get the current stepper position after bumping an endstop
1342
-      current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1342
+      current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
1343 1343
       sync_plan_position();
1344 1344
 
1345 1345
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3143,7 +3143,7 @@ inline void gcode_G28() {
3143 3143
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3144 3144
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3145 3145
               z_tmp = current_position[Z_AXIS],
3146
-              real_z = st_get_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
3146
+              real_z = st_get_axis_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
3147 3147
 
3148 3148
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3149 3149
           if (marlin_debug_flags & DEBUG_LEVELING) {
@@ -3585,10 +3585,10 @@ inline void gcode_M42() {
3585 3585
       }
3586 3586
     }
3587 3587
 
3588
-    double X_current = st_get_position_mm(X_AXIS),
3589
-           Y_current = st_get_position_mm(Y_AXIS),
3590
-           Z_current = st_get_position_mm(Z_AXIS),
3591
-           E_current = st_get_position_mm(E_AXIS),
3588
+    double X_current = st_get_axis_position_mm(X_AXIS),
3589
+           Y_current = st_get_axis_position_mm(Y_AXIS),
3590
+           Z_current = st_get_axis_position_mm(Z_AXIS),
3591
+           E_current = st_get_axis_position_mm(E_AXIS),
3592 3592
            X_probe_location = X_current, Y_probe_location = Y_current,
3593 3593
            Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
3594 3594
 
@@ -3642,10 +3642,10 @@ inline void gcode_M42() {
3642 3642
                      active_extruder);
3643 3643
     st_synchronize();
3644 3644
 
3645
-    current_position[X_AXIS] = X_current = st_get_position_mm(X_AXIS);
3646
-    current_position[Y_AXIS] = Y_current = st_get_position_mm(Y_AXIS);
3647
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3648
-    current_position[E_AXIS] = E_current = st_get_position_mm(E_AXIS);
3645
+    current_position[X_AXIS] = X_current = st_get_axis_position_mm(X_AXIS);
3646
+    current_position[Y_AXIS] = Y_current = st_get_axis_position_mm(Y_AXIS);
3647
+    current_position[Z_AXIS] = Z_current = st_get_axis_position_mm(Z_AXIS);
3648
+    current_position[E_AXIS] = E_current = st_get_axis_position_mm(E_AXIS);
3649 3649
 
3650 3650
     //
3651 3651
     // OK, do the initial probe to get us close to the bed.
@@ -3657,15 +3657,15 @@ inline void gcode_M42() {
3657 3657
     setup_for_endstop_move();
3658 3658
     run_z_probe();
3659 3659
 
3660
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3661
-    Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING;
3660
+    Z_current = current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
3661
+    Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
3662 3662
 
3663 3663
     plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location,
3664 3664
                      E_current,
3665 3665
                      homing_feedrate[X_AXIS] / 60,
3666 3666
                      active_extruder);
3667 3667
     st_synchronize();
3668
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3668
+    Z_current = current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
3669 3669
 
3670 3670
     if (deploy_probe_for_each_reading) stow_z_probe();
3671 3671
 

+ 1
- 1
Marlin/planner.cpp View File

@@ -1005,7 +1005,7 @@ float junction_deviation = 0.1;
1005 1005
 
1006 1006
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1007 1007
   vector_3 plan_get_position() {
1008
-    vector_3 position = vector_3(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS), st_get_position_mm(Z_AXIS));
1008
+    vector_3 position = vector_3(st_get_axis_position_mm(X_AXIS), st_get_axis_position_mm(Y_AXIS), st_get_axis_position_mm(Z_AXIS));
1009 1009
 
1010 1010
     //position.debug("in plan_get position");
1011 1011
     //plan_bed_level_matrix.debug("in plan_get_position");

+ 60
- 22
Marlin/stepper.cpp View File

@@ -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();

Loading…
Cancel
Save