Pārlūkot izejas kodu

Split first move to planner for better chaining

Address #8573, #8595
Scott Lahteine 6 gadus atpakaļ
vecāks
revīzija
1d0ee83e18
4 mainītis faili ar 110 papildinājumiem un 63 dzēšanām
  1. 91
    55
      Marlin/planner.cpp
  2. 16
    5
      Marlin/planner.h
  3. 0
    3
      Marlin/stepper.cpp
  4. 3
    0
      Marlin/stepper.h

+ 91
- 55
Marlin/planner.cpp Parādīt failu

@@ -687,69 +687,35 @@ void Planner::calculate_volumetric_multipliers() {
687 687
 #endif // PLANNER_LEVELING
688 688
 
689 689
 /**
690
- * Planner::_buffer_line
691
- *
692
- * Add a new linear movement to the buffer.
690
+ * Planner::_buffer_steps
693 691
  *
694
- * Leveling and kinematics should be applied ahead of calling this.
692
+ * Add a new linear movement to the buffer (in terms of steps).
695 693
  *
696
- *  a,b,c,e     - target positions in mm or degrees
697
- *  fr_mm_s     - (target) speed of the move
698
- *  extruder    - target extruder
694
+ *  target    - target position in steps units
695
+ *  fr_mm_s   - (target) speed of the move
696
+ *  extruder  - target extruder
699 697
  */
700
-void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
701
-
702
-  // The target position of the tool in absolute steps
703
-  // Calculate target position in absolute steps
704
-  //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
705
-  const long target[XYZE] = {
706
-    LROUND(a * axis_steps_per_mm[X_AXIS]),
707
-    LROUND(b * axis_steps_per_mm[Y_AXIS]),
708
-    LROUND(c * axis_steps_per_mm[Z_AXIS]),
709
-    LROUND(e * axis_steps_per_mm[E_AXIS_N])
710
-  };
711
-
712
-  // When changing extruders recalculate steps corresponding to the E position
713
-  #if ENABLED(DISTINCT_E_FACTORS)
714
-    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
715
-      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
716
-      last_extruder = extruder;
717
-    }
718
-  #endif
698
+void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder) {
719 699
 
720 700
   const int32_t da = target[X_AXIS] - position[X_AXIS],
721 701
                 db = target[Y_AXIS] - position[Y_AXIS],
722 702
                 dc = target[Z_AXIS] - position[Z_AXIS];
723 703
 
724
-  /*
725
-  SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
726
-  SERIAL_CHAR(' ');
727
-  #if IS_KINEMATIC
728
-    SERIAL_ECHOPAIR("A:", a);
729
-    SERIAL_ECHOPAIR(" (", da);
730
-    SERIAL_ECHOPAIR(") B:", b);
731
-  #else
732
-    SERIAL_ECHOPAIR("X:", a);
704
+  int32_t de = target[E_AXIS] - position[E_AXIS];
705
+
706
+  /* <-- add a slash to enable
707
+    SERIAL_ECHOPAIR("  _buffer_steps FR:", fr_mm_s);
708
+    SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
733 709
     SERIAL_ECHOPAIR(" (", da);
734
-    SERIAL_ECHOPAIR(") Y:", b);
735
-  #endif
736
-  SERIAL_ECHOPAIR(" (", db);
737
-  #if ENABLED(DELTA)
738
-    SERIAL_ECHOPAIR(") C:", c);
739
-  #else
740
-    SERIAL_ECHOPAIR(") Z:", c);
741
-  #endif
742
-  SERIAL_ECHOPAIR(" (", dc);
743
-  SERIAL_CHAR(')');
744
-  SERIAL_EOL();
710
+    SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
711
+    SERIAL_ECHOPAIR(" (", db);
712
+    SERIAL_ECHOLNPGM(" steps) C:", target[C_AXIS]);
713
+    SERIAL_ECHOPAIR(" (", dc);
714
+    SERIAL_ECHOLNPGM(" steps) E:", target[E_AXIS]);
715
+    SERIAL_ECHOPAIR(" (", de);
716
+    SERIAL_ECHOLNPGM(" steps)");
745 717
   //*/
746 718
 
747
-  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
748
-  if (DEBUGGING(DRYRUN))
749
-    position[E_AXIS] = target[E_AXIS];
750
-
751
-  int32_t de = target[E_AXIS] - position[E_AXIS];
752
-
753 719
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
754 720
     if (de) {
755 721
       #if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -1056,6 +1022,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1056 1022
     // Segment time im micro seconds
1057 1023
     uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
1058 1024
   #endif
1025
+
1059 1026
   #if ENABLED(SLOWDOWN)
1060 1027
     if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1061 1028
       if (segment_time_us < min_segment_time_us) {
@@ -1294,7 +1261,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1294 1261
     }
1295 1262
   }
1296 1263
 
1297
-  if (moves_queued > 1 && !UNEAR_ZERO(previous_nominal_speed)) {
1264
+  if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1298 1265
     // Estimate a maximum velocity allowed at a joint of two successive segments.
1299 1266
     // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
1300 1267
     // then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
@@ -1368,7 +1335,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1368 1335
   previous_safe_speed = safe_speed;
1369 1336
 
1370 1337
   #if ENABLED(LIN_ADVANCE)
1371
-
1372 1338
     /**
1373 1339
      *
1374 1340
      * Use LIN_ADVANCE for blocks if all these are true:
@@ -1407,9 +1373,79 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1407 1373
 
1408 1374
   recalculate();
1409 1375
 
1376
+} // _buffer_steps()
1377
+
1378
+/**
1379
+ * Planner::_buffer_line
1380
+ *
1381
+ * Add a new linear movement to the buffer in axis units.
1382
+ *
1383
+ * Leveling and kinematics should be applied ahead of calling this.
1384
+ *
1385
+ *  a,b,c,e   - target positions in mm and/or degrees
1386
+ *  fr_mm_s   - (target) speed of the move
1387
+ *  extruder  - target extruder
1388
+ */
1389
+void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder) {
1390
+  // When changing extruders recalculate steps corresponding to the E position
1391
+  #if ENABLED(DISTINCT_E_FACTORS)
1392
+    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
1393
+      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
1394
+      last_extruder = extruder;
1395
+    }
1396
+  #endif
1397
+
1398
+  // The target position of the tool in absolute steps
1399
+  // Calculate target position in absolute steps
1400
+  const int32_t target[XYZE] = {
1401
+    LROUND(a * axis_steps_per_mm[X_AXIS]),
1402
+    LROUND(b * axis_steps_per_mm[Y_AXIS]),
1403
+    LROUND(c * axis_steps_per_mm[Z_AXIS]),
1404
+    LROUND(e * axis_steps_per_mm[E_AXIS_N])
1405
+  };
1406
+
1407
+  /* <-- add a slash to enable
1408
+    SERIAL_ECHOPAIR("  _buffer_line FR:", fr_mm_s);
1409
+    #if IS_KINEMATIC
1410
+      SERIAL_ECHOPAIR(" A:", a);
1411
+      SERIAL_ECHOPAIR(" (", target[A_AXIS]);
1412
+      SERIAL_ECHOPAIR(" steps) B:", b);
1413
+    #else
1414
+      SERIAL_ECHOPAIR(" X:", a);
1415
+      SERIAL_ECHOPAIR(" (", target[X_AXIS]);
1416
+      SERIAL_ECHOPAIR(" steps) Y:", b);
1417
+    #endif
1418
+    SERIAL_ECHOPAIR(" (", target[Y_AXIS]);
1419
+    #if ENABLED(DELTA)
1420
+      SERIAL_ECHOPAIR(" steps) C:", c);
1421
+    #else
1422
+      SERIAL_ECHOPAIR(" steps) Z:", c);
1423
+    #endif
1424
+    SERIAL_ECHOPAIR(" (", target[Z_AXIS]);
1425
+    SERIAL_ECHOPAIR(" steps) E:", e);
1426
+    SERIAL_ECHOPAIR(" (", target[E_AXIS]);
1427
+    SERIAL_ECHOLNPGM(" steps)");
1428
+  //*/
1429
+
1430
+  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1431
+  if (DEBUGGING(DRYRUN))
1432
+    position[E_AXIS] = target[E_AXIS];
1433
+
1434
+  // Always split the first move in two so it can chain
1435
+  if (!blocks_queued()) {
1436
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
1437
+    #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1438
+    const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1439
+    _buffer_steps(between, fr_mm_s, extruder);
1440
+    _buffer_steps(target, fr_mm_s, extruder);
1441
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
1442
+  }
1443
+  else
1444
+    _buffer_steps(target, fr_mm_s, extruder);
1445
+
1410 1446
   stepper.wake_up();
1411 1447
 
1412
-} // buffer_line()
1448
+} // _buffer_line()
1413 1449
 
1414 1450
 /**
1415 1451
  * Directly set the planner XYZ position (and stepper positions)

+ 16
- 5
Marlin/planner.h Parādīt failu

@@ -349,17 +349,28 @@ class Planner {
349 349
     #endif
350 350
 
351 351
     /**
352
+     * Planner::_buffer_steps
353
+     *
354
+     * Add a new linear movement to the buffer (in terms of steps).
355
+     *
356
+     *  target    - target position in steps units
357
+     *  fr_mm_s   - (target) speed of the move
358
+     *  extruder  - target extruder
359
+     */
360
+    static void _buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder);
361
+
362
+    /**
352 363
      * Planner::_buffer_line
353 364
      *
354
-     * Add a new direct linear movement to the buffer.
365
+     * Add a new linear movement to the buffer in axis units.
355 366
      *
356
-     * Leveling and kinematics should be applied ahead of this.
367
+     * Leveling and kinematics should be applied ahead of calling this.
357 368
      *
358
-     *  a,b,c,e   - target position in mm or degrees
359
-     *  fr_mm_s   - (target) speed of the move (mm/s)
369
+     *  a,b,c,e   - target positions in mm and/or degrees
370
+     *  fr_mm_s   - (target) speed of the move
360 371
      *  extruder  - target extruder
361 372
      */
362
-    static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
373
+    static void _buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder);
363 374
 
364 375
     static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
365 376
 

+ 0
- 3
Marlin/stepper.cpp Parādīt failu

@@ -286,9 +286,6 @@ volatile long Stepper::endstops_trigsteps[XYZ];
286 286
 
287 287
 // Some useful constants
288 288
 
289
-#define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
290
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
291
-
292 289
 /**
293 290
  *         __________________________
294 291
  *        /|                        |\     _________________         ^

+ 3
- 0
Marlin/stepper.h Parādīt failu

@@ -52,6 +52,9 @@
52 52
 class Stepper;
53 53
 extern Stepper stepper;
54 54
 
55
+#define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
56
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
57
+
55 58
 // intRes = intIn1 * intIn2 >> 16
56 59
 // uses:
57 60
 // r26 to store 0

Notiek ielāde…
Atcelt
Saglabāt