浏览代码

Restore position_float to fix LIN_ADVANCE

Scott Lahteine 6 年前
父节点
当前提交
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
   #endif
491
   #endif
492
 #endif
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
  * Parking Extruder requirements
499
  * Parking Extruder requirements
496
  */
500
  */

+ 93
- 9
Marlin/src/module/planner.cpp 查看文件

182
 
182
 
183
 #if ENABLED(LIN_ADVANCE)
183
 #if ENABLED(LIN_ADVANCE)
184
   float Planner::extruder_advance_k, // Initialized by settings.load()
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
 #endif
189
 #endif
187
 
190
 
188
 #if ENABLED(ULTRA_LCD)
191
 #if ENABLED(ULTRA_LCD)
198
 void Planner::init() {
201
 void Planner::init() {
199
   block_buffer_head = block_buffer_tail = 0;
202
   block_buffer_head = block_buffer_tail = 0;
200
   ZERO(position);
203
   ZERO(position);
204
+  #if ENABLED(LIN_ADVANCE)
205
+    ZERO(position_float);
206
+  #endif
201
   ZERO(previous_speed);
207
   ZERO(previous_speed);
202
   previous_nominal_speed = 0.0;
208
   previous_nominal_speed = 0.0;
203
   #if ABL_PLANAR
209
   #if ABL_PLANAR
742
     SERIAL_ECHOLNPGM(" steps)");
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
     if (de) {
754
     if (de) {
747
       #if ENABLED(PREVENT_COLD_EXTRUSION)
755
       #if ENABLED(PREVENT_COLD_EXTRUSION)
748
         if (thermalManager.tooColdToExtrude(extruder)) {
756
         if (thermalManager.tooColdToExtrude(extruder)) {
761
         }
769
         }
762
       #endif // PREVENT_LENGTHY_EXTRUDE
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
   // Compute direction bit-mask for this block
774
   // Compute direction bit-mask for this block
767
   uint8_t dm = 0;
775
   uint8_t dm = 0;
1355
      *                                      In that case, the retract and move will be executed together.
1363
      *                                      In that case, the retract and move will be executed together.
1356
      *                                      This leads to too many advance steps due to a huge e_acceleration.
1364
      *                                      This leads to too many advance steps due to a huge e_acceleration.
1357
      *                                      The math is good, but we must avoid retract moves with advance!
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
     block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1368
     block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1361
                             && extruder_advance_k
1369
                             && extruder_advance_k
1362
                             && (uint32_t)esteps != block->step_event_count
1370
                             && (uint32_t)esteps != block->step_event_count
1363
-                            && de > 0;
1371
+                            && lin_dist_e > 0;
1364
     if (block->use_advance_lead)
1372
     if (block->use_advance_lead)
1365
       block->abs_adv_steps_multiplier8 = LROUND(
1373
       block->abs_adv_steps_multiplier8 = LROUND(
1366
         extruder_advance_k
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
         * (block->nominal_speed / (float)block->nominal_rate)
1376
         * (block->nominal_speed / (float)block->nominal_rate)
1369
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1377
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1370
       );
1378
       );
1442
     SERIAL_ECHOLNPGM(")");
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
     position[E_AXIS] = target[E_AXIS];
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
   // Always split the first move into two (if not homing or probing)
1495
   // Always split the first move into two (if not homing or probing)
1450
   if (!blocks_queued()) {
1496
   if (!blocks_queued()) {
1497
+
1451
     #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1498
     #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1452
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1499
     const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1453
     DISABLE_STEPPER_DRIVER_INTERRUPT();
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
     _buffer_steps(between, fr_mm_s, extruder);
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
     const uint8_t next = block_buffer_head;
1516
     const uint8_t next = block_buffer_head;
1456
     _buffer_steps(target, fr_mm_s, extruder);
1517
     _buffer_steps(target, fr_mm_s, extruder);
1457
     SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
1518
     SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
1462
 
1523
 
1463
   stepper.wake_up();
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
 } // buffer_segment()
1532
 } // buffer_segment()
1466
 
1533
 
1467
 /**
1534
 /**
1482
                 nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1549
                 nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1483
                 nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1550
                 nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1484
                 ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
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
   stepper.set_position(na, nb, nc, ne);
1558
   stepper.set_position(na, nb, nc, ne);
1486
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1559
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1487
   ZERO(previous_speed);
1560
   ZERO(previous_speed);
1506
  * Sync from the stepper positions. (e.g., after an interrupted move)
1579
  * Sync from the stepper positions. (e.g., after an interrupted move)
1507
  */
1580
  */
1508
 void Planner::sync_from_steppers() {
1581
 void Planner::sync_from_steppers() {
1509
-  LOOP_XYZE(i)
1582
+  LOOP_XYZE(i) {
1510
     position[i] = stepper.position((AxisEnum)i);
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
     const uint8_t axis_index = axis;
1602
     const uint8_t axis_index = axis;
1522
   #endif
1603
   #endif
1523
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1604
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1605
+  #if ENABLED(LIN_ADVANCE)
1606
+    position_float[axis] = v;
1607
+  #endif
1524
   stepper.set_position(axis, v);
1608
   stepper.set_position(axis, v);
1525
   previous_speed[axis] = 0.0;
1609
   previous_speed[axis] = 0.0;
1526
 }
1610
 }

+ 3
- 1
Marlin/src/module/planner.h 查看文件

195
     #endif
195
     #endif
196
 
196
 
197
     #if ENABLED(LIN_ADVANCE)
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
     #endif
201
     #endif
200
 
202
 
201
     #if ENABLED(SKEW_CORRECTION)
203
     #if ENABLED(SKEW_CORRECTION)

正在加载...
取消
保存