ソースを参照

Split first move to planner for better chaining

Scott Lahteine 6年前
コミット
4b612f590c
2個のファイルの変更112行の追加57行の削除
  1. 100
    56
      Marlin/src/module/planner.cpp
  2. 12
    1
      Marlin/src/module/planner.h

+ 100
- 56
Marlin/src/module/planner.cpp ファイルの表示

@@ -580,6 +580,7 @@ void Planner::calculate_volumetric_multipliers() {
580 580
 #if PLANNER_LEVELING
581 581
   /**
582 582
    * rx, ry, rz - Cartesian positions in mm
583
+   *              Leveled XYZ on completion
583 584
    */
584 585
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
585 586
 
@@ -622,7 +623,7 @@ void Planner::calculate_volumetric_multipliers() {
622 623
       #endif
623 624
 
624 625
       rz += (
625
-        #if ENABLED(AUTO_BED_LEVELING_UBL)
626
+        #if ENABLED(AUTO_BED_LEVELING_UBL) // UBL_DELTA
626 627
           ubl.get_z_correction(rx, ry) * fade_scaling_factor
627 628
         #elif ENABLED(MESH_BED_LEVELING)
628 629
           mbl.get_z(rx, ry
@@ -698,69 +699,35 @@ void Planner::calculate_volumetric_multipliers() {
698 699
 #endif // PLANNER_LEVELING
699 700
 
700 701
 /**
701
- * Planner::_buffer_line
702
- *
703
- * Add a new linear movement to the buffer in axis units.
702
+ * Planner::_buffer_steps
704 703
  *
705
- * Leveling and kinematics should be applied ahead of calling this.
704
+ * Add a new linear movement to the buffer (in terms of steps).
706 705
  *
707
- *  a,b,c,e   - target positions in mm and/or degrees
708
- *  fr_mm_s   - (target) speed of the move
709
- *  extruder  - target extruder
706
+ *  target      - target position in steps units
707
+ *  fr_mm_s     - (target) speed of the move
708
+ *  extruder    - target extruder
710 709
  */
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
710
+void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const uint8_t extruder) {
730 711
 
731 712
   const int32_t da = target[X_AXIS] - position[X_AXIS],
732 713
                 db = target[Y_AXIS] - position[Y_AXIS],
733 714
                 dc = target[Z_AXIS] - position[Z_AXIS];
734 715
 
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);
716
+  int32_t de = target[E_AXIS] - position[E_AXIS];
717
+
718
+  /* <-- add a slash to enable
719
+    SERIAL_ECHOPAIR("  _buffer_steps FR:", fr_mm_s);
720
+    SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
744 721
     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();
722
+    SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
723
+    SERIAL_ECHOPAIR(" (", db);
724
+    SERIAL_ECHOPAIR(" steps) C:", target[C_AXIS]);
725
+    SERIAL_ECHOPAIR(" (", dc);
726
+    SERIAL_ECHOPAIR(" steps) E:", target[E_AXIS]);
727
+    SERIAL_ECHOPAIR(" (", de);
728
+    SERIAL_ECHOLNPGM(" steps)");
756 729
   //*/
757 730
 
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 731
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
765 732
     if (de) {
766 733
       #if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -1067,6 +1034,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1067 1034
     // Segment time im micro seconds
1068 1035
     uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
1069 1036
   #endif
1037
+
1070 1038
   #if ENABLED(SLOWDOWN)
1071 1039
     if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1072 1040
       if (segment_time_us < min_segment_time_us) {
@@ -1314,12 +1282,12 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1314 1282
     // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting.
1315 1283
     vmax_junction = min(block->nominal_speed, previous_nominal_speed);
1316 1284
 
1317
-    const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
1318
-
1319 1285
     // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
1320 1286
     float v_factor = 1;
1321 1287
     limited = 0;
1288
+
1322 1289
     // Now limit the jerk in all axes.
1290
+    const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
1323 1291
     LOOP_XYZE(axis) {
1324 1292
       // Limit an axis. We have to differentiate: coasting, reversal of an axis, full stop.
1325 1293
       float v_exit = previous_speed[axis] * smaller_speed_factor,
@@ -1414,13 +1382,89 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1414 1382
   block_buffer_head = next_buffer_head;
1415 1383
 
1416 1384
   // Update the position (only when a move was queued)
1385
+  static_assert(COUNT(target) > 1, "array as function parameter should be declared as reference and with count");
1417 1386
   COPY(position, target);
1418 1387
 
1419 1388
   recalculate();
1420 1389
 
1390
+} // _buffer_steps()
1391
+
1392
+/**
1393
+ * Planner::_buffer_line
1394
+ *
1395
+ * Add a new linear movement to the buffer in axis units.
1396
+ *
1397
+ * Leveling and kinematics should be applied ahead of calling this.
1398
+ *
1399
+ *  a,b,c,e   - target positions in mm and/or degrees
1400
+ *  fr_mm_s   - (target) speed of the move
1401
+ *  extruder  - target extruder
1402
+ */
1403
+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) {
1404
+  // When changing extruders recalculate steps corresponding to the E position
1405
+  #if ENABLED(DISTINCT_E_FACTORS)
1406
+    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
1407
+      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
1408
+      last_extruder = extruder;
1409
+    }
1410
+  #endif
1411
+
1412
+  // The target position of the tool in absolute steps
1413
+  // Calculate target position in absolute steps
1414
+  const int32_t target[XYZE] = {
1415
+    LROUND(a * axis_steps_per_mm[X_AXIS]),
1416
+    LROUND(b * axis_steps_per_mm[Y_AXIS]),
1417
+    LROUND(c * axis_steps_per_mm[Z_AXIS]),
1418
+    LROUND(e * axis_steps_per_mm[E_AXIS_N])
1419
+  };
1420
+
1421
+  /* <-- add a slash to enable
1422
+    SERIAL_ECHOPAIR("  _buffer_line FR:", fr_mm_s);
1423
+    #if IS_KINEMATIC
1424
+      SERIAL_ECHOPAIR(" A:", a);
1425
+      SERIAL_ECHOPAIR(" (", position[A_AXIS]);
1426
+      SERIAL_ECHOPAIR("->", target[A_AXIS]);
1427
+      SERIAL_ECHOPAIR(") B:", b);
1428
+    #else
1429
+      SERIAL_ECHOPAIR(" X:", a);
1430
+      SERIAL_ECHOPAIR(" (", position[X_AXIS]);
1431
+      SERIAL_ECHOPAIR("->", target[X_AXIS]);
1432
+      SERIAL_ECHOPAIR(") Y:", b);
1433
+    #endif
1434
+    SERIAL_ECHOPAIR(" (", position[Y_AXIS]);
1435
+    SERIAL_ECHOPAIR("->", target[Y_AXIS]);
1436
+    #if ENABLED(DELTA)
1437
+      SERIAL_ECHOPAIR(") C:", c);
1438
+    #else
1439
+      SERIAL_ECHOPAIR(") Z:", c);
1440
+    #endif
1441
+    SERIAL_ECHOPAIR(" (", position[Z_AXIS]);
1442
+    SERIAL_ECHOPAIR("->", target[Z_AXIS]);
1443
+    SERIAL_ECHOPAIR(") E:", e);
1444
+    SERIAL_ECHOPAIR(" (", position[E_AXIS]);
1445
+    SERIAL_ECHOPAIR("->", target[E_AXIS]);
1446
+    SERIAL_ECHOLNPGM(")");
1447
+  //*/
1448
+
1449
+  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1450
+  if (DEBUGGING(DRYRUN))
1451
+    position[E_AXIS] = target[E_AXIS];
1452
+
1453
+  // Always split the first move into one longer and one shorter move
1454
+  if (!blocks_queued()) {
1455
+    #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1456
+    const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1457
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
1458
+    _buffer_steps(between, fr_mm_s, extruder);
1459
+    _buffer_steps(target, fr_mm_s, extruder);
1460
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
1461
+  }
1462
+  else
1463
+    _buffer_steps(target, fr_mm_s, extruder);
1464
+
1421 1465
   stepper.wake_up();
1422 1466
 
1423
-} // buffer_line()
1467
+} // _buffer_line()
1424 1468
 
1425 1469
 /**
1426 1470
  * Directly set the planner XYZ position (and stepper positions)

+ 12
- 1
Marlin/src/module/planner.h ファイルの表示

@@ -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
 

読み込み中…
キャンセル
保存