ENH: Polynomial fitting via Gaussian regression for determining the filament_max_volumetric_speed

Jira: none
Change-Id: Iab1ef65f0546884c60d2a9e39213a07d76a1f483
(cherry picked from commit 186948cc91b12d547b7168104ba629d40c333d1b)
This commit is contained in:
weizhen.xie
2025-08-06 17:03:44 +08:00
committed by Noisyfox
parent 4333872b3d
commit 38a18dc086
282 changed files with 1460 additions and 277 deletions

View File

@@ -5797,6 +5797,28 @@ bool GCode::_needSAFC(const ExtrusionPath &path)
});
}
double GCode::calc_max_volumetric_speed(const double layer_height, const double line_width, const std::string co_str)
{
std::vector<double> cs;
std::stringstream ss(co_str);
std::string token;
while (std::getline(ss, token, ';')) {
try {
cs.push_back(std::stod(token));
} catch (...) {
std::cerr << "Transformation failed: " << token << std::endl;
}
}
if (cs.size() != 6 || std::all_of(cs.begin(), cs.end(), [](double v) { return v == 0; })) return std::numeric_limits<double>::max();
const double x = layer_height;
const double y = line_width;
double res = cs[0] * x * x + cs[1] * y * y + cs[2] * x * y + cs[3] * x + cs[4] * y + cs[5];
return res;
}
std::string GCode::_extrude(const ExtrusionPath &path, std::string description, double speed)
{
std::string gcode;
@@ -5959,8 +5981,10 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
}
}
//BBS: if not set the speed, then use the filament_max_volumetric_speed directly
double filament_max_volumetric_speed = calc_max_volumetric_speed(path.height, path.width, FILAMENT_CONFIG(volumetric_speed_coefficients));
filament_max_volumetric_speed = std::min(filament_max_volumetric_speed, FILAMENT_CONFIG(filament_max_volumetric_speed));
if (speed == 0)
speed = FILAMENT_CONFIG(filament_max_volumetric_speed) / _mm3_per_mm;
speed = filament_max_volumetric_speed / _mm3_per_mm;
if (this->on_first_layer()) {
//BBS: for solid infill of initial layer, speed can be higher as long as
//wall lines have be attached

View File

@@ -634,6 +634,7 @@ private:
int get_bed_temperature(const int extruder_id, const bool is_first_layer, const BedType bed_type) const;
int get_highest_bed_temperature(const bool is_first_layer,const Print &print) const;
double calc_max_volumetric_speed(const double layer_height, const double line_width, const std::string co_str);
std::string _extrude(const ExtrusionPath &path, std::string description = "", double speed = -1);
bool _needSAFC(const ExtrusionPath &path);
void print_machine_envelope(GCodeOutputStream& file, Print& print, int extruder_id);

View File

@@ -947,7 +947,7 @@ static std::vector<std::string> s_Preset_print_options {
"interlocking_beam", "interlocking_orientation", "interlocking_beam_layer_count", "interlocking_depth", "interlocking_boundary_avoidance", "interlocking_beam_width","calib_flowrate_topinfill_special_order",
};
static std::vector<std::string> s_Preset_filament_options {/*"filament_colour", */ "default_filament_colour", "required_nozzle_HRC", "filament_diameter", "pellet_flow_coefficient", "filament_type",
static std::vector<std::string> s_Preset_filament_options {/*"filament_colour", */ "default_filament_colour", "required_nozzle_HRC", "filament_diameter", "pellet_flow_coefficient", "volumetric_speed_coefficients", "filament_type",
"filament_soluble", "filament_is_support", "filament_printable",
"filament_max_volumetric_speed",
"filament_flow_ratio", "filament_density", "filament_adhesiveness_category", "filament_cost", "filament_minimal_purge_on_wipe_tower",

View File

@@ -130,6 +130,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"filament_colour",
"default_filament_colour",
"filament_diameter",
"volumetric_speed_coefficients",
"filament_density",
"filament_cost",
"filament_notes",

View File

@@ -2320,6 +2320,10 @@ void PrintConfigDef::init_fff_params()
def->min = 0;
def->set_default_value(new ConfigOptionFloats{ 0.4157 });
def = this->add("volumetric_speed_coefficients", coStrings);
def->label = L("Max volumetric speed multinomial coefficients");
def->set_default_value(new ConfigOptionStrings{""});
def = this->add("filament_shrink", coPercents);
def->label = L("Shrinkage (XY)");
// xgettext:no-c-format, no-boost-format
@@ -6521,7 +6525,7 @@ void PrintConfigDef::init_extruder_option_keys()
void PrintConfigDef::init_filament_option_keys()
{
m_filament_option_keys = {
"filament_diameter", "min_layer_height", "max_layer_height",
"filament_diameter", "min_layer_height", "max_layer_height","volumetric_speed_coefficients",
"retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
@@ -7518,7 +7522,8 @@ std::set<std::string> filament_options_with_variant = {
"nozzle_temperature_initial_layer",
"nozzle_temperature",
"filament_flush_volumetric_speed",
"filament_flush_temp"
"filament_flush_temp",
"volumetric_speed_coefficients"
};
// Parameters that are the same as the number of extruders

View File

@@ -1224,6 +1224,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionBool, fan_speedup_overhangs))
((ConfigOptionFloat, fan_speedup_time))
((ConfigOptionFloats, filament_diameter))
((ConfigOptionStrings, volumetric_speed_coefficients))
((ConfigOptionInts, filament_adhesiveness_category))
((ConfigOptionFloats, filament_density))
((ConfigOptionStrings, filament_type))