Skip to content

Commit 69c3980

Browse files
committed
fix fan speed after Toolchange, max_vol_speed with first_layer_flow_ratio
2 parents 2a34465 + fa5170f commit 69c3980

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

src/libslic3r/GCode.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5396,13 +5396,19 @@ double_t GCode::_compute_speed_mm_per_sec(const ExtrusionPath& path, double spee
53965396
if (first_layer_over_raft_speed > 0)
53975397
speed = std::min(first_layer_over_raft_speed, speed);
53985398
}
5399+
5400+
// the first_layer_flow_ratio is added at the last time to take into account everything. So do the compute like it's here.
5401+
double path_mm3_per_mm = path.mm3_per_mm;
5402+
if (m_layer->bottom_z() < EPSILON)
5403+
path_mm3_per_mm *= this->config().first_layer_flow_ratio.get_abs_value(1);
53995404
// cap speed with max_volumetric_speed anyway (even if user is not using autospeed)
5400-
if (m_config.max_volumetric_speed.value > 0 && path.mm3_per_mm > 0) {
5401-
speed = std::min(m_config.max_volumetric_speed.value / path.mm3_per_mm, speed);
5405+
if (m_config.max_volumetric_speed.value > 0 && path_mm3_per_mm > 0) {
5406+
speed = std::min(m_config.max_volumetric_speed.value / path_mm3_per_mm, speed);
54025407
}
5408+
// filament cap (volumetric & raw speed)
54035409
double filament_max_volumetric_speed = EXTRUDER_CONFIG_WITH_DEFAULT(filament_max_volumetric_speed, 0);
5404-
if (filament_max_volumetric_speed > 0) {
5405-
speed = std::min(filament_max_volumetric_speed / path.mm3_per_mm, speed);
5410+
if (filament_max_volumetric_speed > 0 && path_mm3_per_mm > 0) {
5411+
speed = std::min(filament_max_volumetric_speed / path_mm3_per_mm, speed);
54065412
}
54075413
double filament_max_speed = EXTRUDER_CONFIG_WITH_DEFAULT(filament_max_speed, 0);
54085414
if (filament_max_speed > 0) {

src/libslic3r/GCode/CoolingBuffer.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace Slic3r {
1919

20-
CoolingBuffer::CoolingBuffer(GCode &gcodegen) : m_config(gcodegen.config()), m_toolchange_prefix(gcodegen.writer().toolchange_prefix()), m_current_extruder(0)
20+
CoolingBuffer::CoolingBuffer(GCode &gcodegen) : m_config(gcodegen.config()), m_current_extruder(0)
2121
{
2222
this->reset(gcodegen.writer().get_position());
2323

@@ -459,7 +459,6 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
459459
if (boost::contains(sline, ";_EXTRUDE_SET_SPEED") && ! wipe) {
460460
line.type |= CoolingLine::TYPE_ADJUSTABLE;
461461
active_speed_modifier = adjustment->lines.size();
462-
std::cout << "TYPE_(not)_ADJUSTABLE!\n";
463462
if (boost::contains(sline, ";_EXTRUDE_SET_SPEED_MAYBE"))
464463
line.type |= CoolingLine::TYPE_ADJUSTABLE_MAYBE;
465464
}
@@ -544,8 +543,9 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
544543
}
545544
}
546545
active_speed_modifier = size_t(-1);
547-
} else if (boost::starts_with(sline, m_toolchange_prefix) || boost::starts_with(sline, ";_TOOLCHANGE")) {
548-
int prefix = boost::starts_with(sline, ";_TOOLCHANGE") ? 13 : m_toolchange_prefix.size();
546+
} else if (boost::starts_with(sline, ";_TOOLCHANGE")) {
547+
//not using m_toolchange_prefix anymore because there is no use case for it, there is always a _TOOLCHANGE for when a fan change is needed.
548+
int prefix = 13;
549549
uint16_t new_extruder = (uint16_t)atoi(sline.c_str() + prefix);
550550
// Only change extruder in case the number is meaningful. User could provide an out-of-range index through custom gcodes - those shall be ignored.
551551
if (new_extruder < map_extruder_to_per_extruder_adjustment.size()) {
@@ -556,8 +556,7 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
556556
current_extruder = new_extruder;
557557
adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]];
558558
}
559-
}
560-
else {
559+
} else {
561560
// Only log the error in case of MM printer. Single extruder printers likely ignore any T anyway.
562561
if (map_extruder_to_per_extruder_adjustment.size() > 1)
563562
BOOST_LOG_TRIVIAL(error) << "CoolingBuffer encountered an invalid toolchange, maybe from a custom gcode: " << sline;
@@ -957,7 +956,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
957956
}
958957
if (fan_speeds[0] != m_fan_speed) {
959958
m_fan_speed = fan_speeds[0];
960-
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);
959+
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed,
960+
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
961+
std::string("set fan for new extruder"));
961962
}
962963
};
963964
//set to know all fan modifiers that can be applied ( TYPE_BRIDGE_FAN_END, TYPE_TOP_FAN_START, TYPE_SUPP_INTER_FAN_START, TYPE_EXTERNAL_PERIMETER).
@@ -984,7 +985,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
984985
} else if (line->type & CoolingLine::TYPE_STORE_FOR_WT) {
985986
stored_fan_speed = m_fan_speed;
986987
} else if (line->type & CoolingLine::TYPE_RESTORE_AFTER_WT) {
987-
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);
988+
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, stored_fan_speed,
989+
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
990+
"restore fan after wipe tower");
988991
} else if (line->type & CoolingLine::TYPE_EXTRUDE_START) {
989992
assert(CoolingLine::to_extrusion_role(uint32_t(line->type)) != 0);
990993
extrude_tree.push_back(CoolingLine::to_extrusion_role(uint32_t(line->type)));
@@ -1080,14 +1083,19 @@ std::string CoolingBuffer::apply_layer_cooldown(
10801083
bool fan_set = false;
10811084
for (size_t i = extrude_tree.size() - 1; i < extrude_tree.size(); --i) {
10821085
if (fan_control[extrude_tree[i]]) {
1083-
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, fan_speeds[extrude_tree[i]], EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage);
1086+
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments,
1087+
fan_speeds[extrude_tree[i]],
1088+
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
1089+
std::string("set fan for ") + ExtrusionEntity::role_to_string(extrude_tree[i]));
10841090
fan_set = true;
10851091
break;
10861092
}
10871093
}
10881094
if (!fan_set) {
10891095
//return to default
1090-
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);
1096+
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed,
1097+
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
1098+
"set default fan");
10911099
}
10921100
fan_need_set = false;
10931101
}

src/libslic3r/GCode/CoolingBuffer.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class CoolingBuffer {
5050
std::vector<unsigned int> m_extruder_ids;
5151
// Highest of m_extruder_ids plus 1.
5252
uint16_t m_num_extruders { 0 };
53-
const std::string m_toolchange_prefix;
5453
// Referencs GCode::m_config, which is FullPrintConfig. While the PrintObjectConfig slice of FullPrintConfig is being modified,
5554
// the PrintConfig slice of FullPrintConfig is constant, thus no thread synchronization is required.
5655
const PrintConfig &m_config;

src/libslic3r/GCodeWriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ std::string GCodeWriter::unlift()
793793
return gcode;
794794
}
795795

796-
std::string GCodeWriter::set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage)
796+
std::string GCodeWriter::set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage, const std::string comment/*=""*/)
797797
{
798798
/*
799799
std::ostringstream gcode;
@@ -858,7 +858,8 @@ std::string GCodeWriter::set_fan(const GCodeFlavor gcode_flavor, bool gcode_comm
858858
}
859859
gcode << (fan_baseline * (fan_speed / 100.0));
860860
}
861-
if (gcode_comments) gcode << " ; enable fan";
861+
if (gcode_comments)
862+
gcode << " ; " << (comment.empty() ? "enable fan" : comment);
862863
gcode << "\n";
863864
}
864865
return gcode.str();

src/libslic3r/GCodeWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class GCodeWriter {
8383
Vec3d get_unlifted_position() const { return m_pos - Vec3d{0, 0, m_extra_lift + m_lifted}; }
8484

8585
// To be called by the CoolingBuffer from another thread.
86-
static std::string set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage);
86+
static std::string set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage, const std::string comment = "");
8787
// To be called by the main thread. It always emits the G-code, it does remember the previous state to be able to reset after the wipe tower (but remove that when the wipe tower will be extrusions and not string).
8888
// Keeping the state is left to the CoolingBuffer, which runs asynchronously on another thread.
8989
std::string set_fan(uint8_t speed, uint16_t default_tool = 0);

version.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ set(SLIC3R_APP_KEY "SuperSlicer")
99
set(SLIC3R_APP_CMD "superslicer")
1010
# versions
1111
set(SLIC3R_VERSION "2.5.59")
12-
set(SLIC3R_VERSION_FULL "2.5.59.2")
12+
set(SLIC3R_VERSION_FULL "2.5.59.3")
1313
set(SLIC3R_BUILD_ID "${SLIC3R_APP_KEY}_${SLIC3R_VERSION_FULL}+UNKNOWN")
14-
set(SLIC3R_RC_VERSION "2,5,59,2")
14+
set(SLIC3R_RC_VERSION "2,5,59,3")
1515
set(SLIC3R_RC_VERSION_DOTS "${SLIC3R_VERSION_FULL}")
1616

1717
# Same as the slicer name but for gcodeviewer

0 commit comments

Comments
 (0)