Browse Source

Split first move to planner for better chaining

Address #8573, #8595
Scott Lahteine 6 years ago
parent
commit
3a97de52ef
2 changed files with 102 additions and 54 deletions
  1. 89
    52
      Marlin/src/module/planner.cpp
  2. 13
    2
      Marlin/src/module/planner.h

+ 89
- 52
Marlin/src/module/planner.cpp View File

@@ -698,69 +698,35 @@ void Planner::calculate_volumetric_multipliers() {
698 698
 #endif // PLANNER_LEVELING
699 699
 
700 700
 /**
701
- * Planner::_buffer_line
701
+ * Planner::_buffer_steps
702 702
  *
703
- * Add a new linear movement to the buffer in axis units.
703
+ * Add a new linear movement to the buffer (in terms of steps).
704 704
  *
705
- * Leveling and kinematics should be applied ahead of calling this.
706
- *
707
- *  a,b,c,e   - target positions in mm and/or degrees
705
+ *  target    - target position in steps units
708 706
  *  fr_mm_s   - (target) speed of the move
709 707
  *  extruder  - target extruder
710 708
  */
711
-void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
712
-
713
-  // The target position of the tool in absolute steps
714
-  // Calculate target position in absolute steps
715
-  //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
716
-  const long target[XYZE] = {
717
-    LROUND(a * axis_steps_per_mm[X_AXIS]),
718
-    LROUND(b * axis_steps_per_mm[Y_AXIS]),
719
-    LROUND(c * axis_steps_per_mm[Z_AXIS]),
720
-    LROUND(e * axis_steps_per_mm[E_AXIS_N])
721
-  };
722
-
723
-  // When changing extruders recalculate steps corresponding to the E position
724
-  #if ENABLED(DISTINCT_E_FACTORS)
725
-    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
726
-      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
727
-      last_extruder = extruder;
728
-    }
729
-  #endif
709
+void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder) {
730 710
 
731 711
   const int32_t da = target[X_AXIS] - position[X_AXIS],
732 712
                 db = target[Y_AXIS] - position[Y_AXIS],
733 713
                 dc = target[Z_AXIS] - position[Z_AXIS];
734 714
 
735
-  /*
736
-  SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
737
-  SERIAL_CHAR(' ');
738
-  #if IS_KINEMATIC
739
-    SERIAL_ECHOPAIR("A:", a);
740
-    SERIAL_ECHOPAIR(" (", da);
741
-    SERIAL_ECHOPAIR(") B:", b);
742
-  #else
743
-    SERIAL_ECHOPAIR("X:", a);
715
+  int32_t de = target[E_AXIS] - position[E_AXIS];
716
+
717
+  /* <-- add a slash to enable
718
+    SERIAL_ECHOPAIR("  _buffer_steps FR:", fr_mm_s);
719
+    SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
744 720
     SERIAL_ECHOPAIR(" (", da);
745
-    SERIAL_ECHOPAIR(") Y:", b);
746
-  #endif
747
-  SERIAL_ECHOPAIR(" (", db);
748
-  #if ENABLED(DELTA)
749
-    SERIAL_ECHOPAIR(") C:", c);
750
-  #else
751
-    SERIAL_ECHOPAIR(") Z:", c);
752
-  #endif
753
-  SERIAL_ECHOPAIR(" (", dc);
754
-  SERIAL_CHAR(')');
755
-  SERIAL_EOL();
721
+    SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
722
+    SERIAL_ECHOPAIR(" (", db);
723
+    SERIAL_ECHOLNPGM(" steps) C:", target[C_AXIS]);
724
+    SERIAL_ECHOPAIR(" (", dc);
725
+    SERIAL_ECHOLNPGM(" steps) E:", target[E_AXIS]);
726
+    SERIAL_ECHOPAIR(" (", de);
727
+    SERIAL_ECHOLNPGM(" steps)");
756 728
   //*/
757 729
 
758
-  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
759
-  if (DEBUGGING(DRYRUN))
760
-    position[E_AXIS] = target[E_AXIS];
761
-
762
-  int32_t de = target[E_AXIS] - position[E_AXIS];
763
-
764 730
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
765 731
     if (de) {
766 732
       #if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -1067,6 +1033,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1067 1033
     // Segment time im micro seconds
1068 1034
     uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
1069 1035
   #endif
1036
+
1070 1037
   #if ENABLED(SLOWDOWN)
1071 1038
     if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1072 1039
       if (segment_time_us < min_segment_time_us) {
@@ -1305,7 +1272,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1305 1272
     }
1306 1273
   }
1307 1274
 
1308
-  if (moves_queued > 1 && !UNEAR_ZERO(previous_nominal_speed)) {
1275
+  if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1309 1276
     // Estimate a maximum velocity allowed at a joint of two successive segments.
1310 1277
     // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
1311 1278
     // then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
@@ -1417,9 +1384,79 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1417 1384
 
1418 1385
   recalculate();
1419 1386
 
1387
+} // _buffer_steps()
1388
+
1389
+/**
1390
+ * Planner::_buffer_line
1391
+ *
1392
+ * Add a new linear movement to the buffer in axis units.
1393
+ *
1394
+ * Leveling and kinematics should be applied ahead of calling this.
1395
+ *
1396
+ *  a,b,c,e   - target positions in mm and/or degrees
1397
+ *  fr_mm_s   - (target) speed of the move
1398
+ *  extruder  - target extruder
1399
+ */
1400
+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) {
1401
+  // When changing extruders recalculate steps corresponding to the E position
1402
+  #if ENABLED(DISTINCT_E_FACTORS)
1403
+    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
1404
+      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
1405
+      last_extruder = extruder;
1406
+    }
1407
+  #endif
1408
+
1409
+  // The target position of the tool in absolute steps
1410
+  // Calculate target position in absolute steps
1411
+  const int32_t target[XYZE] = {
1412
+    LROUND(a * axis_steps_per_mm[X_AXIS]),
1413
+    LROUND(b * axis_steps_per_mm[Y_AXIS]),
1414
+    LROUND(c * axis_steps_per_mm[Z_AXIS]),
1415
+    LROUND(e * axis_steps_per_mm[E_AXIS_N])
1416
+  };
1417
+
1418
+  /* <-- add a slash to enable
1419
+    SERIAL_ECHOPAIR("  _buffer_line FR:", fr_mm_s);
1420
+    #if IS_KINEMATIC
1421
+      SERIAL_ECHOPAIR(" A:", a);
1422
+      SERIAL_ECHOPAIR(" (", target[A_AXIS]);
1423
+      SERIAL_ECHOPAIR(" steps) B:", b);
1424
+    #else
1425
+      SERIAL_ECHOPAIR(" X:", a);
1426
+      SERIAL_ECHOPAIR(" (", target[X_AXIS]);
1427
+      SERIAL_ECHOPAIR(" steps) Y:", b);
1428
+    #endif
1429
+    SERIAL_ECHOPAIR(" (", target[Y_AXIS]);
1430
+    #if ENABLED(DELTA)
1431
+      SERIAL_ECHOPAIR(" steps) C:", c);
1432
+    #else
1433
+      SERIAL_ECHOPAIR(" steps) Z:", c);
1434
+    #endif
1435
+    SERIAL_ECHOPAIR(" (", target[Z_AXIS]);
1436
+    SERIAL_ECHOPAIR(" steps) E:", e);
1437
+    SERIAL_ECHOPAIR(" (", target[E_AXIS]);
1438
+    SERIAL_ECHOLNPGM(" steps)");
1439
+  //*/
1440
+
1441
+  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1442
+  if (DEBUGGING(DRYRUN))
1443
+    position[E_AXIS] = target[E_AXIS];
1444
+
1445
+  // Always split the first move in two so it can chain
1446
+  if (!blocks_queued()) {
1447
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
1448
+    #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1449
+    const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1450
+    _buffer_steps(between, fr_mm_s, extruder);
1451
+    _buffer_steps(target, fr_mm_s, extruder);
1452
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
1453
+  }
1454
+  else
1455
+    _buffer_steps(target, fr_mm_s, extruder);
1456
+
1420 1457
   stepper.wake_up();
1421 1458
 
1422
-} // buffer_line()
1459
+} // _buffer_line()
1423 1460
 
1424 1461
 /**
1425 1462
  * Directly set the planner XYZ position (and stepper positions)

+ 13
- 2
Marlin/src/module/planner.h View File

@@ -144,7 +144,7 @@ class Planner {
144 144
       static uint8_t last_extruder;             // Respond to extruder change
145 145
     #endif
146 146
 
147
-    static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
147
+    static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
148 148
 
149 149
     static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
150 150
                  filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
@@ -353,6 +353,17 @@ class Planner {
353 353
     #endif
354 354
 
355 355
     /**
356
+     * Planner::_buffer_steps
357
+     *
358
+     * Add a new linear movement to the buffer (in terms of steps).
359
+     *
360
+     *  target    - target position in steps units
361
+     *  fr_mm_s   - (target) speed of the move
362
+     *  extruder  - target extruder
363
+     */
364
+    static void _buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder);
365
+
366
+    /**
356 367
      * Planner::_buffer_line
357 368
      *
358 369
      * Add a new linear movement to the buffer in axis units.
@@ -363,7 +374,7 @@ class Planner {
363 374
      *  fr_mm_s   - (target) speed of the move
364 375
      *  extruder  - target extruder
365 376
      */
366
-    static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
377
+    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);
367 378
 
368 379
     static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
369 380
 

Loading…
Cancel
Save