Skip to content

Commit

Permalink
Fan cooling: move min_fan_speed to printer. fan_always_on changed to …
Browse files Browse the repository at this point in the history
…a real default_fan_speed

 - updated helper text.
 - now default will be used when a field is deactivated.
 - default_fan_speed =0 is a bit like the old fan_always_on to false.
 - min fan speed is a real min for fan speed (if not stopped)
Should be easier to understand.
#4009
  • Loading branch information
supermerill committed Dec 23, 2023
1 parent 17b1825 commit 4cfa978
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 153 deletions.
11 changes: 5 additions & 6 deletions resources/ui_layout/default/filament.ui
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ group:Print speed override

page:Cooling:time
group:Fan speed - default
setting:id$0:label$Run the fan at default speed when possible:fan_always_on
line:Disable fan for the first
setting:id$0:width$5:label$_:sidetext_width$7:disable_fan_first_layers
setting:id$0:width$5:label_width$12:full_fan_speed_layer
end_line
setting:id$0:min_fan_speed
setting:id$0:default_fan_speed
line:Perimeter fan speed
setting:id$0:label_width$12:label$Internal:perimeter_fan_speed
setting:id$0:label_width$12:label$External:external_perimeter_fan_speed
Expand All @@ -53,6 +48,10 @@ group:Fan speed - default
setting:id$0:label_width$12:label$Overhangs:overhangs_fan_speed
line:Gap fill fan speed
setting:id$0:label_width$12:label$Gap fill:gap_fill_fan_speed
line:Disable fan for the first
setting:id$0:width$5:label$_:sidetext_width$7:disable_fan_first_layers
setting:id$0:width$5:label_width$12:full_fan_speed_layer
end_line
group:Short layer time - began to increase base fan speed
setting:id$0:fan_below_layer_time
setting:id$0:label$Max fan speed:max_fan_speed
Expand Down
1 change: 1 addition & 0 deletions resources/ui_layout/default/printer_fff.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ group:silent_mode_event:Firmware
end_line
setting:gcode_filename_illegal_char
group:Cooling fan
setting:fan_printer_min_speed
line:Speedup time
setting:label$:fan_speedup_time
setting:label$Only for overhangs:fan_speedup_overhangs
Expand Down
63 changes: 47 additions & 16 deletions src/libslic3r/GCode/CoolingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,24 @@ std::string CoolingBuffer::apply_layer_cooldown(
int fan_speeds[ExtrusionRole::erCount];
int default_fan_speed[ExtrusionRole::erCount];
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_current_extruder)
int min_fan_speed = EXTRUDER_CONFIG(min_fan_speed);
const int min_fan_speed = m_config.fan_printer_min_speed;
assert(min_fan_speed >= 0);
int initial_default_fan_speed = EXTRUDER_CONFIG(default_fan_speed);
//if default_fan_speed activated, be sure it's at least the mins
if (initial_default_fan_speed > 0 && initial_default_fan_speed < min_fan_speed)
initial_default_fan_speed = min_fan_speed;
// 0 was deprecated, replaced by 1: allow 1 to still be 0 (and it's now deprecated)
if (initial_default_fan_speed == 1)
initial_default_fan_speed = 0;
//initialise the speed array
for (int i = 0; i < ExtrusionRole::erCount; i++) {
fan_control[i] = false;
fan_speeds[i] = 0;
default_fan_speed[i] = min_fan_speed;
default_fan_speed[i] = initial_default_fan_speed;
// 0 was deprecated, replaced by 1: allow 1 to still be 0 (and it's now deprecated)
if (default_fan_speed[i] == 1) default_fan_speed[i] = 0;
}
//set the fan controls
default_fan_speed[ExtrusionRole::erBridgeInfill] = EXTRUDER_CONFIG(bridge_fan_speed);
default_fan_speed[ExtrusionRole::erInternalBridgeInfill] = EXTRUDER_CONFIG(bridge_internal_fan_speed);
default_fan_speed[ExtrusionRole::erTopSolidInfill] = EXTRUDER_CONFIG(top_fan_speed);
Expand All @@ -878,8 +888,17 @@ std::string CoolingBuffer::apply_layer_cooldown(
default_fan_speed[ExtrusionRole::erInternalInfill] = EXTRUDER_CONFIG(infill_fan_speed);
default_fan_speed[ExtrusionRole::erOverhangPerimeter] = EXTRUDER_CONFIG(overhangs_fan_speed);
default_fan_speed[ExtrusionRole::erGapFill] = EXTRUDER_CONFIG(gap_fill_fan_speed);
// if default is enabled, it takes over the settings that are disabled.
if (initial_default_fan_speed >= 0) {
for (int i = 0; i < ExtrusionRole::erCount; i++) {
// this setting is disbaled. As default is not, it will use the default value
if (default_fan_speed[i] < 0) {
default_fan_speed[i] = initial_default_fan_speed;
}
}
}
auto change_extruder_set_fan = [this, layer_id, layer_time, &new_gcode,
&fan_control, &fan_speeds, &default_fan_speed, &min_fan_speed]()
&fan_control, &fan_speeds, &default_fan_speed, initial_default_fan_speed, min_fan_speed]()
{
int disable_fan_first_layers = EXTRUDER_CONFIG(disable_fan_first_layers);
// Is the fan speed ramp enabled?
Expand All @@ -891,8 +910,8 @@ std::string CoolingBuffer::apply_layer_cooldown(
for (int i = 0; i < ExtrusionRole::erCount; i++) {
fan_speeds[i] = default_fan_speed[i];
}
//if not always on, the default is "no fan" and not the min.
if (!EXTRUDER_CONFIG(fan_always_on)) {
//fan_speeds[0] carry the current default value. ensure it's not negative.
if (initial_default_fan_speed <= 0) {
fan_speeds[0] = 0;
}
if (layer_time < slowdown_below_layer_time && fan_below_layer_time > 0) {
Expand Down Expand Up @@ -925,13 +944,19 @@ std::string CoolingBuffer::apply_layer_cooldown(
fan_speeds[idx] = std::clamp(int(float(fan_speeds[idx]) * factor + 0.01f), 0, 255);
}
}
//only activate fan control if the fan speed is higher than default
fan_control[0] = true;
//only activate fan control if the fan speed is higher than min
fan_control[0] = fan_speeds[0] >= 0;
for (size_t i = 1; i < ExtrusionRole::erCount; i++) {
fan_control[i] = fan_speeds[i] >= 0 && fan_speeds[i] > fan_speeds[0];
fan_control[i] = fan_speeds[i] >= 0;
}

// if bridge_internal_fan is disabled, it takes the value of bridge_fan_control
// if bridge_fan is disabled, it takes the value of default_fan
if (!fan_control[ExtrusionRole::erBridgeInfill] && fan_control[0]) {
fan_control[ExtrusionRole::erBridgeInfill] = true;
fan_speeds[ExtrusionRole::erBridgeInfill] = fan_speeds[0];
}

// if bridge_internal_fan is disabled, it takes the value of bridge_fan
if (!fan_control[ExtrusionRole::erInternalBridgeInfill] && fan_control[ExtrusionRole::erBridgeInfill]) {
fan_control[ExtrusionRole::erInternalBridgeInfill] = true;
fan_speeds[ExtrusionRole::erInternalBridgeInfill] = fan_speeds[ExtrusionRole::erBridgeInfill];
Expand All @@ -957,7 +982,13 @@ std::string CoolingBuffer::apply_layer_cooldown(
fan_speeds[i] = 0;
}
}
if (fan_speeds[0] != m_fan_speed) {
// apply min fan speed, after the eventual speedup.
for (int i = 1; i < ExtrusionRole::erCount; i++) {
if (fan_control[i] && fan_speeds[i] > 0) {
fan_speeds[i] = std::max(fan_speeds[i], min_fan_speed);
}
}
if (fan_speeds[0] != m_fan_speed && fan_control[0]) {
m_fan_speed = fan_speeds[0];
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
Expand All @@ -968,7 +999,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
std::vector<ExtrusionRole> extrude_tree;
const char *pos = gcode.c_str();
int current_feedrate = 0;
int stored_fan_speed = m_fan_speed;
int stored_fan_speed = m_fan_speed < 0 ? 0 : m_fan_speed;
change_extruder_set_fan();
for (const CoolingLine *line : lines) {
const char *line_start = gcode.c_str() + line->line_start;
Expand All @@ -986,7 +1017,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
new_gcode.append(line_start, line_end - line_start);
}
} else if (line->type & CoolingLine::TYPE_STORE_FOR_WT) {
stored_fan_speed = m_fan_speed;
stored_fan_speed = m_fan_speed < 0 ? 0 : m_fan_speed;
} else if (line->type & CoolingLine::TYPE_RESTORE_AFTER_WT) {
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, stored_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
Expand Down Expand Up @@ -1099,10 +1130,10 @@ std::string CoolingBuffer::apply_layer_cooldown(
}
}
if (!fan_set) {
//return to default
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
"set default fan");
// return to default
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed < 0 ? 0 : m_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
"set default fan");
}
fan_need_set = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode/CoolingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CoolingBuffer {
uint16_t m_num_extruders { 0 };
// Referencs GCode::m_config, which is FullPrintConfig. While the PrintObjectConfig slice of FullPrintConfig is being modified,
// the PrintConfig slice of FullPrintConfig is constant, thus no thread synchronization is required.
const PrintConfig &m_config;
const FullPrintConfig &m_config;
uint16_t m_current_extruder;

//saved previous unslowed layer
Expand Down
10 changes: 6 additions & 4 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,11 @@ static std::vector<std::string> s_Preset_filament_options {
"filament_dip_insertion_speed",
"filament_dip_extraction_speed", //skinnydip params end
"temperature", "first_layer_temperature", "bed_temperature", "first_layer_bed_temperature",
// cooling
"fan_always_on",
"min_fan_speed",
"max_fan_speed",
// "cooling",
// "fan_always_on", (now default_fan_speed)
// "min_fan_speed", (now fan_printer_min_speed)
"default_fan_speed",
"max_fan_speed",
"bridge_fan_speed",
"bridge_internal_fan_speed",
"external_perimeter_fan_speed",
Expand Down Expand Up @@ -807,6 +808,7 @@ static std::vector<std::string> s_Preset_printer_options {
"fan_speedup_overhangs",
"fan_speedup_time",
"fan_percentage",
"fan_printer_min_speed",
"gcode_filename_illegal_char",
"gcode_flavor",
"gcode_precision_xyz",
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver& /* ne
"complete_objects_sort",
"cooling",
"default_acceleration",
"default_fan_speed",
"deretract_speed",
"disable_fan_first_layers",
"duplicate_distance",
Expand All @@ -94,12 +95,12 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver& /* ne
"extruder_fan_offset"
"extruder_temperature_offset",
"extrusion_multiplier",
"fan_always_on",
"fan_below_layer_time",
"fan_kickstart",
"fan_speedup_overhangs",
"fan_speedup_time",
"fan_percentage",
"fan_printer_min_speed",
"filament_colour",
"filament_custom_variables",
"filament_diameter",
Expand Down Expand Up @@ -134,7 +135,6 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver& /* ne
"max_print_height",
"max_print_speed",
"max_volumetric_speed",
"min_fan_speed",
"min_length",
"min_print_speed",
"milling_toolchange_end_gcode",
Expand Down
Loading

0 comments on commit 4cfa978

Please sign in to comment.