Ported the cooling changes from @alexrj: Don't slow down the external

perimeters if not necessary, don't take the bridging time into account
when slowing down the print.

Removed Extruder & GCodeWriter Perl bindings.
Improved Extruder for constness.
Refactored GCode::m_elapsed_time to struct ElapsedTime.
This commit is contained in:
bubnikv 2017-06-22 12:59:23 +02:00
parent c1146e298b
commit 0454cc95f9
17 changed files with 156 additions and 220 deletions

View file

@ -6,6 +6,17 @@
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;
@ -21,7 +32,7 @@ std::string CoolingBuffer::append(const std::string &gcode, size_t object_id, si
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();
*m_elapsed_time += m_gcodegen.get_reset_elapsed_time();
return out;
}
@ -46,37 +57,49 @@ void apply_speed_factor(std::string &line, float speed_factor, float min_print_s
{
std::ostringstream oss;
oss << speed;
line.replace(pos+1, (last_pos-pos), oss.str());
line.replace(pos+1, last_pos-pos, oss.str());
}
}
std::string CoolingBuffer::flush()
{
const FullPrintConfig &config = m_gcodegen.config();
std::string gcode = m_gcode;
float elapsed = m_elapsed_time;
std::string gcode = std::move(m_gcode);
m_gcode.clear();
m_elapsed_time = 0.;
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;
if (config.cooling.values.front()) {
#ifdef SLIC3R_DEBUG
printf("Layer %zu estimated printing time: %f seconds\n", m_layer_id, elapsed);
#endif
if (elapsed < (float)config.slowdown_below_layer_time.values.front()) {
printf("Layer %zu estimated printing time: %f seconds\n", m_layer_id, m_elapsed_time->total);
#endif
if (m_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();
speed_factor = elapsed / (float)config.slowdown_below_layer_time.values.front();
} else if (elapsed < (float)config.fan_below_layer_time.values.front()) {
// We are not altering speed of bridges.
float time_to_stretch = m_elapsed_time->total - m_elapsed_time->bridges;
float target_time = (float)config.slowdown_below_layer_time.values.front() - m_elapsed_time->bridges;
// 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;
slowdown_external = false;
}
speed_factor = time_to_stretch / target_time;
} else if (m_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())
* (elapsed - (float)config.slowdown_below_layer_time.values.front())
* (m_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());
}
@ -97,11 +120,12 @@ std::string CoolingBuffer::flush()
if (boost::starts_with(line, "G1")
&& boost::contains(line, ";_EXTRUDE_SET_SPEED")
&& !boost::contains(line, ";_WIPE")
&& !bridge_fan_start) {
&& !bridge_fan_start
&& (slowdown_external || !boost::contains(line, ";_EXTERNAL_PERIMETER"))) {
apply_speed_factor(line, speed_factor, min_print_speed);
boost::replace_first(line, ";_EXTRUDE_SET_SPEED", "");
}
bridge_fan_start = boost::contains(line, ";_BRIDGE_FAN_START");
bridge_fan_start = boost::starts_with(line, ";_BRIDGE_FAN_START");
new_gcode += line + '\n';
}
gcode = new_gcode;
@ -122,8 +146,10 @@ std::string CoolingBuffer::flush()
}
boost::replace_all(gcode, ";_WIPE", "");
boost::replace_all(gcode, ";_EXTRUDE_SET_SPEED", "");
boost::replace_all(gcode, ";_EXTERNAL_PERIMETER", "");
m_object_ids_visited.clear();
m_elapsed_time->reset();
return gcode;
}