Add pre-calculated planner.e_factor

This commit is contained in:
Scott Lahteine
2017-11-10 02:26:49 -06:00
parent 600c85226e
commit cba9c1cf9e
9 changed files with 45 additions and 21 deletions

View File

@@ -138,8 +138,8 @@
* 533 M208 R swap_retract_recover_feedrate_mm_s (float)
*
* Volumetric Extrusion: 21 bytes
* 537 M200 D volumetric_enabled (bool)
* 538 M200 T D filament_size (float x5) (T0..3)
* 537 M200 D parser.volumetric_enabled (bool)
* 538 M200 T D planner.filament_size (float x5) (T0..3)
*
* HAVE_TMC2130: 22 bytes
* 558 M906 X Stepper X current (uint16_t)

View File

@@ -802,7 +802,7 @@ void prepare_move_to_destination() {
}
#endif // PREVENT_COLD_EXTRUSION
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
if (FABS(destination[E_AXIS] - current_position[E_AXIS]) > (EXTRUDE_MAXLENGTH) / planner.volumetric_multiplier[active_extruder]) {
if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);

View File

@@ -106,7 +106,8 @@ float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
// Initialized by settings.load()
float Planner::filament_size[EXTRUDERS], // As a baseline for the multiplier, filament diameter
float Planner::e_factor[EXTRUDERS], // The flow percentage and volumetric multiplier combine to scale E movement
Planner::filament_size[EXTRUDERS], // As a baseline for the multiplier, filament diameter
Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
@@ -546,8 +547,10 @@ inline float calculate_volumetric_multiplier(const float &diameter) {
}
void Planner::calculate_volumetric_multipliers() {
for (uint8_t i = 0; i < COUNT(filament_size); i++)
for (uint8_t i = 0; i < COUNT(filament_size); i++) {
volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
refresh_e_factor(i);
}
}
#if PLANNER_LEVELING
@@ -740,8 +743,6 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
long de = target[E_AXIS] - position[E_AXIS];
const float e_factor = volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
#if ENABLED(LIN_ADVANCE)
float de_float = e - position_float[E_AXIS]; // Should this include e_factor?
#endif
@@ -761,8 +762,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
}
#endif // PREVENT_COLD_EXTRUSION
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
const int32_t de_mm = labs(de * e_factor);
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
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
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
de = 0; // no difference
#if ENABLED(LIN_ADVANCE)
@@ -803,7 +803,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
#endif
if (de < 0) SBI(dm, E_AXIS);
const float esteps_float = de * e_factor;
const float esteps_float = de * e_factor[extruder];
const int32_t esteps = abs(esteps_float) + 0.5;
// Calculate the buffer head after we push this byte

View File

@@ -146,7 +146,8 @@ class Planner {
static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
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
static float e_factor[EXTRUDERS], // The flow percentage and volumetric multiplier combine to scale E movement
filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
// May be auto-adjusted by a filament width sensor
@@ -246,6 +247,10 @@ class Planner {
static void reset_acceleration_rates();
static void refresh_positioning();
FORCE_INLINE static void refresh_e_factor(const uint8_t e) {
e_factor[e] = volumetric_multiplier[e] * flow_percentage[e] * 0.01;
}
// Manage fans, paste pressure, etc.
static void check_axes_activity();

View File

@@ -818,6 +818,7 @@ void Temperature::manage_heater() {
// the nominal filament diameter then square it to get an area
const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
planner.refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
}
#endif // FILAMENT_WIDTH_SENSOR