Kaynağa Gözat

Add pre-calculated planner.e_factor

Scott Lahteine 6 yıl önce
ebeveyn
işleme
cba9c1cf9e

+ 1
- 1
Marlin/src/feature/fwretract.cpp Dosyayı Görüntüle

@@ -130,7 +130,7 @@ void FWRetract::retract(const bool retracting
130 130
   set_destination_from_current();
131 131
   stepper.synchronize();  // Wait for buffered moves to complete
132 132
 
133
-  const float renormalize = 100.0 / planner.flow_percentage[active_extruder] / planner.volumetric_multiplier[active_extruder];
133
+  const float renormalize = 1.0 / planner.e_factor[active_extruder];
134 134
 
135 135
   if (retracting) {
136 136
     // Retract by moving from a faux E position back to the current E position

+ 1
- 1
Marlin/src/feature/pause.cpp Dosyayı Görüntüle

@@ -94,7 +94,7 @@ static void ensure_safe_temperature() {
94 94
 }
95 95
 
96 96
 void do_pause_e_move(const float &length, const float fr) {
97
-  current_position[E_AXIS] += length * 100.0 / planner.flow_percentage[active_extruder] / planner.volumetric_multiplier[active_extruder];
97
+  current_position[E_AXIS] += length / planner.e_factor[active_extruder];
98 98
   set_destination_from_current();
99 99
   #if IS_KINEMATIC
100 100
     planner.buffer_line_kinematic(destination, fr, active_extruder);

+ 3
- 1
Marlin/src/gcode/config/M221.cpp Dosyayı Görüntüle

@@ -28,6 +28,8 @@
28 28
  */
29 29
 void GcodeSuite::M221() {
30 30
   if (get_target_extruder_from_command()) return;
31
-  if (parser.seenval('S'))
31
+  if (parser.seenval('S')) {
32 32
     planner.flow_percentage[target_extruder] = parser.value_int();
33
+    planner.refresh_e_factor(target_extruder);
34
+  }
33 35
 }

+ 23
- 7
Marlin/src/lcd/ultralcd.cpp Dosyayı Görüntüle

@@ -1249,6 +1249,22 @@ void kill_screen(const char* lcd_msg) {
1249 1249
     #endif
1250 1250
   #endif
1251 1251
 
1252
+  // Refresh the E factor after changing flow
1253
+  inline void _lcd_refresh_e_factor_0() { planner.refresh_e_factor(0); }
1254
+  #if EXTRUDERS > 1
1255
+    inline void _lcd_refresh_e_factor() { planner.refresh_e_factor(active_extruder); }
1256
+    inline void _lcd_refresh_e_factor_1() { planner.refresh_e_factor(1); }
1257
+    #if EXTRUDERS > 2
1258
+      inline void _lcd_refresh_e_factor_2() { planner.refresh_e_factor(2); }
1259
+      #if EXTRUDERS > 3
1260
+        inline void _lcd_refresh_e_factor_3() { planner.refresh_e_factor(3); }
1261
+        #if EXTRUDERS > 4
1262
+          inline void _lcd_refresh_e_factor_4() { planner.refresh_e_factor(4); }
1263
+        #endif // EXTRUDERS > 4
1264
+      #endif // EXTRUDERS > 3
1265
+    #endif // EXTRUDERS > 2
1266
+  #endif // EXTRUDERS > 1
1267
+
1252 1268
   /**
1253 1269
    *
1254 1270
    * "Tune" submenu
@@ -1328,17 +1344,17 @@ void kill_screen(const char* lcd_msg) {
1328 1344
     // Flow [1-5]:
1329 1345
     //
1330 1346
     #if EXTRUDERS == 1
1331
-      MENU_ITEM_EDIT(int3, MSG_FLOW, &planner.flow_percentage[0], 10, 999);
1347
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW, &planner.flow_percentage[0], 10, 999, _lcd_refresh_e_factor_0);
1332 1348
     #else // EXTRUDERS > 1
1333
-      MENU_ITEM_EDIT(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999);
1334
-      MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &planner.flow_percentage[0], 10, 999);
1335
-      MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &planner.flow_percentage[1], 10, 999);
1349
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW, &planner.flow_percentage[active_extruder], 10, 999, _lcd_refresh_e_factor);
1350
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N1, &planner.flow_percentage[0], 10, 999, _lcd_refresh_e_factor_0);
1351
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N2, &planner.flow_percentage[1], 10, 999, _lcd_refresh_e_factor_1);
1336 1352
       #if EXTRUDERS > 2
1337
-        MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &planner.flow_percentage[2], 10, 999);
1353
+        MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N3, &planner.flow_percentage[2], 10, 999, _lcd_refresh_e_factor_2);
1338 1354
         #if EXTRUDERS > 3
1339
-          MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &planner.flow_percentage[3], 10, 999);
1355
+          MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N4, &planner.flow_percentage[3], 10, 999, _lcd_refresh_e_factor_3);
1340 1356
           #if EXTRUDERS > 4
1341
-            MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &planner.flow_percentage[4], 10, 999);
1357
+            MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW MSG_N5, &planner.flow_percentage[4], 10, 999, _lcd_refresh_e_factor_4);
1342 1358
           #endif // EXTRUDERS > 4
1343 1359
         #endif // EXTRUDERS > 3
1344 1360
       #endif // EXTRUDERS > 2

+ 2
- 2
Marlin/src/module/configuration_store.cpp Dosyayı Görüntüle

@@ -138,8 +138,8 @@
138 138
  *  533  M208 R    swap_retract_recover_feedrate_mm_s (float)
139 139
  *
140 140
  * Volumetric Extrusion:                            21 bytes
141
- *  537  M200 D    volumetric_enabled               (bool)
142
- *  538  M200 T D  filament_size                    (float x5) (T0..3)
141
+ *  537  M200 D    parser.volumetric_enabled        (bool)
142
+ *  538  M200 T D  planner.filament_size            (float x5) (T0..3)
143 143
  *
144 144
  * HAVE_TMC2130:                                    22 bytes
145 145
  *  558  M906 X    Stepper X current                (uint16_t)

+ 1
- 1
Marlin/src/module/motion.cpp Dosyayı Görüntüle

@@ -802,7 +802,7 @@ void prepare_move_to_destination() {
802 802
           }
803 803
         #endif // PREVENT_COLD_EXTRUSION
804 804
         #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
805
-          if (FABS(destination[E_AXIS] - current_position[E_AXIS]) > (EXTRUDE_MAXLENGTH) / planner.volumetric_multiplier[active_extruder]) {
805
+          if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
806 806
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
807 807
             SERIAL_ECHO_START();
808 808
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);

+ 7
- 7
Marlin/src/module/planner.cpp Dosyayı Görüntüle

@@ -106,7 +106,8 @@ float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
106 106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
107 107
 
108 108
 // Initialized by settings.load()
109
-float Planner::filament_size[EXTRUDERS],         // As a baseline for the multiplier, filament diameter
109
+float Planner::e_factor[EXTRUDERS],              // The flow percentage and volumetric multiplier combine to scale E movement
110
+      Planner::filament_size[EXTRUDERS],         // As a baseline for the multiplier, filament diameter
110 111
       Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
111 112
 
112 113
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
@@ -546,8 +547,10 @@ inline float calculate_volumetric_multiplier(const float &diameter) {
546 547
 }
547 548
 
548 549
 void Planner::calculate_volumetric_multipliers() {
549
-  for (uint8_t i = 0; i < COUNT(filament_size); i++)
550
+  for (uint8_t i = 0; i < COUNT(filament_size); i++) {
550 551
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
552
+    refresh_e_factor(i);
553
+  }
551 554
 }
552 555
 
553 556
 #if PLANNER_LEVELING
@@ -740,8 +743,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
740 743
 
741 744
   long de = target[E_AXIS] - position[E_AXIS];
742 745
 
743
-  const float e_factor = volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
744
-
745 746
   #if ENABLED(LIN_ADVANCE)
746 747
     float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
747 748
   #endif
@@ -761,8 +762,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
761 762
         }
762 763
       #endif // PREVENT_COLD_EXTRUSION
763 764
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
764
-        const int32_t de_mm = labs(de * e_factor);
765
-        if (de_mm > (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
765
+        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
766 766
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
767 767
           de = 0; // no difference
768 768
           #if ENABLED(LIN_ADVANCE)
@@ -803,7 +803,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
803 803
   #endif
804 804
   if (de < 0) SBI(dm, E_AXIS);
805 805
 
806
-  const float esteps_float = de * e_factor;
806
+  const float esteps_float = de * e_factor[extruder];
807 807
   const int32_t esteps = abs(esteps_float) + 0.5;
808 808
 
809 809
   // Calculate the buffer head after we push this byte

+ 6
- 1
Marlin/src/module/planner.h Dosyayı Görüntüle

@@ -146,7 +146,8 @@ class Planner {
146 146
 
147 147
     static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
148 148
 
149
-    static float filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
149
+    static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
150
+                 filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
150 151
                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
151 152
                                                     // May be auto-adjusted by a filament width sensor
152 153
 
@@ -246,6 +247,10 @@ class Planner {
246 247
     static void reset_acceleration_rates();
247 248
     static void refresh_positioning();
248 249
 
250
+    FORCE_INLINE static void refresh_e_factor(const uint8_t e) {
251
+      e_factor[e] = volumetric_multiplier[e] * flow_percentage[e] * 0.01;
252
+    }
253
+
249 254
     // Manage fans, paste pressure, etc.
250 255
     static void check_axes_activity();
251 256
 

+ 1
- 0
Marlin/src/module/temperature.cpp Dosyayı Görüntüle

@@ -818,6 +818,7 @@ void Temperature::manage_heater() {
818 818
       // the nominal filament diameter then square it to get an area
819 819
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
820 820
       planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
821
+      planner.refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
821 822
     }
822 823
   #endif // FILAMENT_WIDTH_SENSOR
823 824
 

Loading…
İptal
Kaydet