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
 
144
 
145
 // private:
145
 // private:
146
 
146
 
147
-long Planner::position[NUM_AXIS] = { 0 };
147
+int32_t Planner::position[NUM_AXIS] = { 0 };
148
 
148
 
149
 uint32_t Planner::cutoff_long;
149
 uint32_t Planner::cutoff_long;
150
 
150
 
164
 
164
 
165
 #if ENABLED(LIN_ADVANCE)
165
 #if ENABLED(LIN_ADVANCE)
166
   float Planner::extruder_advance_k, // Initialized by settings.load()
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
 #endif
168
 #endif
170
 
169
 
171
 #if ENABLED(ULTRA_LCD)
170
 #if ENABLED(ULTRA_LCD)
181
 void Planner::init() {
180
 void Planner::init() {
182
   block_buffer_head = block_buffer_tail = 0;
181
   block_buffer_head = block_buffer_tail = 0;
183
   ZERO(position);
182
   ZERO(position);
184
-  #if ENABLED(LIN_ADVANCE)
185
-    ZERO(position_float);
186
-  #endif
187
   ZERO(previous_speed);
183
   ZERO(previous_speed);
188
   previous_nominal_speed = 0.0;
184
   previous_nominal_speed = 0.0;
189
   #if ABL_PLANAR
185
   #if ABL_PLANAR
690
     }
686
     }
691
   #endif
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
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
694
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
721
   SERIAL_EOL();
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
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
718
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
739
     if (de) {
719
     if (de) {
741
         if (thermalManager.tooColdToExtrude(extruder)) {
721
         if (thermalManager.tooColdToExtrude(extruder)) {
742
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
722
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
743
           de = 0; // no difference
723
           de = 0; // no difference
744
-          #if ENABLED(LIN_ADVANCE)
745
-            position_float[E_AXIS] = e;
746
-            de_float = 0;
747
-          #endif
748
           SERIAL_ECHO_START();
724
           SERIAL_ECHO_START();
749
           SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
725
           SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
750
         }
726
         }
753
         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
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
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
730
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
755
           de = 0; // no difference
731
           de = 0; // no difference
756
-          #if ENABLED(LIN_ADVANCE)
757
-            position_float[E_AXIS] = e;
758
-            de_float = 0;
759
-          #endif
760
           SERIAL_ECHO_START();
732
           SERIAL_ECHO_START();
761
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
733
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
762
         }
734
         }
1036
       #endif
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
   // Calculate moves/second for this move. No divide by zero due to previous checks.
1013
   // Calculate moves/second for this move. No divide by zero due to previous checks.
1042
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
1014
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
1360
   previous_safe_speed = safe_speed;
1332
   previous_safe_speed = safe_speed;
1361
 
1333
 
1362
   #if ENABLED(LIN_ADVANCE)
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
                             && extruder_advance_k
1350
                             && extruder_advance_k
1382
                             && (uint32_t)esteps != block->step_event_count
1351
                             && (uint32_t)esteps != block->step_event_count
1383
-                            && de_float > 0.0;
1352
+                            && de > 0;
1384
     if (block->use_advance_lead)
1353
     if (block->use_advance_lead)
1385
       block->abs_adv_steps_multiplier8 = LROUND(
1354
       block->abs_adv_steps_multiplier8 = LROUND(
1386
         extruder_advance_k
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
         * (block->nominal_speed / (float)block->nominal_rate)
1357
         * (block->nominal_speed / (float)block->nominal_rate)
1389
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1358
         * axis_steps_per_mm[E_AXIS_N] * 256.0
1390
       );
1359
       );
1398
 
1367
 
1399
   // Update the position (only when a move was queued)
1368
   // Update the position (only when a move was queued)
1400
   COPY(position, target);
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
   recalculate();
1371
   recalculate();
1409
 
1372
 
1425
   #else
1388
   #else
1426
     #define _EINDEX E_AXIS
1389
     #define _EINDEX E_AXIS
1427
   #endif
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
   stepper.set_position(na, nb, nc, ne);
1395
   stepper.set_position(na, nb, nc, ne);
1439
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1396
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1440
   ZERO(previous_speed);
1397
   ZERO(previous_speed);
1459
  * Sync from the stepper positions. (e.g., after an interrupted move)
1416
  * Sync from the stepper positions. (e.g., after an interrupted move)
1460
  */
1417
  */
1461
 void Planner::sync_from_steppers() {
1418
 void Planner::sync_from_steppers() {
1462
-  LOOP_XYZE(i) {
1419
+  LOOP_XYZE(i)
1463
     position[i] = stepper.position((AxisEnum)i);
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
     const uint8_t axis_index = axis;
1431
     const uint8_t axis_index = axis;
1483
   #endif
1432
   #endif
1484
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1433
   position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
1485
-  #if ENABLED(LIN_ADVANCE)
1486
-    position_float[axis] = v;
1487
-  #endif
1488
   stepper.set_position(axis, v);
1434
   stepper.set_position(axis, v);
1489
   previous_speed[axis] = 0.0;
1435
   previous_speed[axis] = 0.0;
1490
 }
1436
 }

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

186
      * The current position of the tool in absolute steps
186
      * The current position of the tool in absolute steps
187
      * Recalculated if any axis_steps_per_mm are changed by gcode
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
      * Speed of previous path line segment
192
      * Speed of previous path line segment
220
       // Old direction bits. Used for speed calculations
220
       // Old direction bits. Used for speed calculations
221
       static unsigned char old_direction_bits;
221
       static unsigned char old_direction_bits;
222
       // Segment times (in µs). Used for speed calculations
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
     #endif
224
     #endif
229
 
225
 
230
     #if ENABLED(ULTRA_LCD)
226
     #if ENABLED(ULTRA_LCD)

Laden…
Annuleren
Opslaan