Browse Source

[2.0.x] Extruder-Distinct Linear Advance K Factors (#11789)

Sam Lane 6 years ago
parent
commit
4f883d5971

+ 22
- 2
Marlin/src/gcode/feature/advance/M900.cpp View File

@@ -34,18 +34,38 @@
34 34
  *  K<factor>   Set advance K factor
35 35
  */
36 36
 void GcodeSuite::M900() {
37
+
38
+  #if EXTRUDERS < 2
39
+    constexpr uint8_t tmp_extruder = 0;
40
+  #else
41
+    const uint8_t tmp_extruder = parser.seenval('T') ? parser.value_int() : active_extruder;
42
+    if (tmp_extruder >= EXTRUDERS) {
43
+      SERIAL_PROTOCOLLNPGM("?T value out of range.");
44
+      return;
45
+    }
46
+  #endif
47
+
37 48
   if (parser.seenval('K')) {
38 49
     const float newK = parser.floatval('K');
39 50
     if (WITHIN(newK, 0, 10)) {
40 51
       planner.synchronize();
41
-      planner.extruder_advance_K = newK;
52
+      planner.extruder_advance_K[tmp_extruder] = newK;
42 53
     }
43 54
     else
44 55
       SERIAL_PROTOCOLLNPGM("?K value out of range (0-10).");
45 56
   }
46 57
   else {
47 58
     SERIAL_ECHO_START();
48
-    SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K);
59
+    #if EXTRUDERS < 2
60
+      SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
61
+    #else
62
+      SERIAL_ECHOPGM("Advance K");
63
+      LOOP_L_N(i, EXTRUDERS) {
64
+        SERIAL_CHAR(' '); SERIAL_ECHO(int(i));
65
+        SERIAL_CHAR('='); SERIAL_ECHO(planner.extruder_advance_K[i]);
66
+      }
67
+      SERIAL_EOL();
68
+    #endif
49 69
   }
50 70
 }
51 71
 

+ 30
- 2
Marlin/src/lcd/ultralcd.cpp View File

@@ -3847,7 +3847,21 @@ void lcd_quick_feedback(const bool clear_buttons) {
3847 3847
     #if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
3848 3848
       MENU_ITEM(submenu, MSG_FILAMENT, lcd_advanced_filament_menu);
3849 3849
     #elif ENABLED(LIN_ADVANCE)
3850
-      MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
3850
+      #if EXTRUDERS == 1
3851
+        MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
3852
+      #elif EXTRUDERS > 1
3853
+        MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E1, &planner.extruder_advance_K[0], 0, 999);
3854
+        MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E2, &planner.extruder_advance_K[1], 0, 999);
3855
+        #if EXTRUDERS > 2
3856
+          MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E3, &planner.extruder_advance_K[2], 0, 999);
3857
+          #if EXTRUDERS > 3
3858
+            MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E4, &planner.extruder_advance_K[3], 0, 999);
3859
+            #if EXTRUDERS > 4
3860
+              MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E5, &planner.extruder_advance_K[4], 0, 999);
3861
+            #endif // EXTRUDERS > 4
3862
+          #endif // EXTRUDERS > 3
3863
+        #endif // EXTRUDERS > 2
3864
+      #endif // EXTRUDERS > 1
3851 3865
     #endif
3852 3866
 
3853 3867
     // M540 S - Abort on endstop hit when SD printing
@@ -3882,7 +3896,21 @@ void lcd_quick_feedback(const bool clear_buttons) {
3882 3896
       MENU_BACK(MSG_ADVANCED_SETTINGS);
3883 3897
 
3884 3898
       #if ENABLED(LIN_ADVANCE)
3885
-        MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
3899
+        #if EXTRUDERS == 1
3900
+          MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 999);
3901
+        #elif EXTRUDERS > 1
3902
+          MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E1, &planner.extruder_advance_K[0], 0, 999);
3903
+          MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E2, &planner.extruder_advance_K[1], 0, 999);
3904
+          #if EXTRUDERS > 2
3905
+            MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E3, &planner.extruder_advance_K[2], 0, 999);
3906
+            #if EXTRUDERS > 3
3907
+              MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E4, &planner.extruder_advance_K[3], 0, 999);
3908
+              #if EXTRUDERS > 4
3909
+                MENU_ITEM_EDIT(float52, MSG_ADVANCE_K MSG_E5, &planner.extruder_advance_K[4], 0, 999);
3910
+              #endif // EXTRUDERS > 4
3911
+            #endif // EXTRUDERS > 3
3912
+          #endif // EXTRUDERS > 2
3913
+        #endif // EXTRUDERS > 1
3886 3914
       #endif
3887 3915
 
3888 3916
       #if DISABLED(NO_VOLUMETRICS)

+ 21
- 13
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 "V56"
40
+#define EEPROM_VERSION "V57"
41 41
 #define EEPROM_OFFSET 100
42 42
 
43 43
 // Check the integrity of data offsets.
@@ -254,7 +254,7 @@ typedef struct SettingsDataStruct {
254 254
   //
255 255
   // LIN_ADVANCE
256 256
   //
257
-  float planner_extruder_advance_K;                     // M900 K    planner.extruder_advance_K
257
+  float planner_extruder_advance_K[EXTRUDERS];          // M900 K  planner.extruder_advance_K
258 258
 
259 259
   //
260 260
   // HAS_MOTOR_CURRENT_PWM
@@ -871,14 +871,13 @@ void MarlinSettings::postprocess() {
871 871
     //
872 872
     // Linear Advance
873 873
     //
874
-
875 874
     _FIELD_TEST(planner_extruder_advance_K);
876 875
 
877 876
     #if ENABLED(LIN_ADVANCE)
878
-      EEPROM_WRITE(planner.extruder_advance_K);
877
+      LOOP_L_N(i, EXTRUDERS) EEPROM_WRITE(planner.extruder_advance_K[i]);
879 878
     #else
880 879
       dummy = 0;
881
-      EEPROM_WRITE(dummy);
880
+      LOOP_L_N(i, EXTRUDERS) EEPROM_WRITE(dummy);
882 881
     #endif
883 882
 
884 883
     _FIELD_TEST(motor_current_setting);
@@ -1471,14 +1470,15 @@ void MarlinSettings::postprocess() {
1471 1470
       //
1472 1471
       // Linear Advance
1473 1472
       //
1474
-
1475 1473
       _FIELD_TEST(planner_extruder_advance_K);
1476 1474
 
1477
-      #if ENABLED(LIN_ADVANCE)
1478
-        EEPROM_READ(planner.extruder_advance_K);
1479
-      #else
1480
-        EEPROM_READ(dummy);
1481
-      #endif
1475
+      LOOP_L_N(i, EXTRUDERS) {
1476
+        #if ENABLED(LIN_ADVANCE)
1477
+          EEPROM_READ(planner.extruder_advance_K[i]);
1478
+        #else
1479
+          EEPROM_READ(dummy);
1480
+        #endif
1481
+      }
1482 1482
 
1483 1483
       //
1484 1484
       // Motor Current PWM
@@ -1957,7 +1957,7 @@ void MarlinSettings::reset(PORTARG_SOLO) {
1957 1957
   reset_stepper_drivers();
1958 1958
 
1959 1959
   #if ENABLED(LIN_ADVANCE)
1960
-    planner.extruder_advance_K = LIN_ADVANCE_K;
1960
+    LOOP_L_N(i, EXTRUDERS) planner.extruder_advance_K[i] = LIN_ADVANCE_K;
1961 1961
   #endif
1962 1962
 
1963 1963
   #if HAS_MOTOR_CURRENT_PWM
@@ -2720,8 +2720,16 @@ void MarlinSettings::reset(PORTARG_SOLO) {
2720 2720
         CONFIG_ECHO_START;
2721 2721
         SERIAL_ECHOLNPGM_P(port, "Linear Advance:");
2722 2722
       }
2723
+
2723 2724
       CONFIG_ECHO_START;
2724
-      SERIAL_ECHOLNPAIR_P(port, "  M900 K", planner.extruder_advance_K);
2725
+      #if EXTRUDERS < 2
2726
+        SERIAL_ECHOLNPAIR_P(port, "  M900 K", planner.extruder_advance_K[0]);
2727
+      #else
2728
+        LOOP_L_N(i, EXTRUDERS) {
2729
+          SERIAL_ECHOPAIR_P(port, "  M900 T", int(i));
2730
+          SERIAL_ECHOLNPAIR_P(port, " K", planner.extruder_advance_K[i]);
2731
+        }
2732
+      #endif
2725 2733
     #endif
2726 2734
 
2727 2735
     #if HAS_MOTOR_CURRENT_PWM

+ 8
- 8
Marlin/src/module/planner.cpp View File

@@ -213,7 +213,7 @@ float Planner::previous_speed[NUM_AXIS],
213 213
 #endif
214 214
 
215 215
 #if ENABLED(LIN_ADVANCE)
216
-  float Planner::extruder_advance_K; // Initialized by settings.load()
216
+  float Planner::extruder_advance_K[EXTRUDERS]; // Initialized by settings.load()
217 217
 #endif
218 218
 
219 219
 #if HAS_POSITION_FLOAT
@@ -1082,7 +1082,7 @@ void Planner::recalculate_trapezoids() {
1082 1082
             calculate_trapezoid_for_block(current, current_entry_speed * nomr, next_entry_speed * nomr);
1083 1083
             #if ENABLED(LIN_ADVANCE)
1084 1084
               if (current->use_advance_lead) {
1085
-                const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
1085
+                const float comp = current->e_D_ratio * extruder_advance_K[active_extruder] * axis_steps_per_mm[E_AXIS];
1086 1086
                 current->max_adv_steps = current_nominal_speed * comp;
1087 1087
                 current->final_adv_steps = next_entry_speed * comp;
1088 1088
               }
@@ -1121,7 +1121,7 @@ void Planner::recalculate_trapezoids() {
1121 1121
       calculate_trapezoid_for_block(next, next_entry_speed * nomr, float(MINIMUM_PLANNER_SPEED) * nomr);
1122 1122
       #if ENABLED(LIN_ADVANCE)
1123 1123
         if (next->use_advance_lead) {
1124
-          const float comp = next->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
1124
+          const float comp = next->e_D_ratio * extruder_advance_K[active_extruder] * axis_steps_per_mm[E_AXIS];
1125 1125
           next->max_adv_steps = next_nominal_speed * comp;
1126 1126
           next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
1127 1127
         }
@@ -2130,12 +2130,12 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2130 2130
        *
2131 2131
        * esteps             : This is a print move, because we checked for A, B, C steps before.
2132 2132
        *
2133
-       * extruder_advance_K : There is an advance factor set.
2133
+       * extruder_advance_K[active_extruder] : There is an advance factor set for this extruder.
2134 2134
        *
2135 2135
        * de > 0             : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
2136 2136
        */
2137 2137
       block->use_advance_lead =  esteps
2138
-                              && extruder_advance_K
2138
+                              && extruder_advance_K[active_extruder]
2139 2139
                               && de > 0;
2140 2140
 
2141 2141
       if (block->use_advance_lead) {
@@ -2154,7 +2154,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2154 2154
         if (block->e_D_ratio > 3.0f)
2155 2155
           block->use_advance_lead = false;
2156 2156
         else {
2157
-          const uint32_t max_accel_steps_per_s2 = MAX_E_JERK / (extruder_advance_K * block->e_D_ratio) * steps_per_mm;
2157
+          const uint32_t max_accel_steps_per_s2 = MAX_E_JERK / (extruder_advance_K[active_extruder] * block->e_D_ratio) * steps_per_mm;
2158 2158
           #if ENABLED(LA_DEBUG)
2159 2159
             if (accel > max_accel_steps_per_s2) SERIAL_ECHOLNPGM("Acceleration limited.");
2160 2160
           #endif
@@ -2190,9 +2190,9 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2190 2190
   #endif
2191 2191
   #if ENABLED(LIN_ADVANCE)
2192 2192
     if (block->use_advance_lead) {
2193
-      block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS_N]);
2193
+      block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS_N]);
2194 2194
       #if ENABLED(LA_DEBUG)
2195
-        if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < SQRT(block->nominal_speed_sqr) * block->e_D_ratio)
2195
+        if (extruder_advance_K[active_extruder] * block->e_D_ratio * block->acceleration * 2 < SQRT(block->nominal_speed_sqr) * block->e_D_ratio)
2196 2196
           SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed.");
2197 2197
         if (block->advance_speed < 200)
2198 2198
           SERIAL_ECHOLNPGM("eISR running at > 10kHz.");

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

@@ -231,7 +231,7 @@ class Planner {
231 231
     #endif
232 232
 
233 233
     #if ENABLED(LIN_ADVANCE)
234
-      static float extruder_advance_K;
234
+      static float extruder_advance_K[EXTRUDERS];
235 235
     #endif
236 236
 
237 237
     #if HAS_POSITION_FLOAT

Loading…
Cancel
Save