Browse Source

Merge pull request #2995 from thinkyhead/rcbugfix_corexy_corexz

Add CORE support to st_get_position_mm (and elsewhere)
Scott Lahteine 9 years ago
parent
commit
34b8b9f0f5
4 changed files with 103 additions and 43 deletions
  1. 41
    20
      Marlin/Marlin_main.cpp
  2. 1
    0
      Marlin/language.h
  3. 1
    1
      Marlin/planner.cpp
  4. 60
    22
      Marlin/stepper.cpp

+ 41
- 20
Marlin/Marlin_main.cpp View File

1332
       st_synchronize();
1332
       st_synchronize();
1333
 
1333
 
1334
       // Tell the planner where we ended up - Get this from the stepper handler
1334
       // Tell the planner where we ended up - Get this from the stepper handler
1335
-      zPosition = st_get_position_mm(Z_AXIS);
1335
+      zPosition = st_get_axis_position_mm(Z_AXIS);
1336
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS]);
1336
       plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS]);
1337
 
1337
 
1338
       // move up the retract distance
1338
       // move up the retract distance
1350
       endstops_hit_on_purpose(); // clear endstop hit flags
1350
       endstops_hit_on_purpose(); // clear endstop hit flags
1351
 
1351
 
1352
       // Get the current stepper position after bumping an endstop
1352
       // Get the current stepper position after bumping an endstop
1353
-      current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1353
+      current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
1354
       sync_plan_position();
1354
       sync_plan_position();
1355
 
1355
 
1356
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1356
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3157
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3157
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3158
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3158
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3159
               z_tmp = current_position[Z_AXIS],
3159
               z_tmp = current_position[Z_AXIS],
3160
-              real_z = st_get_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
3160
+              real_z = st_get_axis_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
3161
 
3161
 
3162
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3162
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3163
           if (marlin_debug_flags & DEBUG_LEVELING) {
3163
           if (marlin_debug_flags & DEBUG_LEVELING) {
3604
       }
3604
       }
3605
     }
3605
     }
3606
 
3606
 
3607
-    double X_current = st_get_position_mm(X_AXIS),
3608
-           Y_current = st_get_position_mm(Y_AXIS),
3609
-           Z_current = st_get_position_mm(Z_AXIS),
3610
-           E_current = st_get_position_mm(E_AXIS),
3607
+    double X_current = st_get_axis_position_mm(X_AXIS),
3608
+           Y_current = st_get_axis_position_mm(Y_AXIS),
3609
+           Z_current = st_get_axis_position_mm(Z_AXIS),
3610
+           E_current = st_get_axis_position_mm(E_AXIS),
3611
            X_probe_location = X_current, Y_probe_location = Y_current,
3611
            X_probe_location = X_current, Y_probe_location = Y_current,
3612
            Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
3612
            Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
3613
 
3613
 
3661
                      active_extruder);
3661
                      active_extruder);
3662
     st_synchronize();
3662
     st_synchronize();
3663
 
3663
 
3664
-    current_position[X_AXIS] = X_current = st_get_position_mm(X_AXIS);
3665
-    current_position[Y_AXIS] = Y_current = st_get_position_mm(Y_AXIS);
3666
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3667
-    current_position[E_AXIS] = E_current = st_get_position_mm(E_AXIS);
3664
+    current_position[X_AXIS] = X_current = st_get_axis_position_mm(X_AXIS);
3665
+    current_position[Y_AXIS] = Y_current = st_get_axis_position_mm(Y_AXIS);
3666
+    current_position[Z_AXIS] = Z_current = st_get_axis_position_mm(Z_AXIS);
3667
+    current_position[E_AXIS] = E_current = st_get_axis_position_mm(E_AXIS);
3668
 
3668
 
3669
     //
3669
     //
3670
     // OK, do the initial probe to get us close to the bed.
3670
     // OK, do the initial probe to get us close to the bed.
3676
     setup_for_endstop_move();
3676
     setup_for_endstop_move();
3677
     run_z_probe();
3677
     run_z_probe();
3678
 
3678
 
3679
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3680
-    Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING;
3679
+    Z_current = current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
3680
+    Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
3681
 
3681
 
3682
     plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location,
3682
     plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location,
3683
                      E_current,
3683
                      E_current,
3684
                      homing_feedrate[X_AXIS] / 60,
3684
                      homing_feedrate[X_AXIS] / 60,
3685
                      active_extruder);
3685
                      active_extruder);
3686
     st_synchronize();
3686
     st_synchronize();
3687
-    current_position[Z_AXIS] = Z_current = st_get_position_mm(Z_AXIS);
3687
+    Z_current = current_position[Z_AXIS] = st_get_axis_position_mm(Z_AXIS);
3688
 
3688
 
3689
     if (deploy_probe_for_each_reading) stow_z_probe();
3689
     if (deploy_probe_for_each_reading) stow_z_probe();
3690
 
3690
 
4302
   SERIAL_PROTOCOLPGM(" E:");
4302
   SERIAL_PROTOCOLPGM(" E:");
4303
   SERIAL_PROTOCOL(current_position[E_AXIS]);
4303
   SERIAL_PROTOCOL(current_position[E_AXIS]);
4304
 
4304
 
4305
-  SERIAL_PROTOCOLPGM(MSG_COUNT_X);
4306
-  SERIAL_PROTOCOL(st_get_position_mm(X_AXIS));
4307
-  SERIAL_PROTOCOLPGM(" Y:");
4308
-  SERIAL_PROTOCOL(st_get_position_mm(Y_AXIS));
4309
-  SERIAL_PROTOCOLPGM(" Z:");
4310
-  SERIAL_PROTOCOL(st_get_position_mm(Z_AXIS));
4305
+  CRITICAL_SECTION_START;
4306
+  extern volatile long count_position[NUM_AXIS];
4307
+  long xpos = count_position[X_AXIS],
4308
+       ypos = count_position[Y_AXIS],
4309
+       zpos = count_position[Z_AXIS];
4310
+  CRITICAL_SECTION_END;
4311
+
4312
+  #if ENABLED(COREXY) || ENABLED(COREXZ)
4313
+    SERIAL_PROTOCOLPGM(MSG_COUNT_A);
4314
+  #else
4315
+    SERIAL_PROTOCOLPGM(MSG_COUNT_X);
4316
+  #endif
4317
+  SERIAL_PROTOCOL(xpos);
4318
+
4319
+  #if ENABLED(COREXY)
4320
+    SERIAL_PROTOCOLPGM(" B:");
4321
+  #else
4322
+    SERIAL_PROTOCOLPGM(" Y:");
4323
+  #endif
4324
+  SERIAL_PROTOCOL(ypos);
4325
+
4326
+  #if ENABLED(COREXZ)
4327
+    SERIAL_PROTOCOLPGM(" C:");
4328
+  #else
4329
+    SERIAL_PROTOCOLPGM(" Z:");
4330
+  #endif
4331
+  SERIAL_PROTOCOL(zpos);
4311
 
4332
 
4312
   SERIAL_EOL;
4333
   SERIAL_EOL;
4313
 
4334
 

+ 1
- 0
Marlin/language.h View File

124
 #define MSG_ERR_NO_THERMISTORS              "No thermistors - no temperature"
124
 #define MSG_ERR_NO_THERMISTORS              "No thermistors - no temperature"
125
 #define MSG_M115_REPORT                     "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" UUID "\n"
125
 #define MSG_M115_REPORT                     "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" UUID "\n"
126
 #define MSG_COUNT_X                         " Count X: "
126
 #define MSG_COUNT_X                         " Count X: "
127
+#define MSG_COUNT_A                         " Count A: "
127
 #define MSG_ERR_KILLED                      "Printer halted. kill() called!"
128
 #define MSG_ERR_KILLED                      "Printer halted. kill() called!"
128
 #define MSG_ERR_STOPPED                     "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
129
 #define MSG_ERR_STOPPED                     "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
129
 #define MSG_RESEND                          "Resend: "
130
 #define MSG_RESEND                          "Resend: "

+ 1
- 1
Marlin/planner.cpp View File

1005
 
1005
 
1006
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1006
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1007
   vector_3 plan_get_position() {
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
     //position.debug("in plan_get position");
1010
     //position.debug("in plan_get position");
1011
     //plan_bed_level_matrix.debug("in plan_get_position");
1011
     //plan_bed_level_matrix.debug("in plan_get_position");

+ 60
- 22
Marlin/stepper.cpp View File

93
 
93
 
94
 static bool check_endstops = true;
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
   }
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
 void enable_endstops(bool check) { check_endstops = check; }
297
 void enable_endstops(bool check) { check_endstops = check; }
290
 
298
 
291
-// Check endstops
299
+// Check endstops - called from ISR!
292
 inline void update_endstops() {
300
 inline void update_endstops() {
293
 
301
 
294
   #if ENABLED(Z_DUAL_ENDSTOPS)
302
   #if ENABLED(Z_DUAL_ENDSTOPS)
311
   // TEST_ENDSTOP: test the old and the current status of an endstop
319
   // TEST_ENDSTOP: test the old and the current status of an endstop
312
   #define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP) && TEST(old_endstop_bits, ENDSTOP))
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
       if (TEST(out_bits, X_HEAD))
352
       if (TEST(out_bits, X_HEAD))
332
   #else
353
   #else
333
     if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular Cartesian bot)
354
     if (TEST(out_bits, X_AXIS))   // stepping along -X axis (regular Cartesian bot)
1087
 }
1108
 }
1088
 
1109
 
1089
 long st_get_position(uint8_t axis) {
1110
 long st_get_position(uint8_t axis) {
1090
-  long count_pos;
1091
   CRITICAL_SECTION_START;
1111
   CRITICAL_SECTION_START;
1092
-  count_pos = count_position[axis];
1112
+  long count_pos = count_position[axis];
1093
   CRITICAL_SECTION_END;
1113
   CRITICAL_SECTION_END;
1094
   return count_pos;
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
 void finishAndDisableSteppers() {
1137
 void finishAndDisableSteppers() {
1100
   st_synchronize();
1138
   st_synchronize();

Loading…
Cancel
Save