Move Volumetric methods to Planner
This commit is contained in:
@ -138,7 +138,7 @@
|
||||
*
|
||||
* Volumetric Extrusion: 21 bytes
|
||||
* 537 M200 D parser.volumetric_enabled (bool)
|
||||
* 538 M200 T D filament_size (float x5) (T0..3)
|
||||
* 538 M200 T D planner.filament_size (float x5) (T0..3)
|
||||
*
|
||||
* HAVE_TMC2130: 20 bytes
|
||||
* 558 M906 X Stepper X current (uint16_t)
|
||||
@ -224,7 +224,7 @@ void MarlinSettings::postprocess() {
|
||||
thermalManager.updatePID();
|
||||
#endif
|
||||
|
||||
calculate_volumetric_multipliers();
|
||||
planner.calculate_volumetric_multipliers();
|
||||
|
||||
#if HAS_HOME_OFFSET || ENABLED(DUAL_X_CARRIAGE)
|
||||
// Software endstops depend on home_offset
|
||||
@ -509,7 +509,7 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
// Save filament sizes
|
||||
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
|
||||
if (q < COUNT(filament_size)) dummy = filament_size[q];
|
||||
if (q < COUNT(planner.filament_size)) dummy = planner.filament_size[q];
|
||||
EEPROM_WRITE(dummy);
|
||||
}
|
||||
|
||||
@ -895,7 +895,7 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
|
||||
EEPROM_READ(dummy);
|
||||
if (q < COUNT(filament_size)) filament_size[q] = dummy;
|
||||
if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
|
||||
}
|
||||
|
||||
uint16_t val;
|
||||
@ -1260,8 +1260,8 @@ void MarlinSettings::reset() {
|
||||
false
|
||||
#endif
|
||||
;
|
||||
for (uint8_t q = 0; q < COUNT(filament_size); q++)
|
||||
filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
|
||||
for (uint8_t q = 0; q < COUNT(planner.filament_size); q++)
|
||||
planner.filament_size[q] = DEFAULT_NOMINAL_FILAMENT_DIA;
|
||||
|
||||
endstops.enable_globally(
|
||||
#if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
|
||||
@ -1388,23 +1388,23 @@ void MarlinSettings::reset() {
|
||||
}
|
||||
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M200 D", filament_size[0]);
|
||||
SERIAL_ECHOPAIR(" M200 D", planner.filament_size[0]);
|
||||
SERIAL_EOL();
|
||||
#if EXTRUDERS > 1
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M200 T1 D", filament_size[1]);
|
||||
SERIAL_ECHOPAIR(" M200 T1 D", planner.filament_size[1]);
|
||||
SERIAL_EOL();
|
||||
#if EXTRUDERS > 2
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M200 T2 D", filament_size[2]);
|
||||
SERIAL_ECHOPAIR(" M200 T2 D", planner.filament_size[2]);
|
||||
SERIAL_EOL();
|
||||
#if EXTRUDERS > 3
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M200 T3 D", filament_size[3]);
|
||||
SERIAL_ECHOPAIR(" M200 T3 D", planner.filament_size[3]);
|
||||
SERIAL_EOL();
|
||||
#if EXTRUDERS > 4
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M200 T4 D", filament_size[4]);
|
||||
SERIAL_ECHOPAIR(" M200 T4 D", planner.filament_size[4]);
|
||||
SERIAL_EOL();
|
||||
#endif // EXTRUDERS > 4
|
||||
#endif // EXTRUDERS > 3
|
||||
|
@ -105,6 +105,10 @@ 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
|
||||
Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
|
||||
|
||||
uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
|
||||
Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
|
||||
|
||||
@ -539,6 +543,16 @@ void Planner::check_axes_activity() {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline float calculate_volumetric_multiplier(const float &diameter) {
|
||||
if (!parser.volumetric_enabled || diameter == 0) return 1.0;
|
||||
return 1.0 / CIRCLE_AREA(diameter * 0.5);
|
||||
}
|
||||
|
||||
void Planner::calculate_volumetric_multipliers() {
|
||||
for (uint8_t i = 0; i < COUNT(filament_size); i++)
|
||||
volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
|
||||
}
|
||||
|
||||
#if PLANNER_LEVELING
|
||||
/**
|
||||
* lx, ly, lz - logical (cartesian, not delta) positions in mm
|
||||
|
@ -151,6 +151,10 @@ 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
|
||||
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
|
||||
|
||||
static float max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
|
||||
axis_steps_per_mm[XYZE_N],
|
||||
steps_to_mm[XYZE_N];
|
||||
@ -254,6 +258,16 @@ class Planner {
|
||||
|
||||
static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
|
||||
|
||||
// Update multipliers based on new diameter measurements
|
||||
static void calculate_volumetric_multipliers();
|
||||
|
||||
FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
|
||||
filament_size[e] = v;
|
||||
// make sure all extruders have some sane value for the filament size
|
||||
for (uint8_t i = 0; i < COUNT(filament_size); i++)
|
||||
if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
|
||||
}
|
||||
|
||||
#if PLANNER_LEVELING
|
||||
|
||||
#define ARG_X float lx
|
||||
|
@ -775,7 +775,7 @@ void Temperature::manage_heater() {
|
||||
// Get the delayed info and add 100 to reconstitute to a percent of
|
||||
// the nominal filament diameter then square it to get an area
|
||||
const float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
|
||||
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
|
||||
planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vmroot <= 0.1 ? 0.01 : sq(vmroot);
|
||||
}
|
||||
#endif // FILAMENT_WIDTH_SENSOR
|
||||
|
||||
|
Reference in New Issue
Block a user