Browse Source

Add pre-calculated planner.e_factor

Scott Lahteine 7 years ago
parent
commit
cba9c1cf9e

+ 1
- 1
Marlin/src/feature/fwretract.cpp View File

130
   set_destination_from_current();
130
   set_destination_from_current();
131
   stepper.synchronize();  // Wait for buffered moves to complete
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
   if (retracting) {
135
   if (retracting) {
136
     // Retract by moving from a faux E position back to the current E position
136
     // Retract by moving from a faux E position back to the current E position

+ 1
- 1
Marlin/src/feature/pause.cpp View File

94
 }
94
 }
95
 
95
 
96
 void do_pause_e_move(const float &length, const float fr) {
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
   set_destination_from_current();
98
   set_destination_from_current();
99
   #if IS_KINEMATIC
99
   #if IS_KINEMATIC
100
     planner.buffer_line_kinematic(destination, fr, active_extruder);
100
     planner.buffer_line_kinematic(destination, fr, active_extruder);

+ 3
- 1
Marlin/src/gcode/config/M221.cpp View File

28
  */
28
  */
29
 void GcodeSuite::M221() {
29
 void GcodeSuite::M221() {
30
   if (get_target_extruder_from_command()) return;
30
   if (get_target_extruder_from_command()) return;
31
-  if (parser.seenval('S'))
31
+  if (parser.seenval('S')) {
32
     planner.flow_percentage[target_extruder] = parser.value_int();
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 View File

1249
     #endif
1249
     #endif
1250
   #endif
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
    * "Tune" submenu
1270
    * "Tune" submenu
1328
     // Flow [1-5]:
1344
     // Flow [1-5]:
1329
     //
1345
     //
1330
     #if EXTRUDERS == 1
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
     #else // EXTRUDERS > 1
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
       #if EXTRUDERS > 2
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
         #if EXTRUDERS > 3
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
           #if EXTRUDERS > 4
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
           #endif // EXTRUDERS > 4
1358
           #endif // EXTRUDERS > 4
1343
         #endif // EXTRUDERS > 3
1359
         #endif // EXTRUDERS > 3
1344
       #endif // EXTRUDERS > 2
1360
       #endif // EXTRUDERS > 2

+ 2
- 2
Marlin/src/module/configuration_store.cpp View File

138
  *  533  M208 R    swap_retract_recover_feedrate_mm_s (float)
138
  *  533  M208 R    swap_retract_recover_feedrate_mm_s (float)
139
  *
139
  *
140
  * Volumetric Extrusion:                            21 bytes
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
  * HAVE_TMC2130:                                    22 bytes
144
  * HAVE_TMC2130:                                    22 bytes
145
  *  558  M906 X    Stepper X current                (uint16_t)
145
  *  558  M906 X    Stepper X current                (uint16_t)

+ 1
- 1
Marlin/src/module/motion.cpp View File

802
           }
802
           }
803
         #endif // PREVENT_COLD_EXTRUSION
803
         #endif // PREVENT_COLD_EXTRUSION
804
         #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
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
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
806
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
807
             SERIAL_ECHO_START();
807
             SERIAL_ECHO_START();
808
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
808
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);

+ 7
- 7
Marlin/src/module/planner.cpp View File

106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
107
 
107
 
108
 // Initialized by settings.load()
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
       Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
111
       Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
111
 
112
 
112
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
113
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
546
 }
547
 }
547
 
548
 
548
 void Planner::calculate_volumetric_multipliers() {
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
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
551
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
552
+    refresh_e_factor(i);
553
+  }
551
 }
554
 }
552
 
555
 
553
 #if PLANNER_LEVELING
556
 #if PLANNER_LEVELING
740
 
743
 
741
   long de = target[E_AXIS] - position[E_AXIS];
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
   #if ENABLED(LIN_ADVANCE)
746
   #if ENABLED(LIN_ADVANCE)
746
     float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
747
     float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
747
   #endif
748
   #endif
761
         }
762
         }
762
       #endif // PREVENT_COLD_EXTRUSION
763
       #endif // PREVENT_COLD_EXTRUSION
763
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
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
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
766
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
767
           de = 0; // no difference
767
           de = 0; // no difference
768
           #if ENABLED(LIN_ADVANCE)
768
           #if ENABLED(LIN_ADVANCE)
803
   #endif
803
   #endif
804
   if (de < 0) SBI(dm, E_AXIS);
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
   const int32_t esteps = abs(esteps_float) + 0.5;
807
   const int32_t esteps = abs(esteps_float) + 0.5;
808
 
808
 
809
   // Calculate the buffer head after we push this byte
809
   // Calculate the buffer head after we push this byte

+ 6
- 1
Marlin/src/module/planner.h View File

146
 
146
 
147
     static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
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
                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
151
                  volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
151
                                                     // May be auto-adjusted by a filament width sensor
152
                                                     // May be auto-adjusted by a filament width sensor
152
 
153
 
246
     static void reset_acceleration_rates();
247
     static void reset_acceleration_rates();
247
     static void refresh_positioning();
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
     // Manage fans, paste pressure, etc.
254
     // Manage fans, paste pressure, etc.
250
     static void check_axes_activity();
255
     static void check_axes_activity();
251
 
256
 

+ 1
- 0
Marlin/src/module/temperature.cpp View File

818
       // the nominal filament diameter then square it to get an area
818
       // the nominal filament diameter then square it to get an area
819
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
819
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
820
       planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
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
   #endif // FILAMENT_WIDTH_SENSOR
823
   #endif // FILAMENT_WIDTH_SENSOR
823
 
824
 

Loading…
Cancel
Save