Skip to content

Commit 2cd7b6b

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 e922411 commit 2cd7b6b

File tree

10 files changed

+186
-34
lines changed

10 files changed

+186
-34
lines changed

src/libslic3r/Extruder.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ double Extruder::filament_flow_ratio() const
168168
// Return a "retract_before_wipe" percentage as a factor clamped to <0, 1>
169169
double Extruder::retract_before_wipe() const
170170
{
171-
return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(m_id) * 0.01));
171+
return std::clamp(m_config->retract_before_wipe.get_at(m_id) * 0.01, 0., 1.);
172+
}
173+
174+
// Return a "retract_after_wipe" percentage as a factor clamped to <0, 1>
175+
double Extruder::retract_after_wipe() const
176+
{
177+
return std::min(std::clamp(m_config->retract_after_wipe.get_at(m_id) * 0.01, 0., 1.), 1. - retract_before_wipe());
172178
}
173179

174180
double Extruder::retraction_length() const

src/libslic3r/Extruder.hpp

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

src/libslic3r/GCode.cpp

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -306,46 +306,61 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
306306

307307
// Declare & initialize retraction lengths
308308
double retraction_length_remaining = 0,
309-
retractionBeforeWipe = 0,
310-
retractionDuringWipe = 0;
309+
retraction_length_before_wipe = 0,
310+
retraction_length_during_wipe = 0,
311+
retraction_length_after_wipe = 0;
311312

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

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

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

326334
// Calculate wipe speed
327-
double wipe_speed = config.role_based_wipe_speed ? writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed");
335+
double wipe_speed = config.role_based_wipe_speed ?
336+
writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed");
328337
wipe_speed = std::max(wipe_speed, 10.0);
329338

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

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

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

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

351366
std::string transform_gcode(const std::string &gcode, Vec2f pos, const Vec2f &translation, float angle)
@@ -6999,8 +7014,9 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
69997014
// wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
70007015
if (FILAMENT_CONFIG(wipe) && m_wipe.has_path() && scale_(FILAMENT_CONFIG(wipe_distance)) > SCALED_EPSILON) {
70017016
Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths(*this, toolchange);
7002-
gcode += toolchange ? m_writer.retract_for_toolchange(true,wipeRetractions.retractLengthBeforeWipe) : m_writer.retract(true, wipeRetractions.retractLengthBeforeWipe);
7003-
gcode += m_wipe.wipe(*this,wipeRetractions.retractLengthDuringWipe, toolchange, is_last_retraction);
7017+
gcode += toolchange ? m_writer.retract_for_toolchange(true, wipeRetractions.retraction_length_before_wipe) :
7018+
m_writer.retract(true, wipeRetractions.retraction_length_before_wipe);
7019+
gcode += m_wipe.wipe(*this, wipeRetractions.retraction_length_during_wipe, toolchange, is_last_retraction);
70047020
}
70057021

70067022
/* 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
@@ -60,9 +60,11 @@ class Wipe {
6060
public:
6161
bool enable;
6262
Polyline path;
63+
6364
struct RetractionValues{
64-
double retractLengthBeforeWipe;
65-
double retractLengthDuringWipe;
65+
double retraction_length_before_wipe = 0.;
66+
double retraction_length_during_wipe = 0.;
67+
double retraction_length_after_wipe = 0.;
6668
};
6769

6870
Wipe() : enable(false) {}

src/libslic3r/Preset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static std::vector<std::string> s_Preset_filament_options {/*"filament_colour",
964964
"activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed",
965965
// Retract overrides
966966
"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",
967-
"filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe",
967+
"filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe", "filament_retract_after_wipe",
968968
// Profile compatibility
969969
"filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits",
970970
//BBS

src/libslic3r/Print.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
172172
"filename_format",
173173
"retraction_minimum_travel",
174174
"retract_before_wipe",
175+
"retract_after_wipe",
175176
"retract_when_changing_layer",
176177
"retraction_length",
177178
"retract_length_toolchange",

src/libslic3r/PrintConfig.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ const std::vector<std::string> filament_extruder_override_keys = {
7777
"filament_wipe",
7878
// percents
7979
"filament_retract_before_wipe",
80+
// Orca
81+
"filament_retract_after_wipe",
82+
// BBS
8083
"filament_long_retractions_when_cut",
8184
"filament_retraction_distances_when_cut"
8285
};
@@ -4564,6 +4567,14 @@ void PrintConfigDef::init_fff_params()
45644567
def->mode = comAdvanced;
45654568
def->set_default_value(new ConfigOptionPercents { 100 });
45664569

4570+
def = this->add("retract_after_wipe", coPercents);
4571+
def->label = L("Retract amount after wipe");
4572+
def->tooltip = L("The length of fast retraction after wipe, relative to retraction length. "
4573+
"The value will be clamped by 100% minus the retract amount before the wipe value.");
4574+
def->sidetext = "%";
4575+
def->mode = comAdvanced;
4576+
def->set_default_value(new ConfigOptionPercents { 0 });
4577+
45674578
def = this->add("retract_when_changing_layer", coBools);
45684579
def->label = L("Retract when change layer");
45694580
def->tooltip = L("Force a retraction when changes layer.");
@@ -6561,14 +6572,15 @@ void PrintConfigDef::init_extruder_option_keys()
65616572
m_extruder_option_keys = {
65626573
"extruder_type", "nozzle_diameter", "default_nozzle_volume_type", "min_layer_height", "max_layer_height", "extruder_offset",
65636574
"retraction_length", "z_hop", "z_hop_types", "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
6564-
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
6575+
"retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
65656576
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour",
65666577
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"
65676578
};
65686579

65696580
m_extruder_retract_keys = {
65706581
"deretraction_speed",
65716582
"long_retractions_when_cut",
6583+
"retract_after_wipe",
65726584
"retract_before_wipe",
65736585
"retract_lift_above",
65746586
"retract_lift_below",
@@ -6593,7 +6605,7 @@ void PrintConfigDef::init_filament_option_keys()
65936605
m_filament_option_keys = {
65946606
"filament_diameter", "min_layer_height", "max_layer_height","volumetric_speed_coefficients",
65956607
"retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed",
6596-
"retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
6608+
"retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance",
65976609
"retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour",
65986610
"default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"/*,"filament_seam_gap"*/
65996611
};
@@ -6602,6 +6614,7 @@ void PrintConfigDef::init_filament_option_keys()
66026614
"deretraction_speed",
66036615
"long_retractions_when_cut",
66046616
"retract_before_wipe",
6617+
"retract_after_wipe",
66056618
"retract_lift_above",
66066619
"retract_lift_below",
66076620
"retract_lift_enforce",
@@ -7580,6 +7593,9 @@ std::set<std::string> filament_options_with_variant = {
75807593
//BBS
75817594
"filament_wipe_distance",
75827595
"filament_retract_before_wipe",
7596+
// Orca
7597+
"filament_retract_after_wipe",
7598+
//BBS
75837599
"filament_long_retractions_when_cut",
75847600
"filament_retraction_distances_when_cut",
75857601
"long_retractions_when_ec",

src/libslic3r/PrintConfig.hpp

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

12851285

12861286
((ConfigOptionPercents, retract_before_wipe))
1287+
// Orca
1288+
((ConfigOptionPercents, retract_after_wipe))
1289+
12871290
((ConfigOptionFloats, retraction_length))
12881291
((ConfigOptionFloats, retract_length_toolchange))
12891292
((ConfigOptionInt, enable_long_retraction_when_cut))

0 commit comments

Comments
 (0)