Skip to content

Commit

Permalink
fix fan speed after Toolchange, max_vol_speed with first_layer_flow_r…
Browse files Browse the repository at this point in the history
…atio
  • Loading branch information
supermerill committed Nov 23, 2023
2 parents 2a34465 + fa5170f commit 69c3980
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
14 changes: 10 additions & 4 deletions src/libslic3r/GCode.cpp
Expand Up @@ -5396,13 +5396,19 @@ double_t GCode::_compute_speed_mm_per_sec(const ExtrusionPath& path, double spee
if (first_layer_over_raft_speed > 0)
speed = std::min(first_layer_over_raft_speed, speed);
}

// the first_layer_flow_ratio is added at the last time to take into account everything. So do the compute like it's here.
double path_mm3_per_mm = path.mm3_per_mm;
if (m_layer->bottom_z() < EPSILON)
path_mm3_per_mm *= this->config().first_layer_flow_ratio.get_abs_value(1);
// cap speed with max_volumetric_speed anyway (even if user is not using autospeed)
if (m_config.max_volumetric_speed.value > 0 && path.mm3_per_mm > 0) {
speed = std::min(m_config.max_volumetric_speed.value / path.mm3_per_mm, speed);
if (m_config.max_volumetric_speed.value > 0 && path_mm3_per_mm > 0) {
speed = std::min(m_config.max_volumetric_speed.value / path_mm3_per_mm, speed);
}
// filament cap (volumetric & raw speed)
double filament_max_volumetric_speed = EXTRUDER_CONFIG_WITH_DEFAULT(filament_max_volumetric_speed, 0);
if (filament_max_volumetric_speed > 0) {
speed = std::min(filament_max_volumetric_speed / path.mm3_per_mm, speed);
if (filament_max_volumetric_speed > 0 && path_mm3_per_mm > 0) {
speed = std::min(filament_max_volumetric_speed / path_mm3_per_mm, speed);
}
double filament_max_speed = EXTRUDER_CONFIG_WITH_DEFAULT(filament_max_speed, 0);
if (filament_max_speed > 0) {
Expand Down
28 changes: 18 additions & 10 deletions src/libslic3r/GCode/CoolingBuffer.cpp
Expand Up @@ -17,7 +17,7 @@

namespace Slic3r {

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

Expand Down Expand Up @@ -459,7 +459,6 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
if (boost::contains(sline, ";_EXTRUDE_SET_SPEED") && ! wipe) {
line.type |= CoolingLine::TYPE_ADJUSTABLE;
active_speed_modifier = adjustment->lines.size();
std::cout << "TYPE_(not)_ADJUSTABLE!\n";
if (boost::contains(sline, ";_EXTRUDE_SET_SPEED_MAYBE"))
line.type |= CoolingLine::TYPE_ADJUSTABLE_MAYBE;
}
Expand Down Expand Up @@ -544,8 +543,9 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
}
}
active_speed_modifier = size_t(-1);
} else if (boost::starts_with(sline, m_toolchange_prefix) || boost::starts_with(sline, ";_TOOLCHANGE")) {
int prefix = boost::starts_with(sline, ";_TOOLCHANGE") ? 13 : m_toolchange_prefix.size();
} else if (boost::starts_with(sline, ";_TOOLCHANGE")) {
//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.
int prefix = 13;
uint16_t new_extruder = (uint16_t)atoi(sline.c_str() + prefix);
// Only change extruder in case the number is meaningful. User could provide an out-of-range index through custom gcodes - those shall be ignored.
if (new_extruder < map_extruder_to_per_extruder_adjustment.size()) {
Expand All @@ -556,8 +556,7 @@ std::vector<PerExtruderAdjustments> CoolingBuffer::parse_layer_gcode(const std::
current_extruder = new_extruder;
adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]];
}
}
else {
} else {
// Only log the error in case of MM printer. Single extruder printers likely ignore any T anyway.
if (map_extruder_to_per_extruder_adjustment.size() > 1)
BOOST_LOG_TRIVIAL(error) << "CoolingBuffer encountered an invalid toolchange, maybe from a custom gcode: " << sline;
Expand Down Expand Up @@ -957,7 +956,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
}
if (fan_speeds[0] != m_fan_speed) {
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);
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,
std::string("set fan for new extruder"));
}
};
//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).
Expand All @@ -984,7 +985,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
} else if (line->type & CoolingLine::TYPE_STORE_FOR_WT) {
stored_fan_speed = 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);
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,
"restore fan after wipe tower");
} else if (line->type & CoolingLine::TYPE_EXTRUDE_START) {
assert(CoolingLine::to_extrusion_role(uint32_t(line->type)) != 0);
extrude_tree.push_back(CoolingLine::to_extrusion_role(uint32_t(line->type)));
Expand Down Expand Up @@ -1080,14 +1083,19 @@ std::string CoolingBuffer::apply_layer_cooldown(
bool fan_set = false;
for (size_t i = extrude_tree.size() - 1; i < extrude_tree.size(); --i) {
if (fan_control[extrude_tree[i]]) {
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);
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,
std::string("set fan for ") + ExtrusionEntity::role_to_string(extrude_tree[i]));
fan_set = true;
break;
}
}
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);
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");
}
fan_need_set = false;
}
Expand Down
1 change: 0 additions & 1 deletion src/libslic3r/GCode/CoolingBuffer.hpp
Expand Up @@ -50,7 +50,6 @@ class CoolingBuffer {
std::vector<unsigned int> m_extruder_ids;
// Highest of m_extruder_ids plus 1.
uint16_t m_num_extruders { 0 };
const std::string m_toolchange_prefix;
// 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;
Expand Down
5 changes: 3 additions & 2 deletions src/libslic3r/GCodeWriter.cpp
Expand Up @@ -793,7 +793,7 @@ std::string GCodeWriter::unlift()
return gcode;
}

std::string GCodeWriter::set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage)
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/*=""*/)
{
/*
std::ostringstream gcode;
Expand Down Expand Up @@ -858,7 +858,8 @@ std::string GCodeWriter::set_fan(const GCodeFlavor gcode_flavor, bool gcode_comm
}
gcode << (fan_baseline * (fan_speed / 100.0));
}
if (gcode_comments) gcode << " ; enable fan";
if (gcode_comments)
gcode << " ; " << (comment.empty() ? "enable fan" : comment);
gcode << "\n";
}
return gcode.str();
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCodeWriter.hpp
Expand Up @@ -83,7 +83,7 @@ class GCodeWriter {
Vec3d get_unlifted_position() const { return m_pos - Vec3d{0, 0, m_extra_lift + m_lifted}; }

// To be called by the CoolingBuffer from another thread.
static std::string set_fan(const GCodeFlavor gcode_flavor, bool gcode_comments, uint8_t speed, uint8_t tool_fan_offset, bool is_fan_percentage);
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 = "");
// 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).
// Keeping the state is left to the CoolingBuffer, which runs asynchronously on another thread.
std::string set_fan(uint8_t speed, uint16_t default_tool = 0);
Expand Down
4 changes: 2 additions & 2 deletions version.inc
Expand Up @@ -9,9 +9,9 @@ set(SLIC3R_APP_KEY "SuperSlicer")
set(SLIC3R_APP_CMD "superslicer")
# versions
set(SLIC3R_VERSION "2.5.59")
set(SLIC3R_VERSION_FULL "2.5.59.2")
set(SLIC3R_VERSION_FULL "2.5.59.3")
set(SLIC3R_BUILD_ID "${SLIC3R_APP_KEY}_${SLIC3R_VERSION_FULL}+UNKNOWN")
set(SLIC3R_RC_VERSION "2,5,59,2")
set(SLIC3R_RC_VERSION "2,5,59,3")
set(SLIC3R_RC_VERSION_DOTS "${SLIC3R_VERSION_FULL}")

# Same as the slicer name but for gcodeviewer
Expand Down

0 comments on commit 69c3980

Please sign in to comment.