Browse Source

Add volumetric extrusion limit (#17017)

MoellerDi 4 years ago
parent
commit
bac760207c
No account linked to committer's email address

+ 13
- 1
Marlin/Configuration_adv.h View File

@@ -2993,9 +2993,21 @@
2993 2993
    * Activate to make volumetric extrusion the default method,
2994 2994
    * with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter.
2995 2995
    *
2996
-   * M200 D0 to disable, M200 Dn to set a new diameter.
2996
+   * M200 D0 to disable, M200 Dn to set a new diameter (and enable volumetric).
2997
+   * M200 S0/S1 to disable/enable volumetric extrusion.
2997 2998
    */
2998 2999
   //#define VOLUMETRIC_DEFAULT_ON
3000
+
3001
+  //#define VOLUMETRIC_EXTRUDER_LIMIT
3002
+  #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
3003
+    /**
3004
+     * Default volumetric extrusion limit in cubic mm per second (mm^3/sec).
3005
+     * This factory setting applies to all extruders.
3006
+     * Use 'M200 [T<extruder>] L<limit>' to override and 'M502' to reset.
3007
+     * A non-zero value activates Volume-based Extrusion Limiting.
3008
+     */
3009
+    #define DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT 0.00      // (mm^3/sec)
3010
+  #endif
2999 3011
 #endif
3000 3012
 
3001 3013
 /**

+ 27
- 6
Marlin/src/gcode/config/M200-M205.cpp View File

@@ -30,21 +30,42 @@
30 30
    * M200: Set filament diameter and set E axis units to cubic units
31 31
    *
32 32
    *    T<extruder> - Optional extruder number. Current extruder if omitted.
33
-   *    D<linear> - Diameter of the filament. Use "D0" to switch back to linear units on the E axis.
33
+   *    D<linear>   - Set filament diameter and enable. D0 disables volumetric.
34
+   *    S<bool>     - Turn volumetric ON or OFF.
35
+   *    L<float>    - Volumetric extruder limit (in mm^3/sec). L0 disables the limit.
34 36
    */
35 37
   void GcodeSuite::M200() {
36 38
 
37 39
     const int8_t target_extruder = get_target_extruder_from_command();
38 40
     if (target_extruder < 0) return;
39 41
 
40
-    if (parser.seen('D')) {
41
-      // setting any extruder filament size disables volumetric on the assumption that
42
-      // slicers either generate in extruder values as cubic mm or as as filament feeds
43
-      // for all extruders
42
+    bool vol_enable = parser.volumetric_enabled,
43
+         can_enable = true;
44
+
45
+    if (parser.seenval('D')) {
44 46
       const float dval = parser.value_linear_units();
45
-      if ( (parser.volumetric_enabled = (dval != 0)) )
47
+      if (dval) { // Set filament size for volumetric calculation
46 48
         planner.set_filament_size(target_extruder, dval);
49
+        vol_enable = true;    // Dn = enable for compatibility
50
+      }
51
+      else
52
+        can_enable = false;   // D0 = disable for compatibility
47 53
     }
54
+
55
+    // Enable or disable with S1 / S0
56
+    parser.volumetric_enabled = can_enable && parser.boolval('S', vol_enable);
57
+
58
+    #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
59
+      if (parser.seenval('L')) {
60
+        // Set volumetric limit (in mm^3/sec)
61
+        const float lval = parser.value_float();
62
+        if (WITHIN(lval, 0, 20))
63
+          planner.set_volumetric_extruder_limit(target_extruder, lval);
64
+        else
65
+          SERIAL_ECHOLNPGM("?L value out of range (0-20).");
66
+      }
67
+    #endif
68
+    
48 69
     planner.calculate_volumetric_multipliers();
49 70
   }
50 71
 

+ 7
- 0
Marlin/src/inc/Conditionals_post.h View File

@@ -261,6 +261,13 @@
261 261
 #endif
262 262
 
263 263
 /**
264
+ * Provide a DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT in case NO_VOLUMETRICS is enabled
265
+ */
266
+#ifndef DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT
267
+  #define DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT 0.00
268
+#endif
269
+
270
+/**
264 271
  * LCD Contrast for Graphical Displays
265 272
  */
266 273
 #if ENABLED(CARTESIO_UI)

+ 11
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -1480,6 +1480,17 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
1480 1480
 #endif
1481 1481
 
1482 1482
 /**
1483
+ * Volumetric Extruder Limit
1484
+ */
1485
+#if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
1486
+  #if ENABLED(NO_VOLUMETRICS)
1487
+    #error "VOLUMETRIC_EXTRUDER_LIMIT requires NO_VOLUMETRICS to be disabled."
1488
+  #elif MIN_STEPS_PER_SEGMENT > 1
1489
+    #error "VOLUMETRIC_EXTRUDER_LIMIT is not compatible with MIN_STEPS_PER_SEGMENT greater than 1."
1490
+  #endif
1491
+#endif
1492
+
1493
+/**
1483 1494
  * ULTIPANEL encoder
1484 1495
  */
1485 1496
 #if ENABLED(ULTIPANEL) && NONE(NEWPANEL, SR_LCD_2W_NL) && !defined(SHIFT_CLK)

+ 2
- 0
Marlin/src/lcd/language/language_en.h View File

@@ -317,6 +317,8 @@ namespace Language_en {
317 317
   PROGMEM Language_Str MSG_MOTION                          = _UxGT("Motion");
318 318
   PROGMEM Language_Str MSG_FILAMENT                        = _UxGT("Filament");
319 319
   PROGMEM Language_Str MSG_VOLUMETRIC_ENABLED              = _UxGT("E in mm³");
320
+  PROGMEM Language_Str MSG_VOLUMETRIC_LIMIT                = _UxGT("E Limit in mm³");
321
+  PROGMEM Language_Str MSG_VOLUMETRIC_LIMIT_E              = _UxGT("E Limit *");
320 322
   PROGMEM Language_Str MSG_FILAMENT_DIAM                   = _UxGT("Fil. Dia.");
321 323
   PROGMEM Language_Str MSG_FILAMENT_DIAM_E                 = _UxGT("Fil. Dia. *");
322 324
   PROGMEM Language_Str MSG_FILAMENT_UNLOAD                 = _UxGT("Unload mm");

+ 8
- 0
Marlin/src/lcd/menu/menu_advanced.cpp View File

@@ -117,6 +117,14 @@ void menu_cancelobject();
117 117
     #if DISABLED(NO_VOLUMETRICS)
118 118
       EDIT_ITEM(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers);
119 119
 
120
+      #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
121
+        EDIT_ITEM_FAST(float42_52, MSG_VOLUMETRIC_LIMIT, &planner.volumetric_extruder_limit[active_extruder], 0.0f, 20.0f, planner.calculate_volumetric_extruder_limits);
122
+        #if EXTRUDERS > 1
123
+          LOOP_L_N(n, EXTRUDERS)
124
+            EDIT_ITEM_FAST_N(float42_52, n, MSG_VOLUMETRIC_LIMIT_E, &planner.volumetric_extruder_limit[n], 0.0f, 20.00f, planner.calculate_volumetric_extruder_limits);
125
+        #endif
126
+      #endif
127
+
120 128
       if (parser.volumetric_enabled) {
121 129
         EDIT_ITEM_FAST(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
122 130
         #if EXTRUDERS > 1

+ 39
- 14
Marlin/src/module/configuration_store.cpp View File

@@ -37,7 +37,7 @@
37 37
  */
38 38
 
39 39
 // Change EEPROM version if the structure changes
40
-#define EEPROM_VERSION "V79"
40
+#define EEPROM_VERSION "V80"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -320,8 +320,9 @@ typedef struct SettingsDataStruct {
320 320
   //
321 321
   // !NO_VOLUMETRIC
322 322
   //
323
-  bool parser_volumetric_enabled;                       // M200 D  parser.volumetric_enabled
323
+  bool parser_volumetric_enabled;                       // M200 S  parser.volumetric_enabled
324 324
   float planner_filament_size[EXTRUDERS];               // M200 T D  planner.filament_size[]
325
+  float planner_volumetric_extruder_limit[EXTRUDERS];   // M200 T L  planner.volumetric_extruder_limit[]
325 326
 
326 327
   //
327 328
   // HAS_TRINAMIC_CONFIG
@@ -935,12 +936,20 @@ void MarlinSettings::postprocess() {
935 936
 
936 937
         EEPROM_WRITE(parser.volumetric_enabled);
937 938
         EEPROM_WRITE(planner.filament_size);
939
+        #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
940
+          EEPROM_WRITE(planner.volumetric_extruder_limit);
941
+        #else
942
+          dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
943
+          for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
944
+        #endif
938 945
 
939 946
       #else
940 947
 
941 948
         const bool volumetric_enabled = false;
942
-        dummyf = DEFAULT_NOMINAL_FILAMENT_DIA;
943 949
         EEPROM_WRITE(volumetric_enabled);
950
+        dummyf = DEFAULT_NOMINAL_FILAMENT_DIA;
951
+        for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
952
+        dummyf = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
944 953
         for (uint8_t q = EXTRUDERS; q--;) EEPROM_WRITE(dummyf);
945 954
 
946 955
       #endif
@@ -1787,6 +1796,9 @@ void MarlinSettings::postprocess() {
1787 1796
         struct {
1788 1797
           bool volumetric_enabled;
1789 1798
           float filament_size[EXTRUDERS];
1799
+          #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
1800
+            float volumetric_extruder_limit[EXTRUDERS];
1801
+          #endif
1790 1802
         } storage;
1791 1803
 
1792 1804
         _FIELD_TEST(parser_volumetric_enabled);
@@ -1796,6 +1808,9 @@ void MarlinSettings::postprocess() {
1796 1808
           if (!validating) {
1797 1809
             parser.volumetric_enabled = storage.volumetric_enabled;
1798 1810
             COPY(planner.filament_size, storage.filament_size);
1811
+            #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
1812
+              COPY(planner.volumetric_extruder_limit, storage.volumetric_extruder_limit);
1813
+            #endif
1799 1814
           }
1800 1815
         #endif
1801 1816
       }
@@ -2598,6 +2613,10 @@ void MarlinSettings::reset() {
2598 2613
     parser.volumetric_enabled = ENABLED(VOLUMETRIC_DEFAULT_ON);
2599 2614
     LOOP_L_N(q, COUNT(planner.filament_size))
2600 2615
       planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
2616
+    #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
2617
+      LOOP_L_N(q, COUNT(planner.volumetric_extruder_limit))
2618
+        planner.volumetric_extruder_limit[q] = DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT;
2619
+    #endif
2601 2620
   #endif
2602 2621
 
2603 2622
   endstops.enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
@@ -2750,7 +2769,7 @@ void MarlinSettings::reset() {
2750 2769
 
2751 2770
     SERIAL_EOL();
2752 2771
 
2753
-    #if DISABLED(NO_VOLUMETRICS)
2772
+    #if EXTRUDERS && DISABLED(NO_VOLUMETRICS)
2754 2773
 
2755 2774
       /**
2756 2775
        * Volumetric extrusion M200
@@ -2765,20 +2784,26 @@ void MarlinSettings::reset() {
2765 2784
 
2766 2785
       #if EXTRUDERS == 1
2767 2786
         CONFIG_ECHO_START();
2768
-        SERIAL_ECHOLNPAIR("  M200 D", LINEAR_UNIT(planner.filament_size[0]));
2769
-      #elif EXTRUDERS
2787
+        SERIAL_ECHOLNPAIR("  M200 S", int(parser.volumetric_enabled)
2788
+                              , " D", LINEAR_UNIT(planner.filament_size[0]),
2789
+                              #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
2790
+                                , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[0])
2791
+                              #endif
2792
+                         );
2793
+      #else
2770 2794
         LOOP_L_N(i, EXTRUDERS) {
2771 2795
           CONFIG_ECHO_START();
2772
-          SERIAL_ECHOPGM("  M200");
2773
-          if (i) SERIAL_ECHOPAIR_P(SP_T_STR, int(i));
2774
-          SERIAL_ECHOLNPAIR(" D", LINEAR_UNIT(planner.filament_size[i]));
2796
+          SERIAL_ECHOLNPAIR("  M200 T", int(i)
2797
+                                , " D", LINEAR_UNIT(planner.filament_size[i])
2798
+                                #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
2799
+                                  , " L", LINEAR_UNIT(planner.volumetric_extruder_limit[i])
2800
+                                #endif
2801
+                           );
2775 2802
         }
2803
+        CONFIG_ECHO_START();
2804
+        SERIAL_ECHOLNPAIR("  M200 S", int(parser.volumetric_enabled));
2776 2805
       #endif
2777
-
2778
-      if (!parser.volumetric_enabled)
2779
-        CONFIG_ECHO_MSG("  M200 D0");
2780
-
2781
-    #endif // !NO_VOLUMETRICS
2806
+    #endif // EXTRUDERS && !NO_VOLUMETRICS
2782 2807
 
2783 2808
     CONFIG_ECHO_HEADING("Steps per unit:");
2784 2809
     report_M92(!forReplay);

+ 47
- 1
Marlin/src/module/planner.cpp View File

@@ -171,6 +171,11 @@ float Planner::steps_to_mm[XYZE_N];             // (mm) Millimeters per step
171 171
         Planner::volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
172 172
 #endif
173 173
 
174
+#if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
175
+  float Planner::volumetric_extruder_limit[EXTRUDERS],          // max mm^3/sec the extruder is able to handle
176
+        Planner::volumetric_extruder_feedrate_limit[EXTRUDERS]; // pre calculated extruder feedrate limit based on volumetric_extruder_limit; pre-calculated to reduce computation in the planner
177
+#endif
178
+
174 179
 #if HAS_LEVELING
175 180
   bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
176 181
   #if ABL_PLANAR
@@ -1407,10 +1412,28 @@ void Planner::check_axes_activity() {
1407 1412
       volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
1408 1413
       refresh_e_factor(i);
1409 1414
     }
1415
+    #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
1416
+      calculate_volumetric_extruder_limits(); // update volumetric_extruder_limits as well.
1417
+    #endif
1410 1418
   }
1411 1419
 
1412 1420
 #endif // !NO_VOLUMETRICS
1413 1421
 
1422
+#if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
1423
+
1424
+  /**
1425
+   * Convert volumetric based limits into pre calculated extruder feedrate limits.
1426
+   */
1427
+  void Planner::calculate_volumetric_extruder_limit(const uint8_t e) {
1428
+    const float &lim = volumetric_extruder_limit[e], &siz = filament_size[e];
1429
+    volumetric_extruder_feedrate_limit[e] = (lim && siz) ? lim / CIRCLE_AREA(siz * 0.5f) : 0;
1430
+  }
1431
+  void Planner::calculate_volumetric_extruder_limits() {
1432
+    LOOP_L_N(e, EXTRUDERS) calculate_volumetric_extruder_limit(e);
1433
+  }
1434
+
1435
+#endif
1436
+
1414 1437
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
1415 1438
   /**
1416 1439
    * Convert the ratio value given by the filament width sensor
@@ -2077,10 +2100,33 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2077 2100
         if (mixer.get_current_vtool() == MIXER_AUTORETRACT_TOOL)
2078 2101
           current_speed.e *= MIXING_STEPPERS;
2079 2102
       #endif
2103
+
2080 2104
       const feedRate_t cs = ABS(current_speed.e),
2081 2105
                    max_fr = settings.max_feedrate_mm_s[E_AXIS_N(extruder)]
2082 2106
                             * TERN(HAS_MIXER_SYNC_CHANNEL, MIXING_STEPPERS, 1);
2083
-      if (cs > max_fr) NOMORE(speed_factor, max_fr / cs);
2107
+
2108
+      if (cs > max_fr) NOMORE(speed_factor, max_fr / cs); //respect max feedrate on any movement (doesn't matter if E axes only or not)
2109
+      
2110
+      #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
2111
+        const feedRate_t max_vfr = volumetric_extruder_feedrate_limit[extruder] 
2112
+                                   * TERN(HAS_MIXER_SYNC_CHANNEL, MIXING_STEPPERS, 1);
2113
+
2114
+        // TODO: Doesn't work properly for joined segments. Set MIN_STEPS_PER_SEGMENT 1 as workaround.
2115
+
2116
+        if (block->steps.a || block->steps.b || block->steps.c) {
2117
+
2118
+          if (max_vfr > 0 && cs > max_vfr) {
2119
+            NOMORE(speed_factor, max_vfr / cs); // respect volumetric extruder limit (if any)
2120
+            /* <-- add a slash to enable
2121
+            SERIAL_ECHOPAIR("volumetric extruder limit enforced: ", (cs * CIRCLE_AREA(filament_size[extruder] * 0.5f)));
2122
+            SERIAL_ECHOPAIR(" mm^3/s (", cs);
2123
+            SERIAL_ECHOPAIR(" mm/s) limited to ", (max_vfr * CIRCLE_AREA(filament_size[extruder] * 0.5f)));
2124
+            SERIAL_ECHOPAIR(" mm^3/s (", max_vfr);
2125
+            SERIAL_ECHOLNPGM(" mm/s)");
2126
+            //*/
2127
+          }
2128
+        }
2129
+      #endif
2084 2130
     }
2085 2131
   #endif
2086 2132
 

+ 22
- 3
Marlin/src/module/planner.h View File

@@ -333,6 +333,11 @@ class Planner {
333 333
                                                       // May be auto-adjusted by a filament width sensor
334 334
     #endif
335 335
 
336
+    #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
337
+      static float volumetric_extruder_limit[EXTRUDERS],          // Maximum mm^3/sec the extruder can handle
338
+                   volumetric_extruder_feedrate_limit[EXTRUDERS]; // Feedrate limit (mm/s) calculated from volume limit
339
+    #endif
340
+
336 341
     static planner_settings_t settings;
337 342
 
338 343
     #if ENABLED(LASER_POWER_INLINE)
@@ -473,9 +478,6 @@ class Planner {
473 478
     // Manage fans, paste pressure, etc.
474 479
     static void check_axes_activity();
475 480
 
476
-    // Update multipliers based on new diameter measurements
477
-    static void calculate_volumetric_multipliers();
478
-
479 481
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
480 482
       void apply_filament_width_sensor(const int8_t encoded_ratio);
481 483
 
@@ -489,8 +491,18 @@ class Planner {
489 491
 
490 492
     #if DISABLED(NO_VOLUMETRICS)
491 493
 
494
+      // Update multipliers based on new diameter measurements
495
+      static void calculate_volumetric_multipliers();
496
+  
497
+      #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
498
+        // Update pre calculated extruder feedrate limits based on volumetric values
499
+        static void calculate_volumetric_extruder_limit(const uint8_t e);
500
+        static void calculate_volumetric_extruder_limits();
501
+      #endif
502
+
492 503
       FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
493 504
         filament_size[e] = v;
505
+        if (v > 0) volumetric_area_nominal = CIRCLE_AREA(v * 0.5); //TODO: should it be per extruder
494 506
         // make sure all extruders have some sane value for the filament size
495 507
         LOOP_L_N(i, COUNT(filament_size))
496 508
           if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
@@ -498,6 +510,13 @@ class Planner {
498 510
 
499 511
     #endif
500 512
 
513
+    #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
514
+      FORCE_INLINE static void set_volumetric_extruder_limit(const uint8_t e, const float &v) {
515
+        volumetric_extruder_limit[e] = v;
516
+        calculate_volumetric_extruder_limit(e);
517
+      }
518
+    #endif
519
+
501 520
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
502 521
 
503 522
       /**

Loading…
Cancel
Save