Browse Source

Reduce E_D_ratio code

pull/1/head
Scott Lahteine 8 years ago
parent
commit
b3e2bd6f29
  1. 39
      Marlin/Marlin_main.cpp
  2. 18
      Marlin/planner.cpp
  3. 4
      Marlin/planner.h

39
Marlin/Marlin_main.cpp

@ -7602,39 +7602,22 @@ inline void gcode_M503() {
inline void gcode_M905() { inline void gcode_M905() {
stepper.synchronize(); stepper.synchronize();
float newD = -1; const float newK = code_seen('K') ? code_value_float() : -1,
float newW = -1; newD = code_seen('D') ? code_value_float() : -1,
float newH = -1; newW = code_seen('W') ? code_value_float() : -1,
newH = code_seen('H') ? code_value_float() : -1;
if (code_seen('K')) { if (newK >= 0.0) planner.set_extruder_advance_k(newK);
float newK = code_value_float();
if (newK >= 0.0)
planner.set_extruder_advance_k(newK);
}
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPAIR("Advance factor: ", planner.get_extruder_advance_k()); SERIAL_ECHOLNPAIR("Advance factor: ", planner.get_extruder_advance_k());
SERIAL_EOL;
if (code_seen('D')) if (newD >= 0 || newW >= 0 || newH >= 0) {
newD = code_value_float(); const float ratio = (!newD || !newW || !newH) ? 0 : (newW * newH) / (sq(newD * 0.5) * M_PI);
if (code_seen('W')) planner.set_advance_ed_ratio(ratio);
newW = code_value_float();
if (code_seen('H'))
newH = code_value_float();
if (newD > 0 && newW > 0 && newH > 0) {
float E_D_ratio = newW * newH / (sq(newD / 2) * M_PI);
planner.set_E_D_ratio(E_D_ratio);
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOPAIR("E/D ratio: ", E_D_ratio); SERIAL_ECHOPGM("E/D ratio: ");
SERIAL_EOL; if (ratio) SERIAL_ECHOLN(ratio); else SERIAL_ECHOLNPGM("Automatic");
}
else if (newD != -1 || newW != -1 || newH != -1) {
planner.set_E_D_ratio(0);
SERIAL_ECHO_START;
SERIAL_ECHOPGM("E/D ratio: Automatic");
SERIAL_EOL;
} }
} }
#endif #endif

18
Marlin/planner.cpp

@ -142,7 +142,7 @@ float Planner::previous_speed[NUM_AXIS],
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
float Planner::extruder_advance_k = LIN_ADVANCE_K, float Planner::extruder_advance_k = LIN_ADVANCE_K,
Planner::E_D_ratio = LIN_ADVANCE_E_D_RATIO, Planner::advance_ed_ratio = LIN_ADVANCE_E_D_RATIO,
Planner::position_float[NUM_AXIS] = { 0 }; Planner::position_float[NUM_AXIS] = { 0 };
#endif #endif
@ -1324,15 +1324,13 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
&& extruder_advance_k && extruder_advance_k
&& (uint32_t)esteps != block->step_event_count && (uint32_t)esteps != block->step_event_count
&& de_float > 0.0; && de_float > 0.0;
if (block->use_advance_lead) { if (block->use_advance_lead)
// Check if we should use the fixed E_D_ratio block->abs_adv_steps_multiplier8 = lround(
if (UNEAR_ZERO(E_D_ratio)) { extruder_advance_k
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); * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
} * (block->nominal_speed / (float)block->nominal_rate)
else { * axis_steps_per_mm[E_AXIS_N] * 256.0
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); );
}
}
#elif ENABLED(ADVANCE) #elif ENABLED(ADVANCE)

4
Marlin/planner.h

@ -210,7 +210,7 @@ class Planner {
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
static float position_float[NUM_AXIS]; static float position_float[NUM_AXIS];
static float extruder_advance_k; static float extruder_advance_k;
static float E_D_ratio; static float advance_ed_ratio;
#endif #endif
#if ENABLED(ULTRA_LCD) #if ENABLED(ULTRA_LCD)
@ -269,7 +269,7 @@ class Planner {
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
static void set_extruder_advance_k(const float &k) { extruder_advance_k = k; }; static void set_extruder_advance_k(const float &k) { extruder_advance_k = k; };
static float get_extruder_advance_k() { return extruder_advance_k; }; static float get_extruder_advance_k() { return extruder_advance_k; };
static void set_E_D_ratio(const float &ratio) { E_D_ratio = ratio; }; static void set_advance_ed_ratio(const float &ratio) { advance_ed_ratio = ratio; };
#endif #endif
/** /**

Loading…
Cancel
Save