NEW:Add pre-start fan gcode for overhang lines.

when encountering overhang paths and the current fan speed is low, the fan is set to start 2 seconds earlier by default. This prevents cooling issues caused by delays in fan acceleration.

Change-Id: I9e9267b77f1e4d9a2b81bda16c1441703a7b28e7
This commit is contained in:
lingdong.gu 2025-01-14 16:07:12 +08:00 committed by lane.wei
parent bcbb08c303
commit d9ad4e81e9
7 changed files with 59 additions and 5 deletions

View File

@ -321,6 +321,10 @@ std::vector<PerExtruderAdjustments> GCodeEditor::parse_layer_gcode(
line.type = CoolingLine::TYPE_FORCE_RESUME_FAN;
} else if (boost::starts_with(sline, ";_SET_FAN_SPEED_CHANGING_LAYER")) {
line.type = CoolingLine::TYPE_SET_FAN_CHANGING_LAYER;
} else if (boost::starts_with(sline, "M624")) {
line.type = CoolingLine::TYPE_OBJECT_START;
} else if (boost::starts_with(sline, "M625")) {
line.type = CoolingLine::TYPE_OBJECT_END;
}
if (line.type != 0)
adjustment->lines.emplace_back(std::move(line));
@ -440,7 +444,34 @@ std::string GCodeEditor::write_layer_gcode(
m_set_fan_changing_layer = false;
m_set_addition_fan_changing_layer = false;
change_extruder_set_fan(SetFanType::sfChangingLayer);
for (const CoolingLine *line : lines) {
//BBS: start the fan earlier for overhangs
const float pre_start_overhang_fan_time = overhang_fan_control? m_config.pre_start_fan_time.get_at(m_current_extruder):0.f;
float cumulative_time = 0.f;
float search_time = 0.f;
for (int i = 0,j = 0; i < lines.size(); i++) {
const CoolingLine *line = lines[i];
if (pre_start_overhang_fan_time > 0.f && overhang_fan_speed > m_fan_speed) {
cumulative_time += line->time;
j = j<i ? i : j;
search_time = search_time<cumulative_time ? cumulative_time : search_time;
// bbs: search for the next overhang line in xx seconds
for (; search_time - cumulative_time < pre_start_overhang_fan_time && j < lines.size() && overhang_fan_control && m_current_fan_speed < overhang_fan_speed; j++) {
const CoolingLine *line_iter = lines[j];
//do not change fan speed for changing filament gcode
if (line_iter->type & CoolingLine::TYPE_FORCE_RESUME_FAN) {
//stop search when find a force resume fan command
break;
}
search_time += line_iter->time;
if (line_iter->type & CoolingLine::TYPE_OVERHANG_FAN_START) {
m_current_fan_speed = overhang_fan_speed;
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed);
break;
}
}
}
const char *line_start = gcode.c_str() + line->line_start;
const char *line_end = gcode.c_str() + line->line_end;
if (line_start > pos)
@ -453,7 +484,7 @@ std::string GCodeEditor::write_layer_gcode(
}
new_gcode.append(line_start, line_end - line_start);
} else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_START) {
if (overhang_fan_control) {
if (overhang_fan_control && m_current_fan_speed < overhang_fan_speed) {
//BBS
m_current_fan_speed = overhang_fan_speed;
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed);
@ -562,7 +593,15 @@ std::string GCodeEditor::write_layer_gcode(
new_gcode.append(end, line_end - end);
}
}
} else {
} else if (line->type & CoolingLine::TYPE_OBJECT_START) {
new_gcode.append(line_start, line_end - line_start);
if (pre_start_overhang_fan_time > 0.f && m_current_fan_speed > m_fan_speed)
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_current_fan_speed);
} else if (line->type & CoolingLine::TYPE_OBJECT_END) {
if (pre_start_overhang_fan_time > 0.f && m_current_fan_speed > m_fan_speed)
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed);
new_gcode.append(line_start, line_end - line_start);
}else {
new_gcode.append(line_start, line_end - line_start);
}
pos = line_end;

View File

@ -34,6 +34,8 @@ struct CoolingLine
TYPE_G3 = 1 << 13,
TYPE_FORCE_RESUME_FAN = 1 << 14,
TYPE_SET_FAN_CHANGING_LAYER = 1 << 15,
TYPE_OBJECT_START = 1 << 16,
TYPE_OBJECT_END = 1 << 17,
};
CoolingLine(unsigned int type, size_t line_start, size_t line_end)

View File

@ -918,7 +918,7 @@ static std::vector<std::string> s_Preset_filament_options {
// "bed_type",
//BBS:temperature_vitrification
"temperature_vitrification", "reduce_fan_stop_start_freq", "slow_down_for_layer_cooling", "fan_min_speed",
"fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "overhang_fan_threshold", "overhang_threshold_participating_cooling","close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed",
"fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "pre_start_fan_time", "overhang_fan_threshold", "overhang_threshold_participating_cooling","close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed",
"filament_start_gcode", "filament_end_gcode",
//exhaust fan control
"activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed",

View File

@ -101,6 +101,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
"pressure_advance",
"enable_overhang_bridge_fan"
"overhang_fan_speed",
"pre_start_fan_time",
"overhang_fan_threshold",
"overhang_threshold_participating_cooling",
"slow_down_for_layer_cooling",

View File

@ -916,6 +916,16 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionInts { 100 });
def = this->add("pre_start_fan_time", coFloats);
def->label = L("Pre start fan time");
def->tooltip = L("Force fan start early(0-5 second) when encountering overhangs. "
"This is because the fan needs time to physically increase its speed.");
def->sidetext = L("s");
def->min = 0.;
def->max = 5.;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{2.0});
def = this->add("overhang_fan_threshold", coEnums);
def->label = L("Cooling overhang threshold");
def->tooltip = L("Force cooling fan to be specific speed when overhang degree of printed part exceeds this value. "

View File

@ -1130,6 +1130,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE(
((ConfigOptionInts, textured_plate_temp_initial_layer))
((ConfigOptionBools, enable_overhang_bridge_fan))
((ConfigOptionInts, overhang_fan_speed))
((ConfigOptionFloats, pre_start_fan_time))
((ConfigOptionEnumsGeneric, overhang_fan_threshold))
((ConfigOptionEnumsGeneric, overhang_threshold_participating_cooling))
((ConfigOptionEnum<PrintSequence>,print_sequence))

View File

@ -3332,6 +3332,7 @@ void TabFilament::build()
optgroup->append_single_option_line("overhang_fan_threshold", "auto-cooling");
optgroup->append_single_option_line("overhang_threshold_participating_cooling", "auto-cooling");
optgroup->append_single_option_line("overhang_fan_speed", "auto-cooling");
optgroup->append_single_option_line("pre_start_fan_time", "auto-cooling");
optgroup = page->new_optgroup(L("Auxiliary part cooling fan"), L"param_cooling_fan");
optgroup->append_single_option_line("additional_cooling_fan_speed");
@ -3464,7 +3465,7 @@ void TabFilament::toggle_options()
toggle_option("slow_down_min_speed", cooling);
bool has_enable_overhang_bridge_fan = m_config->opt_bool("enable_overhang_bridge_fan", 0);
for (auto el : { "overhang_fan_speed", "overhang_fan_threshold" })
for (auto el : {"overhang_fan_speed", "pre_start_fan_time", "overhang_fan_threshold"})
toggle_option(el, has_enable_overhang_bridge_fan);
bool support_air_filtration = m_preset_bundle->printers.get_edited_preset().config.opt_bool("support_air_filtration");