Browse Source

Merge pull request #8356 from tcm0116/2.0.x-M600

[2.0.x] Normalize load/unload length in M600
Scott Lahteine 7 years ago
parent
commit
36426af564
No account linked to committer's email address

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

@@ -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 View File

@@ -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;
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 View File

@@ -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 View File

@@ -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 View File

@@ -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)

+ 11
- 9
Marlin/src/module/motion.cpp View File

@@ -790,26 +790,28 @@ void prepare_move_to_destination() {
790 790
   clamp_to_software_endstops(destination);
791 791
   gcode.refresh_cmd_timeout();
792 792
 
793
-  #if ENABLED(PREVENT_COLD_EXTRUSION)
793
+  #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
794 794
 
795 795
     if (!DEBUGGING(DRYRUN)) {
796 796
       if (destination[E_AXIS] != current_position[E_AXIS]) {
797
-        if (thermalManager.tooColdToExtrude(active_extruder)) {
798
-          current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
799
-          SERIAL_ECHO_START();
800
-          SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
801
-        }
797
+        #if ENABLED(PREVENT_COLD_EXTRUSION)
798
+          if (thermalManager.tooColdToExtrude(active_extruder)) {
799
+            current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
800
+            SERIAL_ECHO_START();
801
+            SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
802
+          }
803
+        #endif // PREVENT_COLD_EXTRUSION
802 804
         #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
803
-          if (destination[E_AXIS] - current_position[E_AXIS] > EXTRUDE_MAXLENGTH) {
805
+          if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
804 806
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
805 807
             SERIAL_ECHO_START();
806 808
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
807 809
           }
808
-        #endif
810
+        #endif // PREVENT_LENGTHY_EXTRUDE
809 811
       }
810 812
     }
811 813
 
812
-  #endif
814
+  #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
813 815
 
814 816
   if (
815 817
     #if UBL_DELTA // Also works for CARTESIAN (smaller segments follow mesh more closely)

+ 23
- 18
Marlin/src/module/planner.cpp View File

@@ -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
@@ -741,23 +744,25 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
741 744
   long de = target[E_AXIS] - position[E_AXIS];
742 745
 
743 746
   #if ENABLED(LIN_ADVANCE)
744
-    float de_float = e - position_float[E_AXIS];
747
+    float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
745 748
   #endif
746 749
 
747
-  #if ENABLED(PREVENT_COLD_EXTRUSION)
750
+  #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
748 751
     if (de) {
749
-      if (thermalManager.tooColdToExtrude(extruder)) {
750
-        position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
751
-        de = 0; // no difference
752
-        #if ENABLED(LIN_ADVANCE)
753
-          position_float[E_AXIS] = e;
754
-          de_float = 0;
755
-        #endif
756
-        SERIAL_ECHO_START();
757
-        SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
758
-      }
752
+      #if ENABLED(PREVENT_COLD_EXTRUSION)
753
+        if (thermalManager.tooColdToExtrude(extruder)) {
754
+          position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
755
+          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();
761
+          SERIAL_ECHOLNPGM(MSG_ERR_COLD_EXTRUDE_STOP);
762
+        }
763
+      #endif // PREVENT_COLD_EXTRUSION
759 764
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
760
-        if (labs(de) > (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
761 766
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
762 767
           de = 0; // no difference
763 768
           #if ENABLED(LIN_ADVANCE)
@@ -767,9 +772,9 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
767 772
           SERIAL_ECHO_START();
768 773
           SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
769 774
         }
770
-      #endif
775
+      #endif // PREVENT_LENGTHY_EXTRUDE
771 776
     }
772
-  #endif
777
+  #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
773 778
 
774 779
   // Compute direction bit-mask for this block
775 780
   uint8_t dm = 0;
@@ -798,7 +803,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
798 803
   #endif
799 804
   if (de < 0) SBI(dm, E_AXIS);
800 805
 
801
-  const float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
806
+  const float esteps_float = de * e_factor[extruder];
802 807
   const int32_t esteps = abs(esteps_float) + 0.5;
803 808
 
804 809
   // Calculate the buffer head after we push this byte

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

@@ -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 View File

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

Loading…
Cancel
Save