Преглед на файлове

Move Volumetric methods to Planner

Scott Lahteine преди 7 години
родител
ревизия
a10451ceed

+ 0
- 13
Marlin/src/Marlin.cpp Целия файл

159
   TempUnit input_temp_units = TEMPUNIT_C;
159
   TempUnit input_temp_units = TEMPUNIT_C;
160
 #endif
160
 #endif
161
 
161
 
162
-// Initialized by settings.load()
163
-float filament_size[EXTRUDERS], volumetric_multiplier[EXTRUDERS];
164
-
165
 #if FAN_COUNT > 0
162
 #if FAN_COUNT > 0
166
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
163
   int16_t fanSpeeds[FAN_COUNT] = { 0 };
167
   #if ENABLED(PROBING_FANS_OFF)
164
   #if ENABLED(PROBING_FANS_OFF)
336
 
333
 
337
 #endif // FILAMENT_RUNOUT_SENSOR
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
 void enable_all_steppers() {
336
 void enable_all_steppers() {
350
   enable_X();
337
   enable_X();
351
   enable_Y();
338
   enable_Y();

+ 0
- 5
Marlin/src/Marlin.h Целия файл

174
 inline bool IsRunning() { return  Running; }
174
 inline bool IsRunning() { return  Running; }
175
 inline bool IsStopped() { return !Running; }
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
 extern bool axis_known_position[XYZ];
177
 extern bool axis_known_position[XYZ];
181
 extern bool axis_homed[XYZ];
178
 extern bool axis_homed[XYZ];
182
 extern volatile bool wait_for_heatup;
179
 extern volatile bool wait_for_heatup;
223
   extern int lpq_len;
220
   extern int lpq_len;
224
 #endif
221
 #endif
225
 
222
 
226
-void calculate_volumetric_multipliers();
227
-
228
 bool pin_is_protected(const int8_t pin);
223
 bool pin_is_protected(const int8_t pin);
229
 
224
 
230
 #endif // __MARLIN_H__
225
 #endif // __MARLIN_H__

+ 2
- 2
Marlin/src/feature/fwretract.cpp Целия файл

124
 
124
 
125
     // Retract by moving from a faux E position back to the current E position
125
     // Retract by moving from a faux E position back to the current E position
126
     feedrate_mm_s = retract_feedrate_mm_s;
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
     sync_plan_position_e();
128
     sync_plan_position_e();
129
     prepare_move_to_destination();
129
     prepare_move_to_destination();
130
 
130
 
149
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
149
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
150
 
150
 
151
     const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
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
     sync_plan_position_e();
153
     sync_plan_position_e();
154
 
154
 
155
     prepare_move_to_destination();  // Recover E
155
     prepare_move_to_destination();  // Recover E

+ 4
- 8
Marlin/src/gcode/config/M200.cpp Целия файл

22
 
22
 
23
 #include "../gcode.h"
23
 #include "../gcode.h"
24
 #include "../../Marlin.h"
24
 #include "../../Marlin.h"
25
+#include "../../module/planner.h"
25
 
26
 
26
 /**
27
 /**
27
  * M200: Set filament diameter and set E axis units to cubic units
28
  * M200: Set filament diameter and set E axis units to cubic units
37
     // setting any extruder filament size disables volumetric on the assumption that
38
     // setting any extruder filament size disables volumetric on the assumption that
38
     // slicers either generate in extruder values as cubic mm or as as filament feeds
39
     // slicers either generate in extruder values as cubic mm or as as filament feeds
39
     // for all extruders
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 Целия файл

76
  */
76
  */
77
 void GcodeSuite::M406() {
77
 void GcodeSuite::M406() {
78
   filament_sensor = false;
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 Целия файл

3442
       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
3442
       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
3443
     #endif
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
     if (parser.volumetric_enabled) {
3447
     if (parser.volumetric_enabled) {
3448
       #if EXTRUDERS == 1
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
       #else // EXTRUDERS > 1
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
         #if EXTRUDERS > 2
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
           #if EXTRUDERS > 3
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
             #if EXTRUDERS > 4
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
             #endif // EXTRUDERS > 4
3459
             #endif // EXTRUDERS > 4
3460
           #endif // EXTRUDERS > 3
3460
           #endif // EXTRUDERS > 3
3461
         #endif // EXTRUDERS > 2
3461
         #endif // EXTRUDERS > 2

+ 2
- 2
Marlin/src/lcd/ultralcd_impl_DOGM.h Целия файл

637
     strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
637
     strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
638
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
638
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
639
       strcpy(wstring, ftostr12ns(filament_width_meas));
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
     #endif
641
     #endif
642
   }
642
   }
643
 
643
 
726
         lcd_print(ftostr12ns(filament_width_meas));
726
         lcd_print(ftostr12ns(filament_width_meas));
727
         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL));
727
         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL));
728
         u8g.print(':');
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
         u8g.print('%');
730
         u8g.print('%');
731
       }
731
       }
732
     #else
732
     #else

+ 1
- 1
Marlin/src/lcd/ultralcd_impl_HD44780.h Целия файл

853
       lcd_printPGM(PSTR("Dia "));
853
       lcd_printPGM(PSTR("Dia "));
854
       lcd.print(ftostr12ns(filament_width_meas));
854
       lcd.print(ftostr12ns(filament_width_meas));
855
       lcd_printPGM(PSTR(" V"));
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
       lcd.write('%');
857
       lcd.write('%');
858
       return;
858
       return;
859
     }
859
     }

+ 11
- 11
Marlin/src/module/configuration_store.cpp Целия файл

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

+ 14
- 0
Marlin/src/module/planner.cpp Целия файл

105
 
105
 
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()
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
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
112
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
109
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
113
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
110
 
114
 
539
   #endif
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
 #if PLANNER_LEVELING
556
 #if PLANNER_LEVELING
543
   /**
557
   /**
544
    * lx, ly, lz - logical (cartesian, not delta) positions in mm
558
    * lx, ly, lz - logical (cartesian, not delta) positions in mm

+ 14
- 0
Marlin/src/module/planner.h Целия файл

151
 
151
 
152
     static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
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
     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
158
     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
155
                  axis_steps_per_mm[XYZE_N],
159
                  axis_steps_per_mm[XYZE_N],
156
                  steps_to_mm[XYZE_N];
160
                  steps_to_mm[XYZE_N];
254
 
258
 
255
     static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
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
     #if PLANNER_LEVELING
271
     #if PLANNER_LEVELING
258
 
272
 
259
       #define ARG_X float lx
273
       #define ARG_X float lx

+ 1
- 1
Marlin/src/module/temperature.cpp Целия файл

775
       // Get the delayed info and add 100 to reconstitute to a percent of
775
       // Get the delayed info and add 100 to reconstitute to a percent of
776
       // the nominal filament diameter then square it to get an area
776
       // the nominal filament diameter then square it to get an area
777
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
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
   #endif // FILAMENT_WIDTH_SENSOR
780
   #endif // FILAMENT_WIDTH_SENSOR
781
 
781
 

Loading…
Отказ
Запис