mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-17 03:37:54 -06:00
Fix of https://github.com/alexrj/Slic3r/issues/4043 , thanks to @lordofhyphens.
Further refactoring of the cooling logic to collect per extruder data.
This commit is contained in:
parent
39b9341359
commit
32fa84c5a5
9 changed files with 123 additions and 132 deletions
|
@ -6,36 +6,6 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
CoolingBuffer::CoolingBuffer(GCode &gcodegen) :
|
||||
m_gcodegen(gcodegen), m_layer_id(0),
|
||||
m_elapsed_time(new ElapsedTime)
|
||||
{
|
||||
}
|
||||
|
||||
CoolingBuffer::~CoolingBuffer()
|
||||
{
|
||||
delete m_elapsed_time;
|
||||
}
|
||||
|
||||
std::string CoolingBuffer::append(const std::string &gcode, size_t object_id, size_t layer_id, bool is_support)
|
||||
{
|
||||
std::string out;
|
||||
size_t signature = object_id * 2 + (is_support ? 1 : 0);
|
||||
if (m_object_ids_visited.find(signature) != m_object_ids_visited.end())
|
||||
// For a single print_z, a combination of (object_id, is_support) could repeat once only.
|
||||
// If the combination of (object_id, is_support) reappears, this must be for another print_z,
|
||||
// therefore a layer has to be finalized.
|
||||
out = this->flush();
|
||||
|
||||
m_object_ids_visited.insert(signature);
|
||||
m_layer_id = layer_id;
|
||||
m_gcode += gcode;
|
||||
// This is a very rough estimate of the print time,
|
||||
// not taking into account the acceleration curves generated by the printer firmware.
|
||||
*m_elapsed_time += m_gcodegen.get_reset_elapsed_time();
|
||||
return out;
|
||||
}
|
||||
|
||||
void apply_speed_factor(std::string &line, float speed_factor, float min_print_speed)
|
||||
{
|
||||
// find pos of F
|
||||
|
@ -61,45 +31,47 @@ void apply_speed_factor(std::string &line, float speed_factor, float min_print_s
|
|||
}
|
||||
}
|
||||
|
||||
std::string CoolingBuffer::flush()
|
||||
std::string CoolingBuffer::process_layer(const std::string &gcode_src, size_t layer_id)
|
||||
{
|
||||
const FullPrintConfig &config = m_gcodegen.config();
|
||||
|
||||
std::string gcode = std::move(m_gcode);
|
||||
m_gcode.clear();
|
||||
std::string gcode = gcode_src;
|
||||
int fan_speed = config.fan_always_on.values.front() ? config.min_fan_speed.values.front() : 0;
|
||||
float speed_factor = 1.0;
|
||||
bool slowdown_external = true;
|
||||
|
||||
int fan_speed = config.fan_always_on.values.front() ? config.min_fan_speed.values.front() : 0;
|
||||
|
||||
float speed_factor = 1.0;
|
||||
bool slowdown_external = true;
|
||||
const std::vector<ElapsedTime> &elapsed_times = m_gcodegen.writer().elapsed_times();
|
||||
ElapsedTime elapsed_time;
|
||||
for (const ElapsedTime &et : elapsed_times)
|
||||
elapsed_time += et;
|
||||
|
||||
if (config.cooling.values.front()) {
|
||||
#ifdef SLIC3R_DEBUG
|
||||
printf("Layer %zu estimated printing time: %f seconds\n", m_layer_id, m_elapsed_time->total);
|
||||
printf("Layer %zu estimated printing time: %f seconds\n", layer_id, elapsed_time.total);
|
||||
#endif
|
||||
if (m_elapsed_time->total < (float)config.slowdown_below_layer_time.values.front()) {
|
||||
if (elapsed_time.total < (float)config.slowdown_below_layer_time.values.front()) {
|
||||
// Layer time very short. Enable the fan to a full throttle and slow down the print
|
||||
// (stretch the layer print time to slowdown_below_layer_time).
|
||||
fan_speed = config.max_fan_speed.values.front();
|
||||
|
||||
// We are not altering speed of bridges.
|
||||
float time_to_stretch = m_elapsed_time->stretchable();
|
||||
float target_time = (float)config.slowdown_below_layer_time.values.front() - m_elapsed_time->non_stretchable();
|
||||
float time_to_stretch = elapsed_time.stretchable();
|
||||
float target_time = (float)config.slowdown_below_layer_time.values.front() - elapsed_time.non_stretchable();
|
||||
|
||||
// If we spend most of our time on external perimeters include them in the slowdown,
|
||||
// otherwise only alter other extrusions.
|
||||
if (m_elapsed_time->external_perimeters < 0.5f * time_to_stretch) {
|
||||
time_to_stretch -= m_elapsed_time->external_perimeters;
|
||||
target_time -= m_elapsed_time->external_perimeters;
|
||||
if (elapsed_time.external_perimeters < 0.5f * time_to_stretch) {
|
||||
time_to_stretch -= elapsed_time.external_perimeters;
|
||||
target_time -= elapsed_time.external_perimeters;
|
||||
slowdown_external = false;
|
||||
}
|
||||
|
||||
speed_factor = time_to_stretch / target_time;
|
||||
} else if (m_elapsed_time->total < (float)config.fan_below_layer_time.values.front()) {
|
||||
} else if (elapsed_time.total < (float)config.fan_below_layer_time.values.front()) {
|
||||
// Layer time quite short. Enable the fan proportionally according to the current layer time.
|
||||
fan_speed = config.max_fan_speed.values.front()
|
||||
- (config.max_fan_speed.values.front() - config.min_fan_speed.values.front())
|
||||
* (m_elapsed_time->total - (float)config.slowdown_below_layer_time.values.front())
|
||||
* (elapsed_time.total - (float)config.slowdown_below_layer_time.values.front())
|
||||
/ (config.fan_below_layer_time.values.front() - config.slowdown_below_layer_time.values.front());
|
||||
}
|
||||
|
||||
|
@ -131,13 +103,13 @@ std::string CoolingBuffer::flush()
|
|||
gcode = new_gcode;
|
||||
}
|
||||
}
|
||||
if (m_layer_id < config.disable_fan_first_layers.values.front())
|
||||
if (layer_id < config.disable_fan_first_layers.values.front())
|
||||
fan_speed = 0;
|
||||
|
||||
gcode = m_gcodegen.writer().set_fan(fan_speed) + gcode;
|
||||
|
||||
// bridge fan speed
|
||||
if (!config.cooling.values.front() || config.bridge_fan_speed.values.front() == 0 || m_layer_id < config.disable_fan_first_layers.values.front()) {
|
||||
if (!config.cooling.values.front() || config.bridge_fan_speed.values.front() == 0 || layer_id < config.disable_fan_first_layers.values.front()) {
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_START", "");
|
||||
boost::replace_all(gcode, ";_BRIDGE_FAN_END", "");
|
||||
} else {
|
||||
|
@ -149,7 +121,7 @@ std::string CoolingBuffer::flush()
|
|||
boost::replace_all(gcode, ";_EXTERNAL_PERIMETER", "");
|
||||
|
||||
m_object_ids_visited.clear();
|
||||
m_elapsed_time->reset();
|
||||
m_gcodegen.writer().reset_elapsed_times();
|
||||
return gcode;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue