Skip to content

Commit a80d152

Browse files
Feature: Retract amount after wipe
A new setting added - `Retract amount after wipe`. It controls the length of fast retraction after wipe, relative to retraction length. The value will be clamped by 100% minus the retract amount before the wipe value.
1 parent 3cb6da6 commit a80d152

File tree

10 files changed

+183
-35
lines changed

10 files changed

+183
-35
lines changed

src/libslic3r/Extruder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,13 @@ double Extruder::filament_flow_ratio() const
159159
// Return a "retract_before_wipe" percentage as a factor clamped to <0, 1>
160160
double Extruder::retract_before_wipe() const
161161
{
162-
return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(m_id) * 0.01));
162+
return std::clamp(m_config->retract_before_wipe.get_at(m_id) * 0.01, 0., 1.);
163+
}
164+
165+
// Return a "retract_after_wipe" percentage as a factor clamped to <0, 1>
166+
double Extruder::retract_after_wipe() const
167+
{
168+
return std::min(std::clamp(m_config->retract_after_wipe.get_at(m_id) * 0.01, 0., 1.), 1. - retract_before_wipe());
163169
}
164170

165171
double Extruder::retraction_length() const

src/libslic3r/Extruder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Extruder
6262
double filament_cost() const;
6363
double filament_flow_ratio() const;
6464
double retract_before_wipe() const;
65+
double retract_after_wipe() const;
6566
double retraction_length() const;
6667
double retract_lift() const;
6768
int retract_speed() const;

src/libslic3r/GCode.cpp

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -307,49 +307,64 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
307307

308308
// Declare & initialize retraction lengths
309309
double retraction_length_remaining = 0,
310-
retractionBeforeWipe = 0,
311-
retractionDuringWipe = 0;
310+
retraction_length_before_wipe = 0,
311+
retraction_length_during_wipe = 0,
312+
retraction_length_after_wipe = 0;
312313

313-
// initialise the remaining retraction amount with the full retraction amount.
314-
retraction_length_remaining = toolchange ? extruder->retract_length_toolchange() : extruder->retraction_length();
314+
// Initialise the remaining retraction amount with the full retraction amount.
315+
retraction_length_remaining = toolchange ?
316+
extruder->retract_length_toolchange() : extruder->retraction_length();
315317

316-
// nothing to retract - return early
317-
if(retraction_length_remaining <=EPSILON) return {0.f,0.f};
318+
// Nothing to retract - return early
319+
if (retraction_length_remaining <= EPSILON)
320+
return { 0.f, 0.f, 0.f };
318321

319-
// calculate retraction before wipe distance from the user setting. Keep adding to this variable any excess retraction needed
320-
// to be performed before the wipe.
321-
retractionBeforeWipe = retraction_length_remaining * extruder->retract_before_wipe();
322-
retraction_length_remaining -= retractionBeforeWipe; // subtract it from the remaining retraction length
323-
324-
// all of the retraction is to be done before the wipe
325-
if(retraction_length_remaining <=EPSILON) return {retractionBeforeWipe,0.f};
322+
// Calculate retraction before and after wipe distances from the user setting.
323+
// Keep adding to the for retraction before wipe variable any excess retraction
324+
// needed to be performed before the wipe.
325+
retraction_length_before_wipe = retraction_length_remaining * extruder->retract_before_wipe();
326+
retraction_length_after_wipe = retraction_length_remaining * extruder->retract_after_wipe();
327+
328+
// Subtract it from the remaining retraction length
329+
retraction_length_remaining -= retraction_length_before_wipe + retraction_length_after_wipe;
330+
331+
// All of the retraction is to be done before the wipe
332+
if (retraction_length_remaining <= EPSILON)
333+
return { retraction_length_before_wipe, 0., retraction_length_after_wipe };
326334

327335
// Calculate wipe speed
328-
double wipe_speed = config.role_based_wipe_speed ? writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed");
336+
double wipe_speed = config.role_based_wipe_speed ?
337+
writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed");
329338
wipe_speed = std::max(wipe_speed, 10.0);
330339

331340
// Process wipe path & calculate wipe path length
332341
double wipe_dist = scale_(config.wipe_distance.get_at(extruder_id));
333-
Polyline wipe_path = {last_pos};
342+
Polyline wipe_path = { last_pos };
334343
wipe_path.append(this->path.points.begin() + 1, this->path.points.end());
335344
double wipe_path_length = std::min(wipe_path.length(), wipe_dist);
336345

337346
// Calculate the maximum retraction amount during wipe
338-
retractionDuringWipe = config.retraction_speed.get_at(extruder_id) * unscale_(wipe_path_length) / wipe_speed;
339-
// If the maximum retraction amount during wipe is too small, return 0 and retract everything prior to the wipe.
340-
if(retractionDuringWipe <= EPSILON) return {retractionBeforeWipe,0.f};
347+
retraction_length_during_wipe = config.retraction_speed.get_at(extruder_id) *
348+
unscale_(wipe_path_length) / wipe_speed;
349+
350+
// If the maximum retraction amount during wipe is too small,
351+
// return 0 and retract everything prior to the wipe.
352+
if (retraction_length_during_wipe <= EPSILON)
353+
return { retraction_length_before_wipe, 0., retraction_length_after_wipe };
341354

342355
// If the maximum retraction amount during wipe is greater than any remaining retraction length
343356
// return the remaining retraction length to be retracted during the wipe
344-
if (retractionDuringWipe - retraction_length_remaining > EPSILON) return {retractionBeforeWipe,retraction_length_remaining};
357+
if (retraction_length_during_wipe - retraction_length_remaining > EPSILON)
358+
return { retraction_length_before_wipe, retraction_length_remaining, retraction_length_after_wipe };
345359

346360
// We will always proceed with incrementing the retraction amount before wiping with the difference
347361
// and return the maximum allowed wipe amount to be retracted during the wipe move
348-
retractionBeforeWipe += retraction_length_remaining - retractionDuringWipe;
349-
return {retractionBeforeWipe, retractionDuringWipe};
362+
retraction_length_before_wipe += retraction_length_remaining - retraction_length_during_wipe;
363+
364+
return { retraction_length_before_wipe, retraction_length_during_wipe, retraction_length_after_wipe };
350365
}
351366

352-
std::string Wipe::wipe(GCode& gcodegen,double length, bool toolchange, bool is_last)
367+
std::string Wipe::wipe(GCode& gcodegen, double length, bool toolchange, bool is_last)
353368
{
354369
std::string gcode;
355370

@@ -6369,8 +6384,9 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
63696384
// wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
63706385
if (EXTRUDER_CONFIG(wipe) && m_wipe.has_path() && scale_(EXTRUDER_CONFIG(wipe_distance)) > SCALED_EPSILON) {
63716386
Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths(*this, toolchange);
6372-
gcode += toolchange ? m_writer.retract_for_toolchange(true,wipeRetractions.retractLengthBeforeWipe) : m_writer.retract(true, wipeRetractions.retractLengthBeforeWipe);
6373-
gcode += m_wipe.wipe(*this,wipeRetractions.retractLengthDuringWipe, toolchange, is_last_retraction);
6387+
gcode += toolchange ? m_writer.retract_for_toolchange(true, wipeRetractions.retraction_length_before_wipe) :
6388+
m_writer.retract(true, wipeRetractions.retraction_length_before_wipe);
6389+
gcode += m_wipe.wipe(*this, wipeRetractions.retraction_length_during_wipe, toolchange, is_last_retraction);
63746390
}
63756391

63766392
/* The parent class will decide whether we need to perform an actual retraction

src/libslic3r/GCode.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ class Wipe {
5858
public:
5959
bool enable;
6060
Polyline path;
61+
6162
struct RetractionValues{
62-
double retractLengthBeforeWipe;
63-
double retractLengthDuringWipe;
63+
double retraction_length_before_wipe = 0.;
64+
double retraction_length_during_wipe = 0.;
65+
double retraction_length_after_wipe = 0.;
6466
};
6567

6668
Wipe() : enable(false) {}

src/libslic3r/Preset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ static std::vector<std::string> s_Preset_filament_options {
867867
"activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed",
868868
// Retract overrides
869869
"filament_retraction_length", "filament_z_hop", "filament_z_hop_types", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", "filament_retraction_minimum_travel",
870-
"filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe",
870+
"filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe", "filament_retract_after_wipe",
871871
// Profile compatibility
872872
"filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits",
873873
//BBS

src/libslic3r/Print.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
157157
"filename_format",
158158
"retraction_minimum_travel",
159159
"retract_before_wipe",
160+
"retract_after_wipe",
160161
"retract_when_changing_layer",
161162
"retraction_length",
162163
"retract_length_toolchange",

src/libslic3r/PrintConfig.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,6 +4273,14 @@ void PrintConfigDef::init_fff_params()
42734273
def->mode = comAdvanced;
42744274
def->set_default_value(new ConfigOptionPercents { 100 });
42754275

4276+
def = this->add("retract_after_wipe", coPercents);
4277+
def->label = L("Retract amount after wipe");
4278+
def->tooltip = L("The length of fast retraction after wipe, relative to retraction length. "
4279+
"The value will be clamped by 100% minus the retract amount before the wipe value.");
4280+
def->sidetext = "%";
4281+
def->mode = comAdvanced;
4282+
def->set_default_value(new ConfigOptionPercents { 0 });
4283+
42764284
def = this->add("retract_when_changing_layer", coBools);
42774285
def->label = L("Retract when change layer");
42784286
def->tooltip = L("Force a retraction when changes layer.");
@@ -6097,6 +6105,7 @@ void PrintConfigDef::init_fff_params()
60976105
"retract_when_changing_layer", "wipe",
60986106
// percents
60996107
"retract_before_wipe",
6108+
"retract_after_wipe",
61006109
"long_retractions_when_cut",
61016110
"retraction_distances_when_cut"
61026111
}) {
@@ -6145,14 +6154,15 @@ void PrintConfigDef::init_extruder_option_keys()
61456154
m_extruder_option_keys = {
61466155
"nozzle_diameter", "min_layer_height", "max_layer_height", "extruder_offset",
61476156
"retraction_length", "z_hop", "z_hop_types", "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
6148-
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
6157+
"retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
61496158
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour",
61506159
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
61516160
};
61526161

61536162
m_extruder_retract_keys = {
61546163
"deretraction_speed",
61556164
"long_retractions_when_cut",
6165+
"retract_after_wipe",
61566166
"retract_before_wipe",
61576167
"retract_lift_above",
61586168
"retract_lift_below",
@@ -6177,7 +6187,7 @@ void PrintConfigDef::init_filament_option_keys()
61776187
m_filament_option_keys = {
61786188
"filament_diameter", "min_layer_height", "max_layer_height",
61796189
"retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
6180-
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
6190+
"retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
61816191
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
61826192
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"/*,"filament_seam_gap"*/
61836193
};
@@ -6186,6 +6196,7 @@ void PrintConfigDef::init_filament_option_keys()
61866196
"deretraction_speed",
61876197
"long_retractions_when_cut",
61886198
"retract_before_wipe",
6199+
"retract_after_wipe",
61896200
"retract_lift_above",
61906201
"retract_lift_below",
61916202
"retract_lift_enforce",

src/libslic3r/PrintConfig.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,9 @@ PRINT_CONFIG_CLASS_DEFINE(
11981198

11991199

12001200
((ConfigOptionPercents, retract_before_wipe))
1201+
// Orca
1202+
((ConfigOptionPercents, retract_after_wipe))
1203+
12011204
((ConfigOptionFloats, retraction_length))
12021205
((ConfigOptionFloats, retract_length_toolchange))
12031206
((ConfigOptionInt, enable_long_retraction_when_cut))

0 commit comments

Comments
 (0)