Ver código fonte

Split first move to planner for better chaining

Scott Lahteine 7 anos atrás
pai
commit
000818f5e4
2 arquivos alterados com 112 adições e 58 exclusões
  1. 96
    53
      Marlin/planner.cpp
  2. 16
    5
      Marlin/planner.h

+ 96
- 53
Marlin/planner.cpp Ver arquivo

@@ -688,69 +688,35 @@ void Planner::calculate_volumetric_multipliers() {
688 688
 #endif // PLANNER_LEVELING
689 689
 
690 690
 /**
691
- * Planner::_buffer_line
691
+ * Planner::_buffer_steps
692 692
  *
693
- * Add a new linear movement to the buffer in axis units.
693
+ * Add a new linear movement to the buffer (in terms of steps).
694 694
  *
695
- * Leveling and kinematics should be applied ahead of calling this.
696
- *
697
- *  a,b,c,e   - target positions in mm and/or degrees
698
- *  fr_mm_s   - (target) speed of the move
699
- *  extruder  - target extruder
695
+ *  target      - target position in steps units
696
+ *  fr_mm_s     - (target) speed of the move
697
+ *  extruder    - target extruder
700 698
  */
701
-void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
702
-
703
-  // The target position of the tool in absolute steps
704
-  // Calculate target position in absolute steps
705
-  //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
706
-  const long target[XYZE] = {
707
-    LROUND(a * axis_steps_per_mm[X_AXIS]),
708
-    LROUND(b * axis_steps_per_mm[Y_AXIS]),
709
-    LROUND(c * axis_steps_per_mm[Z_AXIS]),
710
-    LROUND(e * axis_steps_per_mm[E_AXIS_N])
711
-  };
712
-
713
-  // When changing extruders recalculate steps corresponding to the E position
714
-  #if ENABLED(DISTINCT_E_FACTORS)
715
-    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
716
-      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
717
-      last_extruder = extruder;
718
-    }
719
-  #endif
699
+void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const uint8_t extruder) {
720 700
 
721 701
   const int32_t da = target[X_AXIS] - position[X_AXIS],
722 702
                 db = target[Y_AXIS] - position[Y_AXIS],
723 703
                 dc = target[Z_AXIS] - position[Z_AXIS];
724 704
 
725
-  /*
726
-  SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
727
-  SERIAL_CHAR(' ');
728
-  #if IS_KINEMATIC
729
-    SERIAL_ECHOPAIR("A:", a);
730
-    SERIAL_ECHOPAIR(" (", da);
731
-    SERIAL_ECHOPAIR(") B:", b);
732
-  #else
733
-    SERIAL_ECHOPAIR("X:", a);
705
+  int32_t de = target[E_AXIS] - position[E_AXIS];
706
+
707
+  /* <-- add a slash to enable
708
+    SERIAL_ECHOPAIR("  _buffer_steps FR:", fr_mm_s);
709
+    SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
734 710
     SERIAL_ECHOPAIR(" (", da);
735
-    SERIAL_ECHOPAIR(") Y:", b);
736
-  #endif
737
-  SERIAL_ECHOPAIR(" (", db);
738
-  #if ENABLED(DELTA)
739
-    SERIAL_ECHOPAIR(") C:", c);
740
-  #else
741
-    SERIAL_ECHOPAIR(") Z:", c);
742
-  #endif
743
-  SERIAL_ECHOPAIR(" (", dc);
744
-  SERIAL_CHAR(')');
745
-  SERIAL_EOL();
711
+    SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
712
+    SERIAL_ECHOPAIR(" (", db);
713
+    SERIAL_ECHOPAIR(" steps) C:", target[C_AXIS]);
714
+    SERIAL_ECHOPAIR(" (", dc);
715
+    SERIAL_ECHOPAIR(" steps) E:", target[E_AXIS]);
716
+    SERIAL_ECHOPAIR(" (", de);
717
+    SERIAL_ECHOLNPGM(" steps)");
746 718
   //*/
747 719
 
748
-  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
749
-  if (DEBUGGING(DRYRUN))
750
-    position[E_AXIS] = target[E_AXIS];
751
-
752
-  int32_t de = target[E_AXIS] - position[E_AXIS];
753
-
754 720
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
755 721
     if (de) {
756 722
       #if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -1057,6 +1023,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1057 1023
     // Segment time im micro seconds
1058 1024
     uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
1059 1025
   #endif
1026
+
1060 1027
   #if ENABLED(SLOWDOWN)
1061 1028
     if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1062 1029
       if (segment_time_us < min_segment_time_us) {
@@ -1404,13 +1371,89 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1404 1371
   block_buffer_head = next_buffer_head;
1405 1372
 
1406 1373
   // Update the position (only when a move was queued)
1374
+  static_assert(COUNT(target) > 1, "Parameter to _buffer_steps must be (&target)[XYZE]!");
1407 1375
   COPY(position, target);
1408 1376
 
1409 1377
   recalculate();
1410 1378
 
1379
+} // _buffer_steps()
1380
+
1381
+/**
1382
+ * Planner::_buffer_line
1383
+ *
1384
+ * Add a new linear movement to the buffer in axis units.
1385
+ *
1386
+ * Leveling and kinematics should be applied ahead of calling this.
1387
+ *
1388
+ *  a,b,c,e   - target positions in mm and/or degrees
1389
+ *  fr_mm_s   - (target) speed of the move
1390
+ *  extruder  - target extruder
1391
+ */
1392
+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) {
1393
+  // When changing extruders recalculate steps corresponding to the E position
1394
+  #if ENABLED(DISTINCT_E_FACTORS)
1395
+    if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
1396
+      position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
1397
+      last_extruder = extruder;
1398
+    }
1399
+  #endif
1400
+
1401
+  // The target position of the tool in absolute steps
1402
+  // Calculate target position in absolute steps
1403
+  const int32_t target[XYZE] = {
1404
+    LROUND(a * axis_steps_per_mm[X_AXIS]),
1405
+    LROUND(b * axis_steps_per_mm[Y_AXIS]),
1406
+    LROUND(c * axis_steps_per_mm[Z_AXIS]),
1407
+    LROUND(e * axis_steps_per_mm[E_AXIS_N])
1408
+  };
1409
+
1410
+  /* <-- add a slash to enable
1411
+    SERIAL_ECHOPAIR("  _buffer_line FR:", fr_mm_s);
1412
+    #if IS_KINEMATIC
1413
+      SERIAL_ECHOPAIR(" A:", a);
1414
+      SERIAL_ECHOPAIR(" (", position[A_AXIS]);
1415
+      SERIAL_ECHOPAIR("->", target[A_AXIS]);
1416
+      SERIAL_ECHOPAIR(") B:", b);
1417
+    #else
1418
+      SERIAL_ECHOPAIR(" X:", a);
1419
+      SERIAL_ECHOPAIR(" (", position[X_AXIS]);
1420
+      SERIAL_ECHOPAIR("->", target[X_AXIS]);
1421
+      SERIAL_ECHOPAIR(") Y:", b);
1422
+    #endif
1423
+    SERIAL_ECHOPAIR(" (", position[Y_AXIS]);
1424
+    SERIAL_ECHOPAIR("->", target[Y_AXIS]);
1425
+    #if ENABLED(DELTA)
1426
+      SERIAL_ECHOPAIR(") C:", c);
1427
+    #else
1428
+      SERIAL_ECHOPAIR(") Z:", c);
1429
+    #endif
1430
+    SERIAL_ECHOPAIR(" (", position[Z_AXIS]);
1431
+    SERIAL_ECHOPAIR("->", target[Z_AXIS]);
1432
+    SERIAL_ECHOPAIR(") E:", e);
1433
+    SERIAL_ECHOPAIR(" (", position[E_AXIS]);
1434
+    SERIAL_ECHOPAIR("->", target[E_AXIS]);
1435
+    SERIAL_ECHOLNPGM(")");
1436
+  //*/
1437
+
1438
+  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1439
+  if (DEBUGGING(DRYRUN))
1440
+    position[E_AXIS] = target[E_AXIS];
1441
+
1442
+  // Always split the first move into one longer and one shorter move
1443
+  if (!blocks_queued()) {
1444
+    #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1445
+    const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1446
+    DISABLE_STEPPER_DRIVER_INTERRUPT();
1447
+    _buffer_steps(between, fr_mm_s, extruder);
1448
+    _buffer_steps(target, fr_mm_s, extruder);
1449
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
1450
+  }
1451
+  else
1452
+    _buffer_steps(target, fr_mm_s, extruder);
1453
+
1411 1454
   stepper.wake_up();
1412 1455
 
1413
-} // buffer_line()
1456
+} // _buffer_line()
1414 1457
 
1415 1458
 /**
1416 1459
  * Directly set the planner XYZ position (and stepper positions)

+ 16
- 5
Marlin/planner.h Ver arquivo

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

Carregando…
Cancelar
Salvar