Browse Source

Merge pull request #8613 from thinkyhead/bf1_planner_parity

[1.1.x] Fix some planner bugs
Scott Lahteine 7 years ago
parent
commit
ab43113f73
No account linked to committer's email address
3 changed files with 87 additions and 162 deletions
  1. 2
    6
      Marlin/Marlin_main.cpp
  2. 75
    150
      Marlin/planner.cpp
  3. 10
    6
      Marlin/planner.h

+ 2
- 6
Marlin/Marlin_main.cpp View File

@@ -8714,12 +8714,8 @@ inline void gcode_M200() {
8714 8714
     // setting any extruder filament size disables volumetric on the assumption that
8715 8715
     // slicers either generate in extruder values as cubic mm or as as filament feeds
8716 8716
     // for all extruders
8717
-    if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) ) {
8718
-      planner.filament_size[target_extruder] = parser.value_linear_units();
8719
-      // make sure all extruders have some sane value for the filament size
8720
-      for (uint8_t i = 0; i < COUNT(planner.filament_size); i++)
8721
-        if (!planner.filament_size[i]) planner.filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
8722
-    }
8717
+    if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
8718
+      planner.set_filament_size(target_extruder, parser.value_linear_units());
8723 8719
   }
8724 8720
   planner.calculate_volumetric_multipliers();
8725 8721
 }

+ 75
- 150
Marlin/planner.cpp View File

@@ -153,8 +153,7 @@ float Planner::previous_speed[NUM_AXIS],
153 153
 
154 154
 #if ENABLED(LIN_ADVANCE)
155 155
   float Planner::extruder_advance_k, // Initialized by settings.load()
156
-        Planner::advance_ed_ratio,   // Initialized by settings.load()
157
-        Planner::position_float[NUM_AXIS] = { 0 };
156
+        Planner::advance_ed_ratio;   // Initialized by settings.load()
158 157
 #endif
159 158
 
160 159
 #if ENABLED(ULTRA_LCD)
@@ -170,9 +169,6 @@ Planner::Planner() { init(); }
170 169
 void Planner::init() {
171 170
   block_buffer_head = block_buffer_tail = 0;
172 171
   ZERO(position);
173
-  #if ENABLED(LIN_ADVANCE)
174
-    ZERO(position_float);
175
-  #endif
176 172
   ZERO(previous_speed);
177 173
   previous_nominal_speed = 0.0;
178 174
   #if ABL_PLANAR
@@ -554,34 +550,13 @@ void Planner::calculate_volumetric_multipliers() {
554 550
 
555 551
 #if PLANNER_LEVELING
556 552
   /**
557
-   * rx, ry, rz - cartesian position in mm
553
+   * rx, ry, rz - Cartesian positions in mm
558 554
    */
559 555
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
560 556
 
561 557
     if (!leveling_active) return;
562 558
 
563
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
564
-      const float fade_scaling_factor = fade_scaling_factor_for_z(rz);
565
-      if (!fade_scaling_factor) return;
566
-    #else
567
-      constexpr float fade_scaling_factor = 1.0;
568
-    #endif
569
-
570
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
571
-
572
-      rz += ubl.get_z_correction(rx, ry) * fade_scaling_factor;
573
-
574
-    #elif ENABLED(MESH_BED_LEVELING)
575
-
576
-      rz += mbl.get_z(rx, ry
577
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
578
-          , fade_scaling_factor
579
-        #endif
580
-      );
581
-
582
-    #elif ABL_PLANAR
583
-
584
-      UNUSED(fade_scaling_factor);
559
+    #if ABL_PLANAR
585 560
 
586 561
       float dx = rx - (X_TILT_FULCRUM),
587 562
             dy = ry - (Y_TILT_FULCRUM);
@@ -591,68 +566,43 @@ void Planner::calculate_volumetric_multipliers() {
591 566
       rx = dx + X_TILT_FULCRUM;
592 567
       ry = dy + Y_TILT_FULCRUM;
593 568
 
594
-    #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
595
-
596
-      float tmp[XYZ] = { rx, ry, 0 };
597
-      rz += bilinear_z_offset(tmp) * fade_scaling_factor;
598
-
599
-    #endif
600
-  }
601
-
602
-  void Planner::unapply_leveling(float raw[XYZ]) {
603
-
604
-    #if HAS_LEVELING
605
-      if (!leveling_active) return;
606
-    #endif
607
-
608
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
609
-      if (!leveling_active_at_z(raw[Z_AXIS])) return;
610
-    #endif
611
-
612
-    #if ENABLED(AUTO_BED_LEVELING_UBL)
613
-
614
-      const float z_physical = raw[Z_AXIS],
615
-                  z_correct = ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]),
616
-                  z_virtual = z_physical - z_correct;
617
-            float z_raw = z_virtual;
569
+    #else
618 570
 
619 571
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
572
+        const float fade_scaling_factor = fade_scaling_factor_for_z(rz);
573
+        if (!fade_scaling_factor) return;
574
+      #elif HAS_MESH
575
+        constexpr float fade_scaling_factor = 1.0;
576
+      #endif
620 577
 
621
-        // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
622
-        // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
623
-        //  then L=P-M(1-L/H)
624
-        //    so L=P-M+ML/H
625
-        //    so L-ML/H=P-M
626
-        //    so L(1-M/H)=P-M
627
-        //    so L=(P-M)/(1-M/H) for L<H
628
-
629
-        if (planner.z_fade_height) {
630
-          if (z_raw >= planner.z_fade_height)
631
-            z_raw = z_physical;
632
-          else
633
-            z_raw /= 1.0 - z_correct * planner.inverse_z_fade_height;
634
-        }
635
-
636
-      #endif // ENABLE_LEVELING_FADE_HEIGHT
637
-
638
-      raw[Z_AXIS] = z_raw;
578
+      #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
579
+        const float raw[XYZ] = { rx, ry, 0 };
580
+      #endif
639 581
 
640
-      return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
582
+      rz += (
583
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
584
+          ubl.get_z_correction(rx, ry) * fade_scaling_factor
585
+        #elif ENABLED(MESH_BED_LEVELING)
586
+          mbl.get_z(rx, ry
587
+            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
588
+              , fade_scaling_factor
589
+            #endif
590
+          )
591
+        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
592
+          bilinear_z_offset(raw) * fade_scaling_factor
593
+        #else
594
+          0
595
+        #endif
596
+      );
641 597
 
642 598
     #endif
599
+  }
643 600
 
644
-    #if ENABLED(MESH_BED_LEVELING)
601
+  void Planner::unapply_leveling(float raw[XYZ]) {
645 602
 
646
-      if (leveling_active) {
647
-        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
648
-          const float c = mbl.get_z(raw[X_AXIS], raw[Y_AXIS], 1.0);
649
-          raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS]) - c) / (z_fade_height - c);
650
-        #else
651
-          raw[Z_AXIS] -= mbl.get_z(raw[X_AXIS], raw[Y_AXIS]);
652
-        #endif
653
-      }
603
+    if (!leveling_active) return;
654 604
 
655
-    #elif ABL_PLANAR
605
+    #if ABL_PLANAR
656 606
 
657 607
       matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
658 608
 
@@ -664,15 +614,31 @@ void Planner::calculate_volumetric_multipliers() {
664 614
       raw[X_AXIS] = dx + X_TILT_FULCRUM;
665 615
       raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
666 616
 
667
-    #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
617
+    #else
668 618
 
669 619
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
670
-        const float c = bilinear_z_offset(raw);
671
-        raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS]) - c) / (z_fade_height - c);
672
-      #else
673
-        raw[Z_AXIS] -= bilinear_z_offset(raw);
620
+        const float fade_scaling_factor = fade_scaling_factor_for_z(raw[Z_AXIS]);
621
+        if (!fade_scaling_factor) return;
622
+      #elif HAS_MESH
623
+        constexpr float fade_scaling_factor = 1.0;
674 624
       #endif
675 625
 
626
+      raw[Z_AXIS] -= (
627
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
628
+          ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]) * fade_scaling_factor
629
+        #elif ENABLED(MESH_BED_LEVELING)
630
+          mbl.get_z(raw[X_AXIS], raw[Y_AXIS]
631
+            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
632
+              , fade_scaling_factor
633
+            #endif
634
+          )
635
+        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
636
+          bilinear_z_offset(raw) * fade_scaling_factor
637
+        #else
638
+          0
639
+        #endif
640
+      );
641
+
676 642
     #endif
677 643
   }
678 644
 
@@ -709,10 +675,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
709 675
     }
710 676
   #endif
711 677
 
712
-  #if ENABLED(LIN_ADVANCE)
713
-    const float mm_D_float = SQRT(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
714
-  #endif
715
-
716 678
   const long da = target[X_AXIS] - position[X_AXIS],
717 679
              db = target[Y_AXIS] - position[Y_AXIS],
718 680
              dc = target[Z_AXIS] - position[Z_AXIS];
@@ -741,29 +703,17 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
741 703
   //*/
742 704
 
743 705
   // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
744
-  if (DEBUGGING(DRYRUN)) {
706
+  if (DEBUGGING(DRYRUN))
745 707
     position[E_AXIS] = target[E_AXIS];
746
-    #if ENABLED(LIN_ADVANCE)
747
-      position_float[E_AXIS] = e;
748
-    #endif
749
-  }
750 708
 
751 709
   long de = target[E_AXIS] - position[E_AXIS];
752 710
 
753
-  #if ENABLED(LIN_ADVANCE)
754
-    float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
755
-  #endif
756
-
757 711
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
758 712
     if (de) {
759 713
       #if ENABLED(PREVENT_COLD_EXTRUSION)
760 714
         if (thermalManager.tooColdToExtrude(extruder)) {
761 715
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
762 716
           de = 0; // no difference
763
-          #if ENABLED(LIN_ADVANCE)
764
-            position_float[E_AXIS] = e;
765
-            de_float = 0;
766
-          #endif
767 717
           SERIAL_ECHO_START();
768 718
           SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
769 719
         }
@@ -772,10 +722,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
772 722
         if (labs(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
773 723
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
774 724
           de = 0; // no difference
775
-          #if ENABLED(LIN_ADVANCE)
776
-            position_float[E_AXIS] = e;
777
-            de_float = 0;
778
-          #endif
779 725
           SERIAL_ECHO_START();
780 726
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
781 727
         }
@@ -783,6 +729,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
783 729
     }
784 730
   #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
785 731
 
732
+  #if ENABLED(LIN_ADVANCE)
733
+    float de_float = de * steps_to_mm[E_AXIS_N];
734
+  #endif
735
+
786 736
   // Compute direction bit-mask for this block
787 737
   uint8_t dm = 0;
788 738
   #if CORE_IS_XY
@@ -1380,30 +1330,28 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1380 1330
 
1381 1331
   #if ENABLED(LIN_ADVANCE)
1382 1332
 
1383
-    //
1384
-    // Use LIN_ADVANCE for blocks if all these are true:
1385
-    //
1386
-    // esteps                                          : We have E steps todo (a printing move)
1387
-    //
1388
-    // block->steps[X_AXIS] || block->steps[Y_AXIS]    : We have a movement in XY direction (i.e., not retract / prime).
1389
-    //
1390
-    // extruder_advance_k                              : There is an advance factor set.
1391
-    //
1392
-    // block->steps[E_AXIS] != block->step_event_count : A problem occurs if the move before a retract is too small.
1393
-    //                                                   In that case, the retract and move will be executed together.
1394
-    //                                                   This leads to too many advance steps due to a huge e_acceleration.
1395
-    //                                                   The math is good, but we must avoid retract moves with advance!
1396
-    // de_float > 0.0                                  : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1397
-    //
1398
-    block->use_advance_lead =  esteps
1399
-                            && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1333
+    /**
1334
+     *
1335
+     * Use LIN_ADVANCE for blocks if all these are true:
1336
+     *
1337
+     * esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS]) : This is a print move
1338
+     *
1339
+     * extruder_advance_k                 : There is an advance factor set.
1340
+     *
1341
+     * esteps != block->step_event_count  : A problem occurs if the move before a retract is too small.
1342
+     *                                      In that case, the retract and move will be executed together.
1343
+     *                                      This leads to too many advance steps due to a huge e_acceleration.
1344
+     *                                      The math is good, but we must avoid retract moves with advance!
1345
+     * de > 0                             : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1346
+     */
1347
+    block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1400 1348
                             && extruder_advance_k
1401 1349
                             && (uint32_t)esteps != block->step_event_count
1402
-                            && de_float > 0.0;
1350
+                            && de > 0;
1403 1351
     if (block->use_advance_lead)
1404 1352
       block->abs_adv_steps_multiplier8 = LROUND(
1405 1353
         extruder_advance_k
1406
-        * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
1354
+        * (UNEAR_ZERO(advance_ed_ratio) ? de * steps_to_mm[E_AXIS_N] / HYPOT(da * steps_to_mm[X_AXIS], db * steps_to_mm[Y_AXIS]) : advance_ed_ratio) // Use the fixed ratio, if set
1407 1355
         * (block->nominal_speed / (float)block->nominal_rate)
1408 1356
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1409 1357
       );
@@ -1417,12 +1365,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1417 1365
 
1418 1366
   // Update the position (only when a move was queued)
1419 1367
   COPY(position, target);
1420
-  #if ENABLED(LIN_ADVANCE)
1421
-    position_float[X_AXIS] = a;
1422
-    position_float[Y_AXIS] = b;
1423
-    position_float[Z_AXIS] = c;
1424
-    position_float[E_AXIS] = e;
1425
-  #endif
1426 1368
 
1427 1369
   recalculate();
1428 1370
 
@@ -1448,12 +1390,6 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
1448 1390
              nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1449 1391
              nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1450 1392
              ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
1451
-  #if ENABLED(LIN_ADVANCE)
1452
-    position_float[X_AXIS] = a;
1453
-    position_float[Y_AXIS] = b;
1454
-    position_float[Z_AXIS] = c;
1455
-    position_float[E_AXIS] = e;
1456
-  #endif
1457 1393
   stepper.set_position(na, nb, nc, ne);
1458 1394
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1459 1395
   ZERO(previous_speed);
@@ -1478,16 +1414,8 @@ void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
1478 1414
  * Sync from the stepper positions. (e.g., after an interrupted move)
1479 1415
  */
1480 1416
 void Planner::sync_from_steppers() {
1481
-  LOOP_XYZE(i) {
1417
+  LOOP_XYZE(i)
1482 1418
     position[i] = stepper.position((AxisEnum)i);
1483
-    #if ENABLED(LIN_ADVANCE)
1484
-      position_float[i] = position[i] * steps_to_mm[i
1485
-        #if ENABLED(DISTINCT_E_FACTORS)
1486
-          + (i == E_AXIS ? active_extruder : 0)
1487
-        #endif
1488
-      ];
1489
-    #endif
1490
-  }
1491 1419
 }
1492 1420
 
1493 1421
 /**
@@ -1501,9 +1429,6 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
1501 1429
     const uint8_t axis_index = axis;
1502 1430
   #endif
1503 1431
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1504
-  #if ENABLED(LIN_ADVANCE)
1505
-    position_float[axis] = v;
1506
-  #endif
1507 1432
   stepper.set_position(axis, v);
1508 1433
   previous_speed[axis] = 0.0;
1509 1434
 }

+ 10
- 6
Marlin/planner.h View File

@@ -219,10 +219,6 @@ class Planner {
219 219
       static uint32_t axis_segment_time_us[2][3];
220 220
     #endif
221 221
 
222
-    #if ENABLED(LIN_ADVANCE)
223
-      static float position_float[NUM_AXIS];
224
-    #endif
225
-
226 222
     #if ENABLED(ULTRA_LCD)
227 223
       volatile static uint32_t block_buffer_runtime_us; //Theoretical block buffer runtime in µs
228 224
     #endif
@@ -251,8 +247,6 @@ class Planner {
251 247
     // Manage fans, paste pressure, etc.
252 248
     static void check_axes_activity();
253 249
 
254
-    static void calculate_volumetric_multipliers();
255
-
256 250
     /**
257 251
      * Number of moves currently in the planner
258 252
      */
@@ -260,6 +254,16 @@ class Planner {
260 254
 
261 255
     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
262 256
 
257
+    // Update multipliers based on new diameter measurements
258
+    static void calculate_volumetric_multipliers();
259
+
260
+    FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
261
+      filament_size[e] = v;
262
+      // make sure all extruders have some sane value for the filament size
263
+      for (uint8_t i = 0; i < COUNT(filament_size); i++)
264
+        if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
265
+    }
266
+
263 267
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
264 268
 
265 269
       /**

Loading…
Cancel
Save