Просмотр исходного кода

Restore position_float to fix LIN_ADVANCE

Scott Lahteine 6 лет назад
Родитель
Сommit
5bc2acc072
3 измененных файлов: 100 добавлений и 10 удалений
  1. 4
    0
      Marlin/src/inc/SanityCheck.h
  2. 93
    9
      Marlin/src/module/planner.cpp
  3. 3
    1
      Marlin/src/module/planner.h

+ 4
- 0
Marlin/src/inc/SanityCheck.h Просмотреть файл

@@ -491,6 +491,10 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
491 491
   #endif
492 492
 #endif
493 493
 
494
+#if ENABLED(LIN_ADVANCE) && !IS_CARTESIAN
495
+  #error "Sorry! LIN_ADVANCE is only compatible with Cartesian."
496
+#endif
497
+
494 498
 /**
495 499
  * Parking Extruder requirements
496 500
  */

+ 93
- 9
Marlin/src/module/planner.cpp Просмотреть файл

@@ -182,7 +182,10 @@ float Planner::previous_speed[NUM_AXIS],
182 182
 
183 183
 #if ENABLED(LIN_ADVANCE)
184 184
   float Planner::extruder_advance_k, // Initialized by settings.load()
185
-        Planner::advance_ed_ratio;   // Initialized by settings.load()
185
+        Planner::advance_ed_ratio,   // Initialized by settings.load()
186
+        Planner::position_float[XYZE], // Needed for accurate maths. Steps cannot be used!
187
+        Planner::lin_dist_xy,
188
+        Planner::lin_dist_e;
186 189
 #endif
187 190
 
188 191
 #if ENABLED(ULTRA_LCD)
@@ -198,6 +201,9 @@ Planner::Planner() { init(); }
198 201
 void Planner::init() {
199 202
   block_buffer_head = block_buffer_tail = 0;
200 203
   ZERO(position);
204
+  #if ENABLED(LIN_ADVANCE)
205
+    ZERO(position_float);
206
+  #endif
201 207
   ZERO(previous_speed);
202 208
   previous_nominal_speed = 0.0;
203 209
   #if ABL_PLANAR
@@ -742,7 +748,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
742 748
     SERIAL_ECHOLNPGM(" steps)");
743 749
   //*/
744 750
 
745
-  #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
751
+  // If LIN_ADVANCE is disabled then do E move prevention with integers
752
+  // Otherwise it's done in _buffer_segment.
753
+  #if DISABLED(LIN_ADVANCE) && (ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE))
746 754
     if (de) {
747 755
       #if ENABLED(PREVENT_COLD_EXTRUSION)
748 756
         if (thermalManager.tooColdToExtrude(extruder)) {
@@ -761,7 +769,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
761 769
         }
762 770
       #endif // PREVENT_LENGTHY_EXTRUDE
763 771
     }
764
-  #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
772
+  #endif // !LIN_ADVANCE && (PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE)
765 773
 
766 774
   // Compute direction bit-mask for this block
767 775
   uint8_t dm = 0;
@@ -1355,16 +1363,16 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1355 1363
      *                                      In that case, the retract and move will be executed together.
1356 1364
      *                                      This leads to too many advance steps due to a huge e_acceleration.
1357 1365
      *                                      The math is good, but we must avoid retract moves with advance!
1358
-     * de > 0                             : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1366
+     * lin_dist_e > 0                     : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1359 1367
      */
1360 1368
     block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1361 1369
                             && extruder_advance_k
1362 1370
                             && (uint32_t)esteps != block->step_event_count
1363
-                            && de > 0;
1371
+                            && lin_dist_e > 0;
1364 1372
     if (block->use_advance_lead)
1365 1373
       block->abs_adv_steps_multiplier8 = LROUND(
1366 1374
         extruder_advance_k
1367
-        * (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
1375
+        * (UNEAR_ZERO(advance_ed_ratio) ? lin_dist_e / lin_dist_xy : advance_ed_ratio) // Use the fixed ratio, if set
1368 1376
         * (block->nominal_speed / (float)block->nominal_rate)
1369 1377
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1370 1378
       );
@@ -1442,16 +1450,69 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
1442 1450
     SERIAL_ECHOLNPGM(")");
1443 1451
   //*/
1444 1452
 
1445
-  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1446
-  if (DEBUGGING(DRYRUN))
1453
+  // DRYRUN prevents E moves from taking place
1454
+  if (DEBUGGING(DRYRUN)) {
1447 1455
     position[E_AXIS] = target[E_AXIS];
1456
+    #if ENABLED(LIN_ADVANCE)
1457
+      position_float[E_AXIS] = e;
1458
+    #endif
1459
+  }
1460
+
1461
+  #if ENABLED(LIN_ADVANCE)
1462
+    lin_dist_e = e - position_float[E_AXIS];
1463
+  #endif
1464
+
1465
+  // If LIN_ADVANCE is enabled then do E move prevention with floats
1466
+  // Otherwise it's done in _buffer_steps.
1467
+  #if ENABLED(LIN_ADVANCE) && (ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE))
1468
+    if (lin_dist_e) {
1469
+      #if ENABLED(PREVENT_COLD_EXTRUSION)
1470
+        if (thermalManager.tooColdToExtrude(extruder)) {
1471
+          position_float[E_AXIS] = e; // Behave as if the move really took place, but ignore E part
1472
+          position[E_AXIS] = target[E_AXIS];
1473
+          lin_dist_e = 0;
1474
+          SERIAL_ECHO_START();
1475
+          SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
1476
+        }
1477
+      #endif // PREVENT_COLD_EXTRUSION
1478
+      #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
1479
+        if (lin_dist_e * e_factor[extruder] > (EXTRUDE_MAXLENGTH)) {
1480
+          position_float[E_AXIS] = e; // Behave as if the move really took place, but ignore E part
1481
+          position[E_AXIS] = target[E_AXIS];
1482
+          lin_dist_e = 0;
1483
+          SERIAL_ECHO_START();
1484
+          SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
1485
+        }
1486
+      #endif // PREVENT_LENGTHY_EXTRUDE
1487
+    }
1488
+  #endif // LIN_ADVANCE && (PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE)
1489
+
1490
+  #if ENABLED(LIN_ADVANCE)
1491
+    if (lin_dist_e > 0)
1492
+      lin_dist_xy = HYPOT(a - position_float[X_AXIS], b - position_float[Y_AXIS]);
1493
+  #endif
1448 1494
 
1449 1495
   // Always split the first move into two (if not homing or probing)
1450 1496
   if (!blocks_queued()) {
1497
+
1451 1498
     #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1452 1499
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1453 1500
     DISABLE_STEPPER_DRIVER_INTERRUPT();
1501
+
1502
+    #if ENABLED(LIN_ADVANCE)
1503
+      lin_dist_xy *= 0.5;
1504
+      lin_dist_e *= 0.5;
1505
+    #endif
1506
+
1454 1507
     _buffer_steps(between, fr_mm_s, extruder);
1508
+
1509
+    #if ENABLED(LIN_ADVANCE)
1510
+      position_float[X_AXIS] = (position_float[X_AXIS] + a) * 0.5;
1511
+      position_float[Y_AXIS] = (position_float[Y_AXIS] + b) * 0.5;
1512
+      //position_float[Z_AXIS] = (position_float[Z_AXIS] + c) * 0.5;
1513
+      position_float[E_AXIS] = (position_float[E_AXIS] + e) * 0.5;
1514
+    #endif
1515
+
1455 1516
     const uint8_t next = block_buffer_head;
1456 1517
     _buffer_steps(target, fr_mm_s, extruder);
1457 1518
     SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
@@ -1462,6 +1523,12 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
1462 1523
 
1463 1524
   stepper.wake_up();
1464 1525
 
1526
+  #if ENABLED(LIN_ADVANCE)
1527
+    position_float[X_AXIS] = a;
1528
+    position_float[Y_AXIS] = b;
1529
+    //position_float[Z_AXIS] = c;
1530
+    position_float[E_AXIS] = e;
1531
+  #endif
1465 1532
 } // buffer_segment()
1466 1533
 
1467 1534
 /**
@@ -1482,6 +1549,12 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
1482 1549
                 nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1483 1550
                 nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1484 1551
                 ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
1552
+  #if ENABLED(LIN_ADVANCE)
1553
+    position_float[X_AXIS] = a;
1554
+    position_float[Y_AXIS] = b;
1555
+    //position_float[Z_AXIS] = c;
1556
+    position_float[E_AXIS] = e;
1557
+  #endif
1485 1558
   stepper.set_position(na, nb, nc, ne);
1486 1559
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1487 1560
   ZERO(previous_speed);
@@ -1506,8 +1579,16 @@ void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
1506 1579
  * Sync from the stepper positions. (e.g., after an interrupted move)
1507 1580
  */
1508 1581
 void Planner::sync_from_steppers() {
1509
-  LOOP_XYZE(i)
1582
+  LOOP_XYZE(i) {
1510 1583
     position[i] = stepper.position((AxisEnum)i);
1584
+    #if ENABLED(LIN_ADVANCE)
1585
+      position_float[i] = position[i] * steps_to_mm[i
1586
+        #if ENABLED(DISTINCT_E_FACTORS)
1587
+          + (i == E_AXIS ? active_extruder : 0)
1588
+        #endif
1589
+      ];
1590
+    #endif
1591
+  }
1511 1592
 }
1512 1593
 
1513 1594
 /**
@@ -1521,6 +1602,9 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
1521 1602
     const uint8_t axis_index = axis;
1522 1603
   #endif
1523 1604
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1605
+  #if ENABLED(LIN_ADVANCE)
1606
+    position_float[axis] = v;
1607
+  #endif
1524 1608
   stepper.set_position(axis, v);
1525 1609
   previous_speed[axis] = 0.0;
1526 1610
 }

+ 3
- 1
Marlin/src/module/planner.h Просмотреть файл

@@ -195,7 +195,9 @@ class Planner {
195 195
     #endif
196 196
 
197 197
     #if ENABLED(LIN_ADVANCE)
198
-      static float extruder_advance_k, advance_ed_ratio;
198
+      static float extruder_advance_k, advance_ed_ratio,
199
+                   position_float[XYZE],
200
+                   lin_dist_xy, lin_dist_e;
199 201
     #endif
200 202
 
201 203
     #if ENABLED(SKEW_CORRECTION)

Загрузка…
Отмена
Сохранить