Bladeren bron

Drop Planner::position_float, use int types

Scott Lahteine 7 jaren geleden
bovenliggende
commit
dd3ce40826
2 gewijzigde bestanden met toevoegingen van 31 en 89 verwijderingen
  1. 29
    83
      Marlin/src/module/planner.cpp
  2. 2
    6
      Marlin/src/module/planner.h

+ 29
- 83
Marlin/src/module/planner.cpp Bestand weergeven

@@ -144,7 +144,7 @@ float Planner::min_feedrate_mm_s,
144 144
 
145 145
 // private:
146 146
 
147
-long Planner::position[NUM_AXIS] = { 0 };
147
+int32_t Planner::position[NUM_AXIS] = { 0 };
148 148
 
149 149
 uint32_t Planner::cutoff_long;
150 150
 
@@ -164,8 +164,7 @@ float Planner::previous_speed[NUM_AXIS],
164 164
 
165 165
 #if ENABLED(LIN_ADVANCE)
166 166
   float Planner::extruder_advance_k, // Initialized by settings.load()
167
-        Planner::advance_ed_ratio,   // Initialized by settings.load()
168
-        Planner::position_float[NUM_AXIS] = { 0 };
167
+        Planner::advance_ed_ratio;   // Initialized by settings.load()
169 168
 #endif
170 169
 
171 170
 #if ENABLED(ULTRA_LCD)
@@ -181,9 +180,6 @@ Planner::Planner() { init(); }
181 180
 void Planner::init() {
182 181
   block_buffer_head = block_buffer_tail = 0;
183 182
   ZERO(position);
184
-  #if ENABLED(LIN_ADVANCE)
185
-    ZERO(position_float);
186
-  #endif
187 183
   ZERO(previous_speed);
188 184
   previous_nominal_speed = 0.0;
189 185
   #if ABL_PLANAR
@@ -690,13 +686,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
690 686
     }
691 687
   #endif
692 688
 
693
-  #if ENABLED(LIN_ADVANCE)
694
-    const float mm_D_float = SQRT(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
695
-  #endif
696
-
697
-  const long da = target[X_AXIS] - position[X_AXIS],
698
-             db = target[Y_AXIS] - position[Y_AXIS],
699
-             dc = target[Z_AXIS] - position[Z_AXIS];
689
+  const int32_t da = target[X_AXIS] - position[X_AXIS],
690
+                db = target[Y_AXIS] - position[Y_AXIS],
691
+                dc = target[Z_AXIS] - position[Z_AXIS];
700 692
 
701 693
   /*
702 694
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
@@ -721,19 +713,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
721 713
   SERIAL_EOL();
722 714
   //*/
723 715
 
724
-  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
725
-  if (DEBUGGING(DRYRUN)) {
726
-    position[E_AXIS] = target[E_AXIS];
727
-    #if ENABLED(LIN_ADVANCE)
728
-      position_float[E_AXIS] = e;
729
-    #endif
730
-  }
731
-
732
-  long de = target[E_AXIS] - position[E_AXIS];
733
-
734
-  #if ENABLED(LIN_ADVANCE)
735
-    float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
736
-  #endif
716
+  int32_t de = target[E_AXIS] - position[E_AXIS];
737 717
 
738 718
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
739 719
     if (de) {
@@ -741,10 +721,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
741 721
         if (thermalManager.tooColdToExtrude(extruder)) {
742 722
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
743 723
           de = 0; // no difference
744
-          #if ENABLED(LIN_ADVANCE)
745
-            position_float[E_AXIS] = e;
746
-            de_float = 0;
747
-          #endif
748 724
           SERIAL_ECHO_START();
749 725
           SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
750 726
         }
@@ -753,10 +729,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
753 729
         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
754 730
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
755 731
           de = 0; // no difference
756
-          #if ENABLED(LIN_ADVANCE)
757
-            position_float[E_AXIS] = e;
758
-            de_float = 0;
759
-          #endif
760 732
           SERIAL_ECHO_START();
761 733
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
762 734
         }
@@ -1036,7 +1008,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1036 1008
       #endif
1037 1009
     );
1038 1010
   }
1039
-  const float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
1011
+  float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
1040 1012
 
1041 1013
   // Calculate moves/second for this move. No divide by zero due to previous checks.
1042 1014
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
@@ -1360,31 +1332,28 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1360 1332
   previous_safe_speed = safe_speed;
1361 1333
 
1362 1334
   #if ENABLED(LIN_ADVANCE)
1363
-
1364
-    //
1365
-    // Use LIN_ADVANCE for blocks if all these are true:
1366
-    //
1367
-    // esteps                                          : We have E steps todo (a printing move)
1368
-    //
1369
-    // block->steps[X_AXIS] || block->steps[Y_AXIS]    : We have a movement in XY direction (i.e., not retract / prime).
1370
-    //
1371
-    // extruder_advance_k                              : There is an advance factor set.
1372
-    //
1373
-    // block->steps[E_AXIS] != block->step_event_count : A problem occurs if the move before a retract is too small.
1374
-    //                                                   In that case, the retract and move will be executed together.
1375
-    //                                                   This leads to too many advance steps due to a huge e_acceleration.
1376
-    //                                                   The math is good, but we must avoid retract moves with advance!
1377
-    // de_float > 0.0                                  : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1378
-    //
1379
-    block->use_advance_lead =  esteps
1380
-                            && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1335
+    /**
1336
+     *
1337
+     * Use LIN_ADVANCE for blocks if all these are true:
1338
+     *
1339
+     * esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS]) : This is a print move
1340
+     *
1341
+     * extruder_advance_k                 : There is an advance factor set.
1342
+     *
1343
+     * esteps != block->step_event_count  : A problem occurs if the move before a retract is too small.
1344
+     *                                      In that case, the retract and move will be executed together.
1345
+     *                                      This leads to too many advance steps due to a huge e_acceleration.
1346
+     *                                      The math is good, but we must avoid retract moves with advance!
1347
+     * de > 0                             : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1348
+     */
1349
+    block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1381 1350
                             && extruder_advance_k
1382 1351
                             && (uint32_t)esteps != block->step_event_count
1383
-                            && de_float > 0.0;
1352
+                            && de > 0;
1384 1353
     if (block->use_advance_lead)
1385 1354
       block->abs_adv_steps_multiplier8 = LROUND(
1386 1355
         extruder_advance_k
1387
-        * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
1356
+        * (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
1388 1357
         * (block->nominal_speed / (float)block->nominal_rate)
1389 1358
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1390 1359
       );
@@ -1398,12 +1367,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1398 1367
 
1399 1368
   // Update the position (only when a move was queued)
1400 1369
   COPY(position, target);
1401
-  #if ENABLED(LIN_ADVANCE)
1402
-    position_float[X_AXIS] = a;
1403
-    position_float[Y_AXIS] = b;
1404
-    position_float[Z_AXIS] = c;
1405
-    position_float[E_AXIS] = e;
1406
-  #endif
1407 1370
 
1408 1371
   recalculate();
1409 1372
 
@@ -1425,16 +1388,10 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
1425 1388
   #else
1426 1389
     #define _EINDEX E_AXIS
1427 1390
   #endif
1428
-  const long na = position[X_AXIS] = LROUND(a * axis_steps_per_mm[X_AXIS]),
1429
-             nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1430
-             nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1431
-             ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
1432
-  #if ENABLED(LIN_ADVANCE)
1433
-    position_float[X_AXIS] = a;
1434
-    position_float[Y_AXIS] = b;
1435
-    position_float[Z_AXIS] = c;
1436
-    position_float[E_AXIS] = e;
1437
-  #endif
1391
+  const int32_t na = position[X_AXIS] = LROUND(a * axis_steps_per_mm[X_AXIS]),
1392
+                nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
1393
+                nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
1394
+                ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
1438 1395
   stepper.set_position(na, nb, nc, ne);
1439 1396
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1440 1397
   ZERO(previous_speed);
@@ -1459,16 +1416,8 @@ void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
1459 1416
  * Sync from the stepper positions. (e.g., after an interrupted move)
1460 1417
  */
1461 1418
 void Planner::sync_from_steppers() {
1462
-  LOOP_XYZE(i) {
1419
+  LOOP_XYZE(i)
1463 1420
     position[i] = stepper.position((AxisEnum)i);
1464
-    #if ENABLED(LIN_ADVANCE)
1465
-      position_float[i] = position[i] * steps_to_mm[i
1466
-        #if ENABLED(DISTINCT_E_FACTORS)
1467
-          + (i == E_AXIS ? active_extruder : 0)
1468
-        #endif
1469
-      ];
1470
-    #endif
1471
-  }
1472 1421
 }
1473 1422
 
1474 1423
 /**
@@ -1482,9 +1431,6 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
1482 1431
     const uint8_t axis_index = axis;
1483 1432
   #endif
1484 1433
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1485
-  #if ENABLED(LIN_ADVANCE)
1486
-    position_float[axis] = v;
1487
-  #endif
1488 1434
   stepper.set_position(axis, v);
1489 1435
   previous_speed[axis] = 0.0;
1490 1436
 }

+ 2
- 6
Marlin/src/module/planner.h Bestand weergeven

@@ -186,7 +186,7 @@ class Planner {
186 186
      * The current position of the tool in absolute steps
187 187
      * Recalculated if any axis_steps_per_mm are changed by gcode
188 188
      */
189
-    static long position[NUM_AXIS];
189
+    static int32_t position[NUM_AXIS];
190 190
 
191 191
     /**
192 192
      * Speed of previous path line segment
@@ -220,11 +220,7 @@ class Planner {
220 220
       // Old direction bits. Used for speed calculations
221 221
       static unsigned char old_direction_bits;
222 222
       // Segment times (in µs). Used for speed calculations
223
-      static long axis_segment_time_us[2][3];
224
-    #endif
225
-
226
-    #if ENABLED(LIN_ADVANCE)
227
-      static float position_float[NUM_AXIS];
223
+      static uint32_t axis_segment_time_us[2][3];
228 224
     #endif
229 225
 
230 226
     #if ENABLED(ULTRA_LCD)

Laden…
Annuleren
Opslaan