Skip to content

Commit

Permalink
Change retract_restart_extra_toolchange behavior to trigger at each f…
Browse files Browse the repository at this point in the history
…irst tool unretraction (but the very first)

#1052
  • Loading branch information
supermerill committed Oct 7, 2021
1 parent 666851a commit 54ad2a8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions resources/ui_layout/extruder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ group:Retraction wipe
setting:idx:wipe_extra_perimeter
setting:idx:seam_gap
group:Retraction when tool is disabled (advanced settings for multi-extruder setups)
setting:idx:retract_length_toolchange
setting:idx:retract_restart_extra_toolchange
setting:label$Minimum retraction:idx:retract_length_toolchange
setting:label$Extra unretraction:idx:retract_restart_extra_toolchange
group:Preview
reset_to_filament_color
13 changes: 10 additions & 3 deletions src/libslic3r/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Tool::Tool(uint16_t id, GCodeConfig* config) :
Extruder::Extruder(uint16_t id, GCodeConfig* config) :
Tool(id, config)
{
// set extra_toolchange to be init for when it will be new current extruder
m_restart_extra_toolchange = retract_restart_extra_toolchange();

// cache values that are going to be called often
m_e_per_mm3 = this->extrusion_multiplier();
Expand Down Expand Up @@ -46,7 +48,7 @@ double Tool::extrude(double dE)
The restart_extra argument sets the extra length to be used for
unretraction. If we're actually performing a retraction, any restart_extra
value supplied will overwrite the previous one if any. */
double Tool::retract(double length, double restart_extra)
double Tool::retract(double length, double restart_extra, double restart_extra_toolchange)
{
// in case of relative E distances we always reset to 0 before any output
if (m_config->use_relative_e_distances)
Expand All @@ -56,17 +58,22 @@ double Tool::retract(double length, double restart_extra)
m_E -= to_retract;
m_absolute_E -= to_retract;
m_retracted += to_retract;
m_restart_extra = restart_extra;
if(!std::isnan(restart_extra))
m_restart_extra = restart_extra;
}
if (!std::isnan(restart_extra_toolchange))
m_restart_extra_toolchange = restart_extra_toolchange;
return to_retract;
}

double Tool::unretract()
{
double dE = m_retracted + m_restart_extra;
double dE = m_retracted + m_restart_extra + m_restart_extra_toolchange;
this->extrude(dE);
m_retracted = 0.;
m_restart_extra = 0.;
if(m_restart_extra_toolchange != 0)
m_restart_extra_toolchange = 0.;
return dE;
}

Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/Extruder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class Tool
m_absolute_E = 0;
m_retracted = 0;
m_restart_extra = 0;
m_restart_extra_toolchange = 0; // note: can't call retract_restart_extra_toolchange(); because virtual inheritance doesn't work when only the tool is build (constructor)
}

uint16_t id() const { return m_id; }

virtual double extrude(double dE);
virtual double retract(double length, double restart_extra);
virtual double retract(double length, double restart_extra, double restart_extra_from_toolchange);
virtual double unretract();
double E() const { return m_E; }
void reset_E() { m_E = 0.; }
Expand Down Expand Up @@ -67,6 +68,7 @@ class Tool
double m_retracted;
// When retracted, this value stores the extra amount of priming on deretraction.
double m_restart_extra;
double m_restart_extra_toolchange;
double m_e_per_mm3;
};

Expand Down
3 changes: 3 additions & 0 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
m_writer.toolchange(initial_extruder_id);
}

// ensure the first tool doesn't "extra_retract"
m_writer.unretract();

//write temps after custom gcodes to ensure the temperature are good. (after tool selection)
if ((initial_extruder_id != (uint16_t)-1) && !this->config().start_gcode_manual && print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, true);
Expand Down
8 changes: 6 additions & 2 deletions src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,14 @@ std::string GCodeWriter::retract(bool before_wipe)
return this->_retract(
factor * config_region->print_retract_length,
factor * m_tool->retract_restart_extra(),
NAN,
"retract"
);
}
return this->_retract(
factor * m_tool->retract_length(),
factor * m_tool->retract_restart_extra(),
NAN,
"retract"
);
}
Expand All @@ -617,12 +619,13 @@ std::string GCodeWriter::retract_for_toolchange(bool before_wipe)
assert(factor >= 0. && factor <= 1. + EPSILON);
return this->_retract(
factor * m_tool->retract_length_toolchange(),
NAN,
factor * m_tool->retract_restart_extra_toolchange(),
"retract for toolchange"
);
}

std::string GCodeWriter::_retract(double length, double restart_extra, const std::string &comment)
std::string GCodeWriter::_retract(double length, double restart_extra, double restart_extra_toolchange, const std::string &comment)
{
std::ostringstream gcode;

Expand All @@ -637,9 +640,10 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
double area = d * d * PI/4;
length = length * area;
restart_extra = restart_extra * area;
restart_extra_toolchange = restart_extra_toolchange * area;
}

double dE = m_tool->retract(length, restart_extra);
double dE = m_tool->retract(length, restart_extra, restart_extra_toolchange);
assert(dE >= 0);
assert(dE < 10000000);
if (dE != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCodeWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GCodeWriter {
Vec3d m_pos = Vec3d::Zero();

std::string _travel_to_z(double z, const std::string &comment);
std::string _retract(double length, double restart_extra, const std::string &comment);
std::string _retract(double length, double restart_extra, double restart_extra_toolchange, const std::string &comment);

// if positive, it's set, and the next lift wil have this extra lift
double extra_lift = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,8 @@ void PrintConfigDef::init_fff_params()
def->full_label = L("Retraction Length (Toolchange)");
def->tooltip = L("When retraction is triggered before changing tool, filament is pulled back "
"by the specified amount (the length is measured on raw filament, before it enters "
"the extruder).");
"the extruder)."
"\nNote: This value will be unretracted when this extruder will load the next time.");
def->sidetext = L("mm (zero to disable)");
def->mode = comExpert;
def->min = 0;
Expand Down Expand Up @@ -3361,7 +3362,8 @@ void PrintConfigDef::init_fff_params()
def->label = L("Extra length on restart");
def->full_label = L("Extrat length on toolchange restart");
def->tooltip = L("When the retraction is compensated after changing tool, the extruder will push "
"this additional amount of filament.");
"this additional amount of filament"
" (but not on the first extruder after start, as it should already be loaded).");
def->sidetext = L("mm");
def->mode = comExpert;
def->is_vector_extruder = true;
Expand Down

0 comments on commit 54ad2a8

Please sign in to comment.