Browse Source

Add pre-calculated planner.e_factor

Scott Lahteine 7 years ago
parent
commit
3293823642

+ 0
- 6
Marlin/Marlin.h View File

215
 #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
215
 #define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
216
 
216
 
217
 extern bool axis_relative_modes[];
217
 extern bool axis_relative_modes[];
218
-extern bool volumetric_enabled;
219
-extern int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
220
-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.
221
-extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
222
 extern bool axis_known_position[XYZ];
218
 extern bool axis_known_position[XYZ];
223
 extern bool axis_homed[XYZ];
219
 extern bool axis_homed[XYZ];
224
 extern volatile bool wait_for_heatup;
220
 extern volatile bool wait_for_heatup;
427
   extern float mixing_factor[MIXING_STEPPERS];
423
   extern float mixing_factor[MIXING_STEPPERS];
428
 #endif
424
 #endif
429
 
425
 
430
-void calculate_volumetric_multipliers();
431
-
432
 /**
426
 /**
433
  * Blocking movement and shorthand functions
427
  * Blocking movement and shorthand functions
434
  */
428
  */

+ 16
- 28
Marlin/Marlin_main.cpp View File

452
 
452
 
453
 float feedrate_mm_s = MMM_TO_MMS(1500.0);
453
 float feedrate_mm_s = MMM_TO_MMS(1500.0);
454
 static float saved_feedrate_mm_s;
454
 static float saved_feedrate_mm_s;
455
-int16_t feedrate_percentage = 100, saved_feedrate_percentage,
456
-    flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100);
455
+int16_t feedrate_percentage = 100, saved_feedrate_percentage;
457
 
456
 
458
 // Initialized by settings.load()
457
 // Initialized by settings.load()
459
-bool axis_relative_modes[] = AXIS_RELATIVE_MODES,
460
-     volumetric_enabled;
461
-float filament_size[EXTRUDERS], volumetric_multiplier[EXTRUDERS];
458
+bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
462
 
459
 
463
 #if HAS_WORKSPACE_OFFSET
460
 #if HAS_WORKSPACE_OFFSET
464
   #if HAS_POSITION_SHIFT
461
   #if HAS_POSITION_SHIFT
3226
     set_destination_from_current();
3223
     set_destination_from_current();
3227
     stepper.synchronize();  // Wait for buffered moves to complete
3224
     stepper.synchronize();  // Wait for buffered moves to complete
3228
 
3225
 
3229
-    const float renormalize = 100.0 / flow_percentage[active_extruder] / volumetric_multiplier[active_extruder];
3226
+    const float renormalize = 1.0 / planner.e_factor[active_extruder];
3230
 
3227
 
3231
     if (retracting) {
3228
     if (retracting) {
3232
       // Retract by moving from a faux E position back to the current E position
3229
       // Retract by moving from a faux E position back to the current E position
6553
   #endif
6550
   #endif
6554
 
6551
 
6555
   void do_pause_e_move(const float &length, const float fr) {
6552
   void do_pause_e_move(const float &length, const float fr) {
6556
-    current_position[E_AXIS] += length * 100.0 / flow_percentage[active_extruder] / volumetric_multiplier[active_extruder];
6553
+    current_position[E_AXIS] += length / planner.e_factor[active_extruder];
6557
     set_destination_from_current();
6554
     set_destination_from_current();
6558
     RUNPLAN(fr);
6555
     RUNPLAN(fr);
6559
     stepper.synchronize();
6556
     stepper.synchronize();
8832
     // setting any extruder filament size disables volumetric on the assumption that
8829
     // setting any extruder filament size disables volumetric on the assumption that
8833
     // slicers either generate in extruder values as cubic mm or as as filament feeds
8830
     // slicers either generate in extruder values as cubic mm or as as filament feeds
8834
     // for all extruders
8831
     // for all extruders
8835
-    volumetric_enabled = (parser.value_linear_units() != 0.0);
8836
-    if (volumetric_enabled) {
8837
-      filament_size[target_extruder] = parser.value_linear_units();
8832
+    if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) ) {
8833
+      planner.filament_size[target_extruder] = parser.value_linear_units();
8838
       // make sure all extruders have some sane value for the filament size
8834
       // make sure all extruders have some sane value for the filament size
8839
-      for (uint8_t i = 0; i < COUNT(filament_size); i++)
8840
-        if (! filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
8835
+      for (uint8_t i = 0; i < COUNT(planner.filament_size); i++)
8836
+        if (!planner.filament_size[i]) planner.filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
8841
     }
8837
     }
8842
   }
8838
   }
8843
-  calculate_volumetric_multipliers();
8839
+  planner.calculate_volumetric_multipliers();
8844
 }
8840
 }
8845
 
8841
 
8846
 /**
8842
 /**
9201
  */
9197
  */
9202
 inline void gcode_M221() {
9198
 inline void gcode_M221() {
9203
   if (get_target_extruder_from_command(221)) return;
9199
   if (get_target_extruder_from_command(221)) return;
9204
-  if (parser.seenval('S'))
9205
-    flow_percentage[target_extruder] = parser.value_int();
9200
+  if (parser.seenval('S')) {
9201
+    planner.flow_percentage[target_extruder] = parser.value_int();
9202
+    planner.refresh_e_factor(target_extruder);
9203
+  }
9206
 }
9204
 }
9207
 
9205
 
9208
 /**
9206
 /**
9735
     //SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
9733
     //SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
9736
     //SERIAL_PROTOCOL(filament_width_meas);
9734
     //SERIAL_PROTOCOL(filament_width_meas);
9737
     //SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
9735
     //SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
9738
-    //SERIAL_PROTOCOL(flow_percentage[active_extruder]);
9736
+    //SERIAL_PROTOCOL(planner.flow_percentage[active_extruder]);
9739
   }
9737
   }
9740
 
9738
 
9741
   /**
9739
   /**
9743
    */
9741
    */
9744
   inline void gcode_M406() {
9742
   inline void gcode_M406() {
9745
     filament_sensor = false;
9743
     filament_sensor = false;
9746
-    calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
9744
+    planner.calculate_volumetric_multipliers();   // Restore correct 'volumetric_multiplier' value
9747
   }
9745
   }
9748
 
9746
 
9749
   /**
9747
   /**
12967
           }
12965
           }
12968
         #endif // PREVENT_COLD_EXTRUSION
12966
         #endif // PREVENT_COLD_EXTRUSION
12969
         #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
12967
         #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
12970
-          if (FABS(destination[E_AXIS] - current_position[E_AXIS]) > (EXTRUDE_MAXLENGTH) / volumetric_multiplier[active_extruder]) {
12968
+          if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
12971
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
12969
             current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
12972
             SERIAL_ECHO_START();
12970
             SERIAL_ECHO_START();
12973
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
12971
             SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
13387
 
13385
 
13388
 #endif // FAST_PWM_FAN
13386
 #endif // FAST_PWM_FAN
13389
 
13387
 
13390
-float calculate_volumetric_multiplier(const float diameter) {
13391
-  if (!volumetric_enabled || diameter == 0) return 1.0;
13392
-  return 1.0 / (M_PI * sq(diameter * 0.5));
13393
-}
13394
-
13395
-void calculate_volumetric_multipliers() {
13396
-  for (uint8_t i = 0; i < COUNT(filament_size); i++)
13397
-    volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
13398
-}
13399
-
13400
 void enable_all_steppers() {
13388
 void enable_all_steppers() {
13401
   enable_X();
13389
   enable_X();
13402
   enable_Y();
13390
   enable_Y();

+ 19
- 22
Marlin/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)
188
 #include "temperature.h"
188
 #include "temperature.h"
189
 #include "ultralcd.h"
189
 #include "ultralcd.h"
190
 #include "stepper.h"
190
 #include "stepper.h"
191
-
192
-#if ENABLED(INCH_MODE_SUPPORT) || (ENABLED(ULTIPANEL) && ENABLED(TEMPERATURE_UNITS_SUPPORT))
193
-  #include "gcode.h"
194
-#endif
191
+#include "gcode.h"
195
 
192
 
196
 #if ENABLED(MESH_BED_LEVELING)
193
 #if ENABLED(MESH_BED_LEVELING)
197
   #include "mesh_bed_leveling.h"
194
   #include "mesh_bed_leveling.h"
238
     thermalManager.updatePID();
235
     thermalManager.updatePID();
239
   #endif
236
   #endif
240
 
237
 
241
-  calculate_volumetric_multipliers();
238
+  planner.calculate_volumetric_multipliers();
242
 
239
 
243
   #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
240
   #if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
244
     // Software endstops depend on home_offset
241
     // Software endstops depend on home_offset
569
     EEPROM_WRITE(swap_retract_recover_length);
566
     EEPROM_WRITE(swap_retract_recover_length);
570
     EEPROM_WRITE(swap_retract_recover_feedrate_mm_s);
567
     EEPROM_WRITE(swap_retract_recover_feedrate_mm_s);
571
 
568
 
572
-    EEPROM_WRITE(volumetric_enabled);
569
+    EEPROM_WRITE(parser.volumetric_enabled);
573
 
570
 
574
     // Save filament sizes
571
     // Save filament sizes
575
     for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
572
     for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
576
-      if (q < COUNT(filament_size)) dummy = filament_size[q];
573
+      if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
577
       EEPROM_WRITE(dummy);
574
       EEPROM_WRITE(dummy);
578
     }
575
     }
579
 
576
 
1018
       // Volumetric & Filament Size
1015
       // Volumetric & Filament Size
1019
       //
1016
       //
1020
 
1017
 
1021
-      EEPROM_READ(volumetric_enabled);
1018
+      EEPROM_READ(parser.volumetric_enabled);
1022
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1019
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
1023
         EEPROM_READ(dummy);
1020
         EEPROM_READ(dummy);
1024
-        if (q < COUNT(filament_size)) filament_size[q] = dummy;
1021
+        if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
1025
       }
1022
       }
1026
 
1023
 
1027
       //
1024
       //
1424
     swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
1421
     swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
1425
   #endif // FWRETRACT
1422
   #endif // FWRETRACT
1426
 
1423
 
1427
-  volumetric_enabled =
1424
+  parser.volumetric_enabled =
1428
     #if ENABLED(VOLUMETRIC_DEFAULT_ON)
1425
     #if ENABLED(VOLUMETRIC_DEFAULT_ON)
1429
       true
1426
       true
1430
     #else
1427
     #else
1431
       false
1428
       false
1432
     #endif
1429
     #endif
1433
   ;
1430
   ;
1434
-  for (uint8_t q = 0; q < COUNT(filament_size); q++)
1435
-    filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
1431
+  for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
1432
+    planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
1436
 
1433
 
1437
   endstops.enable_globally(
1434
   endstops.enable_globally(
1438
     #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
1435
     #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
1515
     CONFIG_ECHO_START;
1512
     CONFIG_ECHO_START;
1516
     #if ENABLED(INCH_MODE_SUPPORT)
1513
     #if ENABLED(INCH_MODE_SUPPORT)
1517
       #define LINEAR_UNIT(N) ((N) / parser.linear_unit_factor)
1514
       #define LINEAR_UNIT(N) ((N) / parser.linear_unit_factor)
1518
-      #define VOLUMETRIC_UNIT(N) ((N) / (volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
1515
+      #define VOLUMETRIC_UNIT(N) ((N) / (parser.volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
1519
       SERIAL_ECHOPGM("  G2");
1516
       SERIAL_ECHOPGM("  G2");
1520
       SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
1517
       SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
1521
       SERIAL_ECHOPGM(" ; Units in ");
1518
       SERIAL_ECHOPGM(" ; Units in ");
1552
     if (!forReplay) {
1549
     if (!forReplay) {
1553
       CONFIG_ECHO_START;
1550
       CONFIG_ECHO_START;
1554
       SERIAL_ECHOPGM("Filament settings:");
1551
       SERIAL_ECHOPGM("Filament settings:");
1555
-      if (volumetric_enabled)
1552
+      if (parser.volumetric_enabled)
1556
         SERIAL_EOL();
1553
         SERIAL_EOL();
1557
       else
1554
       else
1558
         SERIAL_ECHOLNPGM(" Disabled");
1555
         SERIAL_ECHOLNPGM(" Disabled");
1559
     }
1556
     }
1560
 
1557
 
1561
     CONFIG_ECHO_START;
1558
     CONFIG_ECHO_START;
1562
-    SERIAL_ECHOPAIR("  M200 D", filament_size[0]);
1559
+    SERIAL_ECHOPAIR("  M200 D", planner.filament_size[0]);
1563
     SERIAL_EOL();
1560
     SERIAL_EOL();
1564
     #if EXTRUDERS > 1
1561
     #if EXTRUDERS > 1
1565
       CONFIG_ECHO_START;
1562
       CONFIG_ECHO_START;
1566
-      SERIAL_ECHOPAIR("  M200 T1 D", filament_size[1]);
1563
+      SERIAL_ECHOPAIR("  M200 T1 D", planner.filament_size[1]);
1567
       SERIAL_EOL();
1564
       SERIAL_EOL();
1568
       #if EXTRUDERS > 2
1565
       #if EXTRUDERS > 2
1569
         CONFIG_ECHO_START;
1566
         CONFIG_ECHO_START;
1570
-        SERIAL_ECHOPAIR("  M200 T2 D", filament_size[2]);
1567
+        SERIAL_ECHOPAIR("  M200 T2 D", planner.filament_size[2]);
1571
         SERIAL_EOL();
1568
         SERIAL_EOL();
1572
         #if EXTRUDERS > 3
1569
         #if EXTRUDERS > 3
1573
           CONFIG_ECHO_START;
1570
           CONFIG_ECHO_START;
1574
-          SERIAL_ECHOPAIR("  M200 T3 D", filament_size[3]);
1571
+          SERIAL_ECHOPAIR("  M200 T3 D", planner.filament_size[3]);
1575
           SERIAL_EOL();
1572
           SERIAL_EOL();
1576
           #if EXTRUDERS > 4
1573
           #if EXTRUDERS > 4
1577
             CONFIG_ECHO_START;
1574
             CONFIG_ECHO_START;
1578
-            SERIAL_ECHOPAIR("  M200 T4 D", filament_size[4]);
1575
+            SERIAL_ECHOPAIR("  M200 T4 D", planner.filament_size[4]);
1579
             SERIAL_EOL();
1576
             SERIAL_EOL();
1580
           #endif // EXTRUDERS > 4
1577
           #endif // EXTRUDERS > 4
1581
         #endif // EXTRUDERS > 3
1578
         #endif // EXTRUDERS > 3
1582
       #endif // EXTRUDERS > 2
1579
       #endif // EXTRUDERS > 2
1583
     #endif // EXTRUDERS > 1
1580
     #endif // EXTRUDERS > 1
1584
 
1581
 
1585
-    if (!volumetric_enabled) {
1582
+    if (!parser.volumetric_enabled) {
1586
       CONFIG_ECHO_START;
1583
       CONFIG_ECHO_START;
1587
       SERIAL_ECHOLNPGM("  M200 D0");
1584
       SERIAL_ECHOLNPGM("  M200 D0");
1588
     }
1585
     }

+ 2
- 0
Marlin/gcode.cpp View File

32
 // Must be declared for allocation and to satisfy the linker
32
 // Must be declared for allocation and to satisfy the linker
33
 // Zero values need no initialization.
33
 // Zero values need no initialization.
34
 
34
 
35
+bool GCodeParser::volumetric_enabled;
36
+
35
 #if ENABLED(INCH_MODE_SUPPORT)
37
 #if ENABLED(INCH_MODE_SUPPORT)
36
   float GCodeParser::linear_unit_factor, GCodeParser::volumetric_unit_factor;
38
   float GCodeParser::linear_unit_factor, GCodeParser::volumetric_unit_factor;
37
 #endif
39
 #endif

+ 2
- 4
Marlin/gcode.h View File

44
   #include "serial.h"
44
   #include "serial.h"
45
 #endif
45
 #endif
46
 
46
 
47
-#if ENABLED(INCH_MODE_SUPPORT)
48
-  extern bool volumetric_enabled;
49
-#endif
50
-
51
 /**
47
 /**
52
  * GCode parser
48
  * GCode parser
53
  *
49
  *
76
 
72
 
77
   // Global states for GCode-level units features
73
   // Global states for GCode-level units features
78
 
74
 
75
+  static bool volumetric_enabled;
76
+
79
   #if ENABLED(INCH_MODE_SUPPORT)
77
   #if ENABLED(INCH_MODE_SUPPORT)
80
     static float linear_unit_factor, volumetric_unit_factor;
78
     static float linear_unit_factor, volumetric_unit_factor;
81
   #endif
79
   #endif

+ 21
- 6
Marlin/planner.cpp View File

91
   uint8_t Planner::last_extruder = 0;     // Respond to extruder change
91
   uint8_t Planner::last_extruder = 0;     // Respond to extruder change
92
 #endif
92
 #endif
93
 
93
 
94
+int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
95
+
96
+float Planner::e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
97
+      Planner::filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
98
+      Planner::volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
99
+
94
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
100
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
95
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
101
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
96
 
102
 
521
   #endif
527
   #endif
522
 }
528
 }
523
 
529
 
530
+inline float calculate_volumetric_multiplier(const float &diameter) {
531
+  if (!parser.volumetric_enabled || diameter == 0) return 1.0;
532
+  return 1.0 / CIRCLE_AREA(diameter * 0.5);
533
+}
534
+
535
+void Planner::calculate_volumetric_multipliers() {
536
+  for (uint8_t i = 0; i < COUNT(filament_size); i++) {
537
+    volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
538
+    refresh_e_factor(i);
539
+  }
540
+}
541
+
524
 #if PLANNER_LEVELING
542
 #if PLANNER_LEVELING
525
   /**
543
   /**
526
    * rx, ry, rz - cartesian position in mm
544
    * rx, ry, rz - cartesian position in mm
719
 
737
 
720
   long de = target[E_AXIS] - position[E_AXIS];
738
   long de = target[E_AXIS] - position[E_AXIS];
721
 
739
 
722
-  const float e_factor = volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
723
-
724
   #if ENABLED(LIN_ADVANCE)
740
   #if ENABLED(LIN_ADVANCE)
725
-    float de_float = e - position_float[E_AXIS];
741
+    float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
726
   #endif
742
   #endif
727
 
743
 
728
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
744
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
740
         }
756
         }
741
       #endif // PREVENT_COLD_EXTRUSION
757
       #endif // PREVENT_COLD_EXTRUSION
742
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
758
       #if ENABLED(PREVENT_LENGTHY_EXTRUDE)
743
-        const int32_t de_mm = labs(de * e_factor);
744
-        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
759
+        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
745
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
760
           position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
746
           de = 0; // no difference
761
           de = 0; // no difference
747
           #if ENABLED(LIN_ADVANCE)
762
           #if ENABLED(LIN_ADVANCE)
782
   #endif
797
   #endif
783
   if (de < 0) SBI(dm, E_AXIS);
798
   if (de < 0) SBI(dm, E_AXIS);
784
 
799
 
785
-  const float esteps_float = de * e_factor;
800
+  const float esteps_float = de * e_factor[extruder];
786
   const int32_t esteps = abs(esteps_float) + 0.5;
801
   const int32_t esteps = abs(esteps_float) + 0.5;
787
 
802
 
788
   // Calculate the buffer head after we push this byte
803
   // Calculate the buffer head after we push this byte

+ 13
- 0
Marlin/planner.h View File

140
       static uint8_t last_extruder;             // Respond to extruder change
140
       static uint8_t last_extruder;             // Respond to extruder change
141
     #endif
141
     #endif
142
 
142
 
143
+    static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
144
+
145
+    static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
146
+                 filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
147
+                 volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
148
+                                                    // May be auto-adjusted by a filament width sensor
149
+
143
     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
150
     static float max_feedrate_mm_s[XYZE_N],     // Max speeds in mm per second
144
                  axis_steps_per_mm[XYZE_N],
151
                  axis_steps_per_mm[XYZE_N],
145
                  steps_to_mm[XYZE_N];
152
                  steps_to_mm[XYZE_N];
236
     static void reset_acceleration_rates();
243
     static void reset_acceleration_rates();
237
     static void refresh_positioning();
244
     static void refresh_positioning();
238
 
245
 
246
+    FORCE_INLINE static void refresh_e_factor(const uint8_t e) {
247
+      e_factor[e] = volumetric_multiplier[e] * flow_percentage[e] * 0.01;
248
+    }
249
+
239
     // Manage fans, paste pressure, etc.
250
     // Manage fans, paste pressure, etc.
240
     static void check_axes_activity();
251
     static void check_axes_activity();
241
 
252
 
253
+    static void calculate_volumetric_multipliers();
254
+
242
     /**
255
     /**
243
      * Number of moves currently in the planner
256
      * Number of moves currently in the planner
244
      */
257
      */

+ 2
- 1
Marlin/temperature.cpp View File

815
       // Get the delayed info and add 100 to reconstitute to a percent of
815
       // Get the delayed info and add 100 to reconstitute to a percent of
816
       // the nominal filament diameter then square it to get an area
816
       // the nominal filament diameter then square it to get an area
817
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
817
       const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
818
-      volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
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
   #endif // FILAMENT_WIDTH_SENSOR
821
   #endif // FILAMENT_WIDTH_SENSOR
821
 
822
 

+ 32
- 15
Marlin/ultralcd.cpp View File

33
 #include "stepper.h"
33
 #include "stepper.h"
34
 #include "configuration_store.h"
34
 #include "configuration_store.h"
35
 #include "utility.h"
35
 #include "utility.h"
36
+#include "gcode.h"
36
 
37
 
37
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
38
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
38
   #include "buzzer.h"
39
   #include "buzzer.h"
1248
     #endif
1249
     #endif
1249
   #endif
1250
   #endif
1250
 
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
+
1251
   /**
1268
   /**
1252
    *
1269
    *
1253
    * "Tune" submenu
1270
    * "Tune" submenu
1327
     // Flow [1-5]:
1344
     // Flow [1-5]:
1328
     //
1345
     //
1329
     #if EXTRUDERS == 1
1346
     #if EXTRUDERS == 1
1330
-      MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[0], 10, 999);
1347
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_FLOW, &planner.flow_percentage[0], 10, 999, _lcd_refresh_e_factor_0);
1331
     #else // EXTRUDERS > 1
1348
     #else // EXTRUDERS > 1
1332
-      MENU_ITEM_EDIT(int3, MSG_FLOW, &flow_percentage[active_extruder], 10, 999);
1333
-      MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N1, &flow_percentage[0], 10, 999);
1334
-      MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N2, &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);
1335
       #if EXTRUDERS > 2
1352
       #if EXTRUDERS > 2
1336
-        MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N3, &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);
1337
         #if EXTRUDERS > 3
1354
         #if EXTRUDERS > 3
1338
-          MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N4, &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);
1339
           #if EXTRUDERS > 4
1356
           #if EXTRUDERS > 4
1340
-            MENU_ITEM_EDIT(int3, MSG_FLOW MSG_N5, &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);
1341
           #endif // EXTRUDERS > 4
1358
           #endif // EXTRUDERS > 4
1342
         #endif // EXTRUDERS > 3
1359
         #endif // EXTRUDERS > 3
1343
       #endif // EXTRUDERS > 2
1360
       #endif // EXTRUDERS > 2
3678
       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
3695
       MENU_ITEM_EDIT(float3, MSG_ADVANCE_K, &planner.extruder_advance_k, 0, 999);
3679
     #endif
3696
     #endif
3680
 
3697
 
3681
-    MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &volumetric_enabled, calculate_volumetric_multipliers);
3698
+    MENU_ITEM_EDIT_CALLBACK(bool, MSG_VOLUMETRIC_ENABLED, &parser.volumetric_enabled, planner.calculate_volumetric_multipliers);
3682
 
3699
 
3683
-    if (volumetric_enabled) {
3700
+    if (parser.volumetric_enabled) {
3684
       #if EXTRUDERS == 1
3701
       #if EXTRUDERS == 1
3685
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
3702
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3686
       #else // EXTRUDERS > 1
3703
       #else // EXTRUDERS > 1
3687
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &filament_size[0], 1.5, 3.25, calculate_volumetric_multipliers);
3688
-        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &filament_size[1], 1.5, 3.25, calculate_volumetric_multipliers);
3704
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3705
+        MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3689
         #if EXTRUDERS > 2
3706
         #if EXTRUDERS > 2
3690
-          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &filament_size[2], 1.5, 3.25, calculate_volumetric_multipliers);
3707
+          MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3691
           #if EXTRUDERS > 3
3708
           #if EXTRUDERS > 3
3692
-            MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &filament_size[3], 1.5, 3.25, calculate_volumetric_multipliers);
3709
+            MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3693
             #if EXTRUDERS > 4
3710
             #if EXTRUDERS > 4
3694
-              MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &filament_size[4], 1.5, 3.25, calculate_volumetric_multipliers);
3711
+              MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5, 3.25, planner.calculate_volumetric_multipliers);
3695
             #endif // EXTRUDERS > 4
3712
             #endif // EXTRUDERS > 4
3696
           #endif // EXTRUDERS > 3
3713
           #endif // EXTRUDERS > 3
3697
         #endif // EXTRUDERS > 2
3714
         #endif // EXTRUDERS > 2

+ 2
- 2
Marlin/ultralcd_impl_DOGM.h View File

650
     strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
650
     strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
651
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
651
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
652
       strcpy(wstring, ftostr12ns(filament_width_meas));
652
       strcpy(wstring, ftostr12ns(filament_width_meas));
653
-      strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
653
+      strcpy(mstring, itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
654
     #endif
654
     #endif
655
   }
655
   }
656
 
656
 
739
         lcd_print(ftostr12ns(filament_width_meas));
739
         lcd_print(ftostr12ns(filament_width_meas));
740
         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL));
740
         lcd_printPGM(PSTR("  " LCD_STR_FILAM_MUL));
741
         u8g.print(':');
741
         u8g.print(':');
742
-        lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
742
+        lcd_print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
743
         u8g.print('%');
743
         u8g.print('%');
744
       }
744
       }
745
     #else
745
     #else

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h View File

857
       lcd_printPGM(PSTR("Dia "));
857
       lcd_printPGM(PSTR("Dia "));
858
       lcd.print(ftostr12ns(filament_width_meas));
858
       lcd.print(ftostr12ns(filament_width_meas));
859
       lcd_printPGM(PSTR(" V"));
859
       lcd_printPGM(PSTR(" V"));
860
-      lcd.print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
860
+      lcd.print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
861
       lcd.write('%');
861
       lcd.write('%');
862
       return;
862
       return;
863
     }
863
     }

Loading…
Cancel
Save