Explorar el Código

Regression: Endstops Core compatibility (#10823)

Co-Authored-By: ejtagle <ejtagle@hotmail.com>
Scott Lahteine hace 7 años
padre
commit
3e3789da85
No account linked to committer's email address

+ 1
- 0
Marlin/src/core/macros.h Ver fichero

@@ -71,6 +71,7 @@
71 71
 #define TEST(n,b) !!((n)&_BV(b))
72 72
 #define SBI(n,b) (n |= _BV(b))
73 73
 #define CBI(n,b) (n &= ~_BV(b))
74
+#define SET_BIT(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
74 75
 
75 76
 #define _BV32(b) (1UL << (b))
76 77
 #define TEST32(n,b) !!((n)&_BV32(b))

+ 29
- 84
Marlin/src/module/endstops.cpp Ver fichero

@@ -37,9 +37,9 @@
37 37
 #endif
38 38
 
39 39
 #if HAS_BED_PROBE
40
-  #define ENDSTOPS_ENABLED  (endstops.enabled || endstops.z_probe_enabled)
40
+  #define ENDSTOPS_ENABLED  (enabled || z_probe_enabled)
41 41
 #else
42
-  #define ENDSTOPS_ENABLED  endstops.enabled
42
+  #define ENDSTOPS_ENABLED  enabled
43 43
 #endif
44 44
 
45 45
 Endstops endstops;
@@ -223,17 +223,17 @@ void Endstops::init() {
223 223
 } // Endstops::init
224 224
 
225 225
 // Called from ISR. A change was detected. Find out what happened!
226
-void Endstops::check_possible_change() { if (ENDSTOPS_ENABLED) endstops.update(); }
226
+void Endstops::check_possible_change() { if (ENDSTOPS_ENABLED) update(); }
227 227
 
228 228
 // Called from ISR: Poll endstop state if required
229 229
 void Endstops::poll() {
230 230
 
231 231
   #if ENABLED(PINS_DEBUGGING)
232
-    endstops.run_monitor();  // report changes in endstop status
232
+    run_monitor();  // report changes in endstop status
233 233
   #endif
234 234
 
235 235
   #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
236
-    if (ENDSTOPS_ENABLED) endstops.update();
236
+    if (ENDSTOPS_ENABLED) update();
237 237
   #endif
238 238
 }
239 239
 
@@ -241,7 +241,7 @@ void Endstops::enable_globally(const bool onoff) {
241 241
   enabled_globally = enabled = onoff;
242 242
 
243 243
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
244
-    if (onoff) endstops.update(); // If enabling, update state now
244
+    if (onoff) update(); // If enabling, update state now
245 245
   #endif
246 246
 }
247 247
 
@@ -250,17 +250,16 @@ void Endstops::enable(const bool onoff) {
250 250
   enabled = onoff;
251 251
 
252 252
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
253
-    if (onoff) endstops.update(); // If enabling, update state now
253
+    if (onoff) update(); // If enabling, update state now
254 254
   #endif
255 255
 }
256 256
 
257
-
258 257
 // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
259 258
 void Endstops::not_homing() {
260 259
   enabled = enabled_globally;
261 260
 
262 261
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
263
-    if (enabled) endstops.update(); // If enabling, update state now
262
+    if (enabled) update(); // If enabling, update state now
264 263
   #endif
265 264
 }
266 265
 
@@ -269,7 +268,7 @@ void Endstops::hit_on_purpose() {
269 268
   hit_state = 0;
270 269
 
271 270
   #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
272
-    if (enabled) endstops.update(); // If enabling, update state now
271
+    if (enabled) update(); // If enabling, update state now
273 272
   #endif
274 273
 }
275 274
 
@@ -279,7 +278,7 @@ void Endstops::hit_on_purpose() {
279 278
     z_probe_enabled = onoff;
280 279
 
281 280
     #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
282
-      if (enabled) endstops.update(); // If enabling, update state now
281
+      if (enabled) update(); // If enabling, update state now
283 282
     #endif
284 283
   }
285 284
 #endif
@@ -417,89 +416,37 @@ void Endstops::update() {
417 416
     if (G38_move) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
418 417
   #endif
419 418
 
420
-  /**
421
-   * Define conditions for checking endstops
422
-   */
423
-
424
-  #if IS_CORE
425
-    #define S_(N) stepper.movement_non_null(CORE_AXIS_##N)
426
-    #define D_(N) stepper.motor_direction(CORE_AXIS_##N)
419
+  // With Dual X, endstops are only checked in the homing direction for the active extruder
420
+  #if ENABLED(DUAL_X_CARRIAGE)
421
+    #define E0_ACTIVE stepper.movement_extruder() == 0
422
+    #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
423
+    #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
424
+  #else
425
+    #define X_MIN_TEST true
426
+    #define X_MAX_TEST true
427 427
   #endif
428 428
 
429
+  // Use HEAD for core axes, AXIS for others
429 430
   #if CORE_IS_XY || CORE_IS_XZ
430
-    /**
431
-     * Head direction in -X axis for CoreXY and CoreXZ bots.
432
-     *
433
-     * If steps differ, both axes are moving.
434
-     * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
435
-     * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X)
436
-     */
437
-    #if ENABLED(COREXY) || ENABLED(COREXZ)
438
-      #define X_CMP ==
439
-    #else
440
-      #define X_CMP !=
441
-    #endif
442
-    #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
443 431
     #define X_AXIS_HEAD X_HEAD
444 432
   #else
445
-    #define X_MOVE_TEST stepper.movement_non_null(X_AXIS)
446 433
     #define X_AXIS_HEAD X_AXIS
447 434
   #endif
448
-
449 435
   #if CORE_IS_XY || CORE_IS_YZ
450
-    /**
451
-     * Head direction in -Y axis for CoreXY / CoreYZ bots.
452
-     *
453
-     * If steps differ, both axes are moving
454
-     * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X or Y)
455
-     * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
456
-     */
457
-    #if ENABLED(COREYX) || ENABLED(COREYZ)
458
-      #define Y_CMP ==
459
-    #else
460
-      #define Y_CMP !=
461
-    #endif
462
-    #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
463 436
     #define Y_AXIS_HEAD Y_HEAD
464 437
   #else
465
-    #define Y_MOVE_TEST stepper.movement_non_null(Y_AXIS)
466 438
     #define Y_AXIS_HEAD Y_AXIS
467 439
   #endif
468
-
469 440
   #if CORE_IS_XZ || CORE_IS_YZ
470
-    /**
471
-     * Head direction in -Z axis for CoreXZ or CoreYZ bots.
472
-     *
473
-     * If steps differ, both axes are moving
474
-     * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
475
-     * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
476
-     */
477
-    #if ENABLED(COREZX) || ENABLED(COREZY)
478
-      #define Z_CMP ==
479
-    #else
480
-      #define Z_CMP !=
481
-    #endif
482
-    #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
483 441
     #define Z_AXIS_HEAD Z_HEAD
484 442
   #else
485
-    #define Z_MOVE_TEST stepper.movement_non_null(Z_AXIS)
486 443
     #define Z_AXIS_HEAD Z_AXIS
487 444
   #endif
488 445
 
489
-  // With Dual X, endstops are only checked in the homing direction for the active extruder
490
-  #if ENABLED(DUAL_X_CARRIAGE)
491
-    #define E0_ACTIVE stepper.movement_extruder() == 0
492
-    #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
493
-    #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
494
-  #else
495
-    #define X_MIN_TEST true
496
-    #define X_MAX_TEST true
497
-  #endif
498
-
499 446
   /**
500 447
    * Check and update endstops according to conditions
501 448
    */
502
-  if (X_MOVE_TEST) {
449
+  if (stepper.axis_is_moving(X_AXIS)) {
503 450
     if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
504 451
       #if HAS_X_MIN
505 452
         #if ENABLED(X_DUAL_ENDSTOPS)
@@ -530,7 +477,7 @@ void Endstops::update() {
530 477
     }
531 478
   }
532 479
 
533
-  if (Y_MOVE_TEST) {
480
+  if (stepper.axis_is_moving(Y_AXIS)) {
534 481
     if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
535 482
       #if HAS_Y_MIN
536 483
         #if ENABLED(Y_DUAL_ENDSTOPS)
@@ -561,7 +508,7 @@ void Endstops::update() {
561 508
     }
562 509
   }
563 510
 
564
-  if (Z_MOVE_TEST) {
511
+  if (stepper.axis_is_moving(Z_AXIS)) {
565 512
     if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
566 513
       #if HAS_Z_MIN
567 514
         #if ENABLED(Z_DUAL_ENDSTOPS)
@@ -582,9 +529,7 @@ void Endstops::update() {
582 529
 
583 530
       // When closing the gap check the enabled probe
584 531
       #if ENABLED(Z_MIN_PROBE_ENDSTOP)
585
-        if (z_probe_enabled) {
586
-          UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
587
-        }
532
+        if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
588 533
       #endif
589 534
     }
590 535
     else { // Z +direction. Gantry up, bed down.
@@ -660,16 +605,16 @@ void Endstops::update() {
660 605
     // If G38 command is active check Z_MIN_PROBE for ALL movement
661 606
     if (G38_move) {
662 607
       if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
663
-        if      (stepper.movement_non_null(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); }
664
-        else if (stepper.movement_non_null(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); }
665
-        else if (stepper.movement_non_null(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); }
608
+        if      (stepper.axis_is_moving(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); }
609
+        else if (stepper.axis_is_moving(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); }
610
+        else if (stepper.axis_is_moving(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); }
666 611
         G38_endstop_hit = true;
667 612
       }
668 613
     }
669 614
   #endif
670 615
 
671 616
   // Now, we must signal, after validation, if an endstop limit is pressed or not
672
-  if (X_MOVE_TEST) {
617
+  if (stepper.axis_is_moving(X_AXIS)) {
673 618
     if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
674 619
       #if HAS_X_MIN
675 620
         #if ENABLED(X_DUAL_ENDSTOPS)
@@ -690,7 +635,7 @@ void Endstops::update() {
690 635
     }
691 636
   }
692 637
 
693
-  if (Y_MOVE_TEST) {
638
+  if (stepper.axis_is_moving(Y_AXIS)) {
694 639
     if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
695 640
       #if HAS_Y_MIN
696 641
         #if ENABLED(Y_DUAL_ENDSTOPS)
@@ -711,7 +656,7 @@ void Endstops::update() {
711 656
     }
712 657
   }
713 658
 
714
-  if (Z_MOVE_TEST) {
659
+  if (stepper.axis_is_moving(Z_AXIS)) {
715 660
     if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
716 661
       #if HAS_Z_MIN
717 662
         #if ENABLED(Z_DUAL_ENDSTOPS)

+ 73
- 6
Marlin/src/module/stepper.cpp Ver fichero

@@ -96,10 +96,10 @@ block_t* Stepper::current_block = NULL;  // A pointer to the block currently bei
96 96
 
97 97
 // private:
98 98
 
99
-uint8_t Stepper::last_direction_bits = 0,       // The next stepping-bits to be output
100
-        Stepper::last_movement_extruder = 0xFF; // Last movement extruder, as computed when the last movement was fetched from planner
101
-bool Stepper::abort_current_block,              // Signals to the stepper that current block should be aborted
102
-     Stepper::last_movement_non_null[NUM_AXIS]; // Last Movement in the given direction is not null, as computed when the last movement was fetched from planner
99
+uint8_t Stepper::last_direction_bits = 0,
100
+        Stepper::last_movement_extruder = 0xFF,
101
+        Stepper::axis_did_move;
102
+bool Stepper::abort_current_block;
103 103
 
104 104
 #if ENABLED(X_DUAL_ENDSTOPS)
105 105
   bool Stepper::locked_x_motor = false, Stepper::locked_x2_motor = false;
@@ -1566,8 +1566,75 @@ uint32_t Stepper::stepper_block_phase_isr() {
1566 1566
           return interval; // No more queued movements!
1567 1567
       }
1568 1568
 
1569
-      // Compute movement direction for proper endstop handling
1570
-      LOOP_NA(i) last_movement_non_null[i] = !!current_block->steps[i];
1569
+      // Flag all moving axes for proper endstop handling
1570
+
1571
+      #if IS_CORE
1572
+        // Define conditions for checking endstops
1573
+        #define S_(N) current_block->steps[CORE_AXIS_##N]
1574
+        #define D_(N) motor_direction(CORE_AXIS_##N)
1575
+      #endif
1576
+
1577
+      #if CORE_IS_XY || CORE_IS_XZ
1578
+        /**
1579
+         * Head direction in -X axis for CoreXY and CoreXZ bots.
1580
+         *
1581
+         * If steps differ, both axes are moving.
1582
+         * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
1583
+         * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X)
1584
+         */
1585
+        #if ENABLED(COREXY) || ENABLED(COREXZ)
1586
+          #define X_CMP ==
1587
+        #else
1588
+          #define X_CMP !=
1589
+        #endif
1590
+        #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
1591
+      #else
1592
+        #define X_MOVE_TEST !!current_block->steps[X_AXIS]
1593
+      #endif
1594
+
1595
+      #if CORE_IS_XY || CORE_IS_YZ
1596
+        /**
1597
+         * Head direction in -Y axis for CoreXY / CoreYZ bots.
1598
+         *
1599
+         * If steps differ, both axes are moving
1600
+         * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X or Y)
1601
+         * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
1602
+         */
1603
+        #if ENABLED(COREYX) || ENABLED(COREYZ)
1604
+          #define Y_CMP ==
1605
+        #else
1606
+          #define Y_CMP !=
1607
+        #endif
1608
+        #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
1609
+      #else
1610
+        #define Y_MOVE_TEST !!current_block->steps[Y_AXIS]
1611
+      #endif
1612
+
1613
+      #if CORE_IS_XZ || CORE_IS_YZ
1614
+        /**
1615
+         * Head direction in -Z axis for CoreXZ or CoreYZ bots.
1616
+         *
1617
+         * If steps differ, both axes are moving
1618
+         * If DeltaA ==  DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
1619
+         * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
1620
+         */
1621
+        #if ENABLED(COREZX) || ENABLED(COREZY)
1622
+          #define Z_CMP ==
1623
+        #else
1624
+          #define Z_CMP !=
1625
+        #endif
1626
+        #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
1627
+      #else
1628
+        #define Z_MOVE_TEST !!current_block->steps[Z_AXIS]
1629
+      #endif
1630
+
1631
+      SET_BIT(axis_did_move, X_AXIS, X_MOVE_TEST);
1632
+      SET_BIT(axis_did_move, Y_AXIS, Y_MOVE_TEST);
1633
+      SET_BIT(axis_did_move, Z_AXIS, Z_MOVE_TEST);
1634
+      SET_BIT(axis_did_move, E_AXIS, !!current_block->steps[E_AXIS]);
1635
+      SET_BIT(axis_did_move, X_HEAD, !!current_block->steps[X_HEAD]);
1636
+      SET_BIT(axis_did_move, Y_HEAD, !!current_block->steps[Y_HEAD]);
1637
+      SET_BIT(axis_did_move, Z_HEAD, !!current_block->steps[Z_HEAD]);
1571 1638
 
1572 1639
       // Initialize the trapezoid generator from the current block.
1573 1640
       #if ENABLED(LIN_ADVANCE)

+ 6
- 7
Marlin/src/module/stepper.h Ver fichero

@@ -75,10 +75,10 @@ class Stepper {
75 75
 
76 76
   private:
77 77
 
78
-    static uint8_t last_direction_bits,           // The next stepping-bits to be output
79
-                   last_movement_extruder;        // Last movement extruder, as computed when the last movement was fetched from planner
80
-    static bool abort_current_block,              // Signals to the stepper that current block should be aborted
81
-                last_movement_non_null[NUM_AXIS]; // Last Movement in the given direction is not null, as computed when the last movement was fetched from planner
78
+    static uint8_t last_direction_bits,     // The next stepping-bits to be output
79
+                   last_movement_extruder,  // Last movement extruder, as computed when the last movement was fetched from planner
80
+                   axis_did_move;           // Last Movement in the given direction is not null, as computed when the last movement was fetched from planner
81
+    static bool abort_current_block;        // Signals to the stepper that current block should be aborted
82 82
 
83 83
     #if ENABLED(X_DUAL_ENDSTOPS)
84 84
       static bool locked_x_motor, locked_x2_motor;
@@ -198,7 +198,7 @@ class Stepper {
198 198
     FORCE_INLINE static bool motor_direction(const AxisEnum axis) { return TEST(last_direction_bits, axis); }
199 199
 
200 200
     // The last movement direction was not null on the specified axis. Note that motor direction is not necessarily the same.
201
-    FORCE_INLINE static bool movement_non_null(const AxisEnum axis) { return last_movement_non_null[axis]; }
201
+    FORCE_INLINE static bool axis_is_moving(const AxisEnum axis) { return TEST(axis_did_move, axis); }
202 202
 
203 203
     // The extruder associated to the last movement
204 204
     FORCE_INLINE static uint8_t movement_extruder() { return last_movement_extruder; }
@@ -326,8 +326,7 @@ class Stepper {
326 326
         }
327 327
         if (timer < 100) { // (20kHz - this should never happen)
328 328
           timer = 100;
329
-          SERIAL_ECHOPGM(MSG_STEPPER_TOO_HIGH);
330
-          SERIAL_ECHOLN(step_rate);
329
+          SERIAL_ECHOLNPAIR(MSG_STEPPER_TOO_HIGH, step_rate);
331 330
         }
332 331
       #endif
333 332
 

Loading…
Cancelar
Guardar