Ver código fonte

Move Volumetric methods to Planner

Scott Lahteine 7 anos atrás
pai
commit
a10451ceed

+ 0
- 13
Marlin/src/Marlin.cpp Ver arquivo

@@ -159,9 +159,6 @@ bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false };
159 159
   TempUnit input_temp_units = TEMPUNIT_C;
160 160
 #endif
161 161
 
162
-// Initialized by settings.load()
163
-float filament_size[EXTRUDERS], volumetric_multiplier[EXTRUDERS];
164
-
165 162
 #if FAN_COUNT > 0
166 163
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
167 164
   #if ENABLED(PROBING_FANS_OFF)
@@ -336,16 +333,6 @@ void quickstop_stepper() {
336 333
 
337 334
 #endif // FILAMENT_RUNOUT_SENSOR
338 335
 
339
-float calculate_volumetric_multiplier(const float diameter) {
340
-  if (!parser.volumetric_enabled || diameter == 0) return 1.0;
341
-  return 1.0 / (M_PI * sq(diameter * 0.5));
342
-}
343
-
344
-void calculate_volumetric_multipliers() {
345
-  for (uint8_t i = 0; i < COUNT(filament_size); i++)
346
-    volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
347
-}
348
-
349 336
 void enable_all_steppers() {
350 337
   enable_X();
351 338
   enable_Y();

+ 0
- 5
Marlin/src/Marlin.h Ver arquivo

@@ -174,9 +174,6 @@ extern bool Running;
174 174
 inline bool IsRunning() { return  Running; }
175 175
 inline bool IsStopped() { return !Running; }
176 176
 
177
-extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
178
-extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
179
-
180 177
 extern bool axis_known_position[XYZ];
181 178
 extern bool axis_homed[XYZ];
182 179
 extern volatile bool wait_for_heatup;
@@ -223,8 +220,6 @@ extern millis_t max_inactive_time, stepper_inactive_time;
223 220
   extern int lpq_len;
224 221
 #endif
225 222
 
226
-void calculate_volumetric_multipliers();
227
-
228 223
 bool pin_is_protected(const int8_t pin);
229 224
 
230 225
 #endif // __MARLIN_H__

+ 2
- 2
Marlin/src/feature/fwretract.cpp Ver arquivo

@@ -124,7 +124,7 @@ void FWRetract::retract(const bool retracting
124 124
 
125 125
     // Retract by moving from a faux E position back to the current E position
126 126
     feedrate_mm_s = retract_feedrate_mm_s;
127
-    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / volumetric_multiplier[active_extruder];
127
+    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / planner.volumetric_multiplier[active_extruder];
128 128
     sync_plan_position_e();
129 129
     prepare_move_to_destination();
130 130
 
@@ -149,7 +149,7 @@ void FWRetract::retract(const bool retracting
149 149
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
150 150
 
151 151
     const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
152
-    current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder];
152
+    current_position[E_AXIS] -= move_e / planner.volumetric_multiplier[active_extruder];
153 153
     sync_plan_position_e();
154 154
 
155 155
     prepare_move_to_destination();  // Recover E

+ 4
- 8
Marlin/src/gcode/config/M200.cpp Ver arquivo

@@ -22,6 +22,7 @@
22 22
 
23 23
 #include "../gcode.h"
24 24
 #include "../../Marlin.h"
25
+#include "../../module/planner.h"
25 26
 
26 27
 /**
27 28
  * M200: Set filament diameter and set E axis units to cubic units
@@ -37,13 +38,8 @@ void GcodeSuite::M200() {
37 38
     // setting any extruder filament size disables volumetric on the assumption that
38 39
     // slicers either generate in extruder values as cubic mm or as as filament feeds
39 40
     // for all extruders
40
-    parser.volumetric_enabled = (parser.value_linear_units() != 0.0);
41
-    if (parser.volumetric_enabled) {
42
-      filament_size[target_extruder] = parser.value_linear_units();
43
-      // make sure all extruders have some sane value for the filament size
44
-      for (uint8_t i = 0; i < COUNT(filament_size); i++)
45
-        if (! filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
46
-    }
41
+    if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
42
+      planner.set_filament_size(target_extruder, parser.value_linear_units());
47 43
   }
48
-  calculate_volumetric_multipliers();
44
+  planner.calculate_volumetric_multipliers();
49 45
 }

+ 1
- 1
Marlin/src/gcode/feature/filwidth/M404-M407.cpp Ver arquivo

@@ -76,7 +76,7 @@ void GcodeSuite::M405() {
76 76
  */
77 77
 void GcodeSuite::M406() {
78 78
   filament_sensor = false;
79
-  calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
79
+  planner.calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
80 80
 }
81 81
 
82 82
 /**

+ 7
- 7
Marlin/src/lcd/ultralcd.cpp Ver arquivo

@@ -3442,20 +3442,20 @@ void kill_screen(const char* lcd_msg) {
3442 3442
       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
3443 3443
     #endif
3444 3444
 
3445
-    MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, calculate_volumetric_multipliers);
3445
+    MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers);
3446 3446
 
3447 3447
     if (parser.volumetric_enabled) {
3448 3448
       #if EXTRUDERS == 1
3449
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
3449
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3450 3450
       #else // EXTRUDERS > 1
3451
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
3452
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
3451
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3452
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3453 3453
         #if EXTRUDERS > 2
3454
-          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
3454
+          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3455 3455
           #if EXTRUDERS > 3
3456
-            MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
3456
+            MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3457 3457
             #if EXTRUDERS > 4
3458
-              MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
3458
+              MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3459 3459
             #endif // EXTRUDERS > 4
3460 3460
           #endif // EXTRUDERS > 3
3461 3461
         #endif // EXTRUDERS > 2

+ 2
- 2
Marlin/src/lcd/ultralcd_impl_DOGM.h Ver arquivo

@@ -637,7 +637,7 @@ static void lcd_implementation_status_screen() {
637 637
     strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
638 638
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
639 639
       strcpy(wstring, ftostr12ns(filament_width_meas));
640
-      strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
640
+      strcpy(mstring, itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
641 641
     #endif
642 642
   }
643 643
 
@@ -726,7 +726,7 @@ static void lcd_implementation_status_screen() {
726 726
         lcd_print(ftostr12ns(filament_width_meas));
727 727
         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL));
728 728
         u8g.print(':');
729
-        lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
729
+        lcd_print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
730 730
         u8g.print('%');
731 731
       }
732 732
     #else

+ 1
- 1
Marlin/src/lcd/ultralcd_impl_HD44780.h Ver arquivo

@@ -853,7 +853,7 @@ static void lcd_implementation_status_screen() {
853 853
       lcd_printPGM(PSTR("Dia "));
854 854
       lcd.print(ftostr12ns(filament_width_meas));
855 855
       lcd_printPGM(PSTR(" V"));
856
-      lcd.print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
856
+      lcd.print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
857 857
       lcd.write('%');
858 858
       return;
859 859
     }

+ 11
- 11
Marlin/src/module/configuration_store.cpp Ver arquivo

@@ -138,7 +138,7 @@
138 138
  *
139 139
  * Volumetric Extrusion:                            21 bytes
140 140
  *  537  M200 D    parser.volumetric_enabled        (bool)
141
- *  538  M200 T D  filament_size                    (float x5) (T0..3)
141
+ *  538  M200 T D  planner.filament_size            (float x5) (T0..3)
142 142
  *
143 143
  * HAVE_TMC2130:                                    20 bytes
144 144
  *  558  M906 X    Stepper X current                (uint16_t)
@@ -224,7 +224,7 @@ void MarlinSettings::postprocess() {
224 224
     thermalManager.updatePID();
225 225
   #endif
226 226
 
227
-  calculate_volumetric_multipliers();
227
+  planner.calculate_volumetric_multipliers();
228 228
 
229 229
   #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
230 230
     // Software endstops depend on home_offset
@@ -509,7 +509,7 @@ void MarlinSettings::postprocess() {
509 509
 
510 510
     // Save filament sizes
511 511
     for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
512
-      if (q < COUNT(filament_size)) dummy = filament_size[q];
512
+      if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
513 513
       EEPROM_WRITE(dummy);
514 514
     }
515 515
 
@@ -895,7 +895,7 @@ void MarlinSettings::postprocess() {
895 895
 
896 896
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
897 897
         EEPROM_READ(dummy);
898
-        if (q < COUNT(filament_size)) filament_size[q] = dummy;
898
+        if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
899 899
       }
900 900
 
901 901
       uint16_t val;
@@ -1260,8 +1260,8 @@ void MarlinSettings::reset() {
1260 1260
       false
1261 1261
     #endif
1262 1262
   ;
1263
-  for (uint8_t q = 0; q < COUNT(filament_size); q++)
1264
-    filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
1263
+  for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
1264
+    planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
1265 1265
 
1266 1266
   endstops.enable_globally(
1267 1267
     #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
@@ -1388,23 +1388,23 @@ void MarlinSettings::reset() {
1388 1388
     }
1389 1389
 
1390 1390
     CONFIG_ECHO_START;
1391
-    SERIAL_ECHOPAIR("  M200 D", filament_size[0]);
1391
+    SERIAL_ECHOPAIR("  M200 D", planner.filament_size[0]);
1392 1392
     SERIAL_EOL();
1393 1393
     #if EXTRUDERS > 1
1394 1394
       CONFIG_ECHO_START;
1395
-      SERIAL_ECHOPAIR("  M200 T1 D", filament_size[1]);
1395
+      SERIAL_ECHOPAIR("  M200 T1 D", planner.filament_size[1]);
1396 1396
       SERIAL_EOL();
1397 1397
       #if EXTRUDERS > 2
1398 1398
         CONFIG_ECHO_START;
1399
-        SERIAL_ECHOPAIR("  M200 T2 D", filament_size[2]);
1399
+        SERIAL_ECHOPAIR("  M200 T2 D", planner.filament_size[2]);
1400 1400
         SERIAL_EOL();
1401 1401
         #if EXTRUDERS > 3
1402 1402
           CONFIG_ECHO_START;
1403
-          SERIAL_ECHOPAIR("  M200 T3 D", filament_size[3]);
1403
+          SERIAL_ECHOPAIR("  M200 T3 D", planner.filament_size[3]);
1404 1404
           SERIAL_EOL();
1405 1405
           #if EXTRUDERS > 4
1406 1406
             CONFIG_ECHO_START;
1407
-            SERIAL_ECHOPAIR("  M200 T4 D", filament_size[4]);
1407
+            SERIAL_ECHOPAIR("  M200 T4 D", planner.filament_size[4]);
1408 1408
             SERIAL_EOL();
1409 1409
           #endif // EXTRUDERS > 4
1410 1410
         #endif // EXTRUDERS > 3

+ 14
- 0
Marlin/src/module/planner.cpp Ver arquivo

@@ -105,6 +105,10 @@ float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
105 105
 
106 106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
107 107
 
108
+// Initialized by settings.load()
109
+float 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
+
108 112
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
109 113
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
110 114
 
@@ -539,6 +543,16 @@ void Planner::check_axes_activity() {
539 543
   #endif
540 544
 }
541 545
 
546
+inline float calculate_volumetric_multiplier(const float &diameter) {
547
+  if (!parser.volumetric_enabled || diameter == 0) return 1.0;
548
+  return 1.0 / CIRCLE_AREA(diameter * 0.5);
549
+}
550
+
551
+void Planner::calculate_volumetric_multipliers() {
552
+  for (uint8_t i = 0; i < COUNT(filament_size); i++)
553
+    volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
554
+}
555
+
542 556
 #if PLANNER_LEVELING
543 557
   /**
544 558
    * lx, ly, lz - logical (cartesian, not delta) positions in mm

+ 14
- 0
Marlin/src/module/planner.h Ver arquivo

@@ -151,6 +151,10 @@ class Planner {
151 151
 
152 152
     static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
153 153
 
154
+    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
155
+                 volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
156
+                                                    // May be auto-adjusted by a filament width sensor
157
+
154 158
     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
155 159
                  axis_steps_per_mm[XYZE_N],
156 160
                  steps_to_mm[XYZE_N];
@@ -254,6 +258,16 @@ class Planner {
254 258
 
255 259
     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
256 260
 
261
+    // Update multipliers based on new diameter measurements
262
+    static void calculate_volumetric_multipliers();
263
+
264
+    FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
265
+      filament_size[e] = v;
266
+      // make sure all extruders have some sane value for the filament size
267
+      for (uint8_t i = 0; i < COUNT(filament_size); i++)
268
+        if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
269
+    }
270
+
257 271
     #if PLANNER_LEVELING
258 272
 
259 273
       #define ARG_X float lx

+ 1
- 1
Marlin/src/module/temperature.cpp Ver arquivo

@@ -775,7 +775,7 @@ void Temperature::manage_heater() {
775 775
       // Get the delayed info and add 100 to reconstitute to a percent of
776 776
       // the nominal filament diameter then square it to get an area
777 777
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
778
-      volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
778
+      planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
779 779
     }
780 780
   #endif // FILAMENT_WIDTH_SENSOR
781 781
 

Carregando…
Cancelar
Salvar