Browse Source

Reduce E_D_ratio code

Scott Lahteine 7 years ago
parent
commit
b3e2bd6f29
3 changed files with 24 additions and 43 deletions
  1. 14
    31
      Marlin/Marlin_main.cpp
  2. 8
    10
      Marlin/planner.cpp
  3. 2
    2
      Marlin/planner.h

+ 14
- 31
Marlin/Marlin_main.cpp View File

7601
    */
7601
    */
7602
   inline void gcode_M905() {
7602
   inline void gcode_M905() {
7603
     stepper.synchronize();
7603
     stepper.synchronize();
7604
-    
7605
-    float newD = -1;
7606
-    float newW = -1;
7607
-    float newH = -1;
7608
-    
7609
-    if (code_seen('K')) {
7610
-      float newK = code_value_float();
7611
-      if (newK >= 0.0)
7612
-        planner.set_extruder_advance_k(newK);
7613
-    }
7604
+
7605
+    const float newK = code_seen('K') ? code_value_float() : -1,
7606
+                newD = code_seen('D') ? code_value_float() : -1,
7607
+                newW = code_seen('W') ? code_value_float() : -1,
7608
+                newH = code_seen('H') ? code_value_float() : -1;
7609
+
7610
+    if (newK >= 0.0) planner.set_extruder_advance_k(newK);
7614
 
7611
 
7615
     SERIAL_ECHO_START;
7612
     SERIAL_ECHO_START;
7616
-    SERIAL_ECHOPAIR("Advance factor: ", planner.get_extruder_advance_k());
7617
-    SERIAL_EOL;
7618
-    
7619
-    if (code_seen('D'))
7620
-      newD = code_value_float();
7621
-    if (code_seen('W'))
7622
-      newW = code_value_float();
7623
-    if (code_seen('H'))
7624
-      newH = code_value_float();
7625
-
7626
-    if (newD > 0 && newW > 0 && newH > 0) {
7627
-      float E_D_ratio = newW * newH / (sq(newD / 2) * M_PI);
7628
-      planner.set_E_D_ratio(E_D_ratio);
7629
-      SERIAL_ECHO_START;
7630
-      SERIAL_ECHOPAIR("E/D ratio: ", E_D_ratio);
7631
-      SERIAL_EOL;
7632
-    }
7633
-    else if (newD != -1 || newW != -1 || newH != -1) {
7634
-      planner.set_E_D_ratio(0);
7613
+    SERIAL_ECHOLNPAIR("Advance factor: ", planner.get_extruder_advance_k());
7614
+
7615
+    if (newD >= 0 || newW >= 0 || newH >= 0) {
7616
+      const float ratio = (!newD || !newW || !newH) ? 0 : (newW * newH) / (sq(newD * 0.5) * M_PI);
7617
+      planner.set_advance_ed_ratio(ratio);
7635
       SERIAL_ECHO_START;
7618
       SERIAL_ECHO_START;
7636
-      SERIAL_ECHOPGM("E/D ratio: Automatic");
7637
-      SERIAL_EOL;
7619
+      SERIAL_ECHOPGM("E/D ratio: ");
7620
+      if (ratio) SERIAL_ECHOLN(ratio); else SERIAL_ECHOLNPGM("Automatic");
7638
     }
7621
     }
7639
   }
7622
   }
7640
 #endif
7623
 #endif

+ 8
- 10
Marlin/planner.cpp View File

142
 
142
 
143
 #if ENABLED(LIN_ADVANCE)
143
 #if ENABLED(LIN_ADVANCE)
144
   float Planner::extruder_advance_k = LIN_ADVANCE_K,
144
   float Planner::extruder_advance_k = LIN_ADVANCE_K,
145
-        Planner::E_D_ratio = LIN_ADVANCE_E_D_RATIO,
145
+        Planner::advance_ed_ratio = LIN_ADVANCE_E_D_RATIO,
146
         Planner::position_float[NUM_AXIS] = { 0 };
146
         Planner::position_float[NUM_AXIS] = { 0 };
147
 #endif
147
 #endif
148
 
148
 
1324
                             && extruder_advance_k
1324
                             && extruder_advance_k
1325
                             && (uint32_t)esteps != block->step_event_count
1325
                             && (uint32_t)esteps != block->step_event_count
1326
                             && de_float > 0.0;
1326
                             && de_float > 0.0;
1327
-    if (block->use_advance_lead) {
1328
-      // Check if we should use the fixed E_D_ratio
1329
-      if (UNEAR_ZERO(E_D_ratio)) {
1330
-        block->abs_adv_steps_multiplier8 = lround(extruder_advance_k * (de_float / mm_D_float) * block->nominal_speed / (float)block->nominal_rate * axis_steps_per_mm[E_AXIS_N] * 256.0);
1331
-      }
1332
-      else {
1333
-        block->abs_adv_steps_multiplier8 = lround(extruder_advance_k * E_D_ratio * block->nominal_speed / (float)block->nominal_rate * axis_steps_per_mm[E_AXIS_N] * 256.0);
1334
-      }
1335
-    }
1327
+    if (block->use_advance_lead)
1328
+      block->abs_adv_steps_multiplier8 = lround(
1329
+        extruder_advance_k
1330
+        * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
1331
+        * (block->nominal_speed / (float)block->nominal_rate)
1332
+        * axis_steps_per_mm[E_AXIS_N] * 256.0
1333
+      );
1336
 
1334
 
1337
   #elif ENABLED(ADVANCE)
1335
   #elif ENABLED(ADVANCE)
1338
 
1336
 

+ 2
- 2
Marlin/planner.h View File

210
     #if ENABLED(LIN_ADVANCE)
210
     #if ENABLED(LIN_ADVANCE)
211
       static float position_float[NUM_AXIS];
211
       static float position_float[NUM_AXIS];
212
       static float extruder_advance_k;
212
       static float extruder_advance_k;
213
-      static float E_D_ratio;
213
+      static float advance_ed_ratio;
214
     #endif
214
     #endif
215
 
215
 
216
     #if ENABLED(ULTRA_LCD)
216
     #if ENABLED(ULTRA_LCD)
269
     #if ENABLED(LIN_ADVANCE)
269
     #if ENABLED(LIN_ADVANCE)
270
       static void set_extruder_advance_k(const float &k) { extruder_advance_k = k; };
270
       static void set_extruder_advance_k(const float &k) { extruder_advance_k = k; };
271
       static float get_extruder_advance_k() { return extruder_advance_k; };
271
       static float get_extruder_advance_k() { return extruder_advance_k; };
272
-      static void set_E_D_ratio(const float &ratio) { E_D_ratio = ratio; };
272
+      static void set_advance_ed_ratio(const float &ratio) { advance_ed_ratio = ratio; };
273
     #endif
273
     #endif
274
 
274
 
275
     /**
275
     /**

Loading…
Cancel
Save