Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Slic3r/Extruder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ sub retract_speed_mm_min {
return $self->retract_speed * 60;
}

sub unretract_speed_mm_min {
my $self = shift;
return $self->unretract_speed * 60;
}

sub scaled_wipe_distance {
my ($self, $travel_speed) = @_;

Expand Down
43 changes: 42 additions & 1 deletion lib/Slic3r/GCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ has 'last_speed' => (is => 'rw', default => sub {""});
has 'last_f' => (is => 'rw', default => sub {""});
has 'last_fan_speed' => (is => 'rw', default => sub {0});
has 'wipe_path' => (is => 'rw');
has 'adv_last_speed' => (is => 'rw', default => sub {0} );
has 'adv_last_amnt' => (is => 'rw', default => sub {0} );

sub BUILD {
my ($self) = @_;
Expand Down Expand Up @@ -344,6 +346,45 @@ sub extrude_path {
$F = $self->print_config->get_abs_value_over('first_layer_speed', $F/60) * 60;
}

# Advance algorithm to compensate pressure during speed change
if ($self->extruder->pressure_multiplier > 0) {
my $v1 = $self->adv_last_speed/60;
my $v2 = $F/60;

# Verify change
if (($v1 != $v2)) {

# Advance algorithm
my $adv_amnt = $e * $v2**2 * ($self->extruder->pressure_multiplier/100);

# Edit unretract to account for advance
my $eaxis = $self->_extrusion_axis;
if ($gcode !~ s/G1 ${eaxis}(\d+\.?\d*) F(\d+\.?\d*)( ?)(.*)\n/
my $str = sprintf("G1 %s%.5f F$2$3$4",
$eaxis,
($self->print_config->use_relative_e_distances ? $1 : 0) +
$self->extruder->extrude($adv_amnt - $self->adv_last_amnt));
$str .= " + pressure advance" if $self->print_config->gcode_comments;
$str .= "\n";
sprintf("%s", $str);
/ge) {

# There were no unretraction before
$gcode .= sprintf "G1 %s%.5f F%.3f",
$eaxis,
$self->extruder->extrude($adv_amnt - $self->adv_last_amnt),
($self->extruder->unretract_speed > 0 && ($adv_amnt - $self->adv_last_amnt) > 0 ) ?
$self->extruder->unretract_speed_mm_min :
$self->extruder->retract_speed_mm_min;
$gcode .= " ; pressure advance"
if $self->print_config->gcode_comments;
$gcode .= "\n";
}
$self->adv_last_amnt($adv_amnt);
}
$self->adv_last_speed($F);
}

# extrude arc or line
$gcode .= ";_BRIDGE_FAN_START\n" if $path->is_bridge;
my $path_length = unscale $path->length;
Expand Down Expand Up @@ -549,7 +590,7 @@ sub unretract {
$gcode .= sprintf "G1 %s%.5f F%.3f",
$self->_extrusion_axis,
$self->extruder->extrude($to_unretract),
$self->extruder->retract_speed_mm_min;
$self->extruder->unretract_speed > 0 ? $self->extruder->unretract_speed_mm_min : $self->extruder->retract_speed_mm_min;
$gcode .= " ; compensate retraction" if $self->print_config->gcode_comments;
$gcode .= "\n";
}
Expand Down
9 changes: 8 additions & 1 deletion lib/Slic3r/GUI/Tab.pm
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ sub build {
$self->_build_extruder_pages;
}

sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_speed retract_restart_extra retract_before_travel wipe
sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_speed pressure_multiplier unretract_speed retract_restart_extra retract_before_travel wipe
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange) }

sub _build_extruder_pages {
Expand Down Expand Up @@ -772,6 +772,13 @@ sub _build_extruder_pages {
qw(retract_length_toolchange retract_restart_extra_toolchange)
],
},
{
title => 'Advanced Retraction and Pressure Control',
options => [
map "${_}#${extruder_idx}",
qw(pressure_multiplier unretract_speed)
],
},
]);
$self->{extruder_pages}[$extruder_idx]{disabled} = 0;
}
Expand Down
12 changes: 12 additions & 0 deletions xs/src/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ Extruder::retract_speed() const
return this->config->retract_speed.get_at(this->id);
}

int
Extruder::unretract_speed() const
{
return this->config->unretract_speed.get_at(this->id);
}

double
Extruder::pressure_multiplier() const
{
return this->config->pressure_multiplier.get_at(this->id);
}

double
Extruder::retract_restart_extra() const
{
Expand Down
2 changes: 2 additions & 0 deletions xs/src/Extruder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Extruder
double retract_length() const;
double retract_lift() const;
int retract_speed() const;
int unretract_speed() const;
double pressure_multiplier() const;
double retract_restart_extra() const;
double retract_before_travel() const;
bool retract_layer_change() const;
Expand Down
22 changes: 22 additions & 0 deletions xs/src/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,20 @@ class PrintConfigDef
Options["retract_speed"].cli = "retract-speed=f@";
Options["retract_speed"].max = 1000;

Options["unretract_speed"].type = coInts;
Options["unretract_speed"].label = "Unretract Speed";
Options["unretract_speed"].tooltip = "The speed for unretractions (retract compensation). Set zero to disable and use the same as retract speed.";
Options["unretract_speed"].sidetext = "mm/s";
Options["unretract_speed"].cli = "unretract-speed=f@";
Options["unretract_speed"].max = 1000;

Options["pressure_multiplier"].type = coFloats;
Options["pressure_multiplier"].label = "Pressure advance constant";
Options["pressure_multiplier"].tooltip = "Pressure management multiplier. If greater than zero, it will inject or retract additional filament to control the pressure in the bowden tube. 1 means 100%. It adjusts only the amount of input raw filament that will be pushed or pulled, proportional.";
Options["pressure_multiplier"].sidetext = "(zero to disable)";
Options["pressure_multiplier"].cli = "pressure-multiplier=f@";
Options["pressure_multiplier"].max = 200;

Options["skirt_distance"].type = coFloat;
Options["skirt_distance"].label = "Distance from object";
Options["skirt_distance"].tooltip = "Distance between skirt and object(s). Set this to zero to attach the skirt to the object(s) and get a brim for better adhesion.";
Expand Down Expand Up @@ -1179,6 +1193,8 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionFloats retract_restart_extra;
ConfigOptionFloats retract_restart_extra_toolchange;
ConfigOptionInts retract_speed;
ConfigOptionInts unretract_speed;
ConfigOptionFloats pressure_multiplier;
ConfigOptionFloat skirt_distance;
ConfigOptionInt skirt_height;
ConfigOptionInt skirts;
Expand Down Expand Up @@ -1279,6 +1295,10 @@ class PrintConfig : public virtual StaticPrintConfig
this->retract_restart_extra_toolchange.values[0] = 0;
this->retract_speed.values.resize(1);
this->retract_speed.values[0] = 30;
this->unretract_speed.values.resize(1);
this->unretract_speed.values[0] = 0;
this->pressure_multiplier.values.resize(1);
this->pressure_multiplier.values[0] = 0;
this->skirt_distance.value = 6;
this->skirt_height.value = 1;
this->skirts.value = 1;
Expand Down Expand Up @@ -1370,6 +1390,8 @@ class PrintConfig : public virtual StaticPrintConfig
if (opt_key == "retract_restart_extra") return &this->retract_restart_extra;
if (opt_key == "retract_restart_extra_toolchange") return &this->retract_restart_extra_toolchange;
if (opt_key == "retract_speed") return &this->retract_speed;
if (opt_key == "unretract_speed") return &this->unretract_speed;
if (opt_key == "pressure_multiplier") return &this->pressure_multiplier;
if (opt_key == "skirt_distance") return &this->skirt_distance;
if (opt_key == "skirt_height") return &this->skirt_height;
if (opt_key == "skirts") return &this->skirts;
Expand Down
2 changes: 2 additions & 0 deletions xs/xsp/Extruder.xsp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
double retract_length() const;
double retract_lift() const;
int retract_speed() const;
int unretract_speed() const;
double pressure_multiplier() const;
double retract_restart_extra() const;
double retract_before_travel() const;
bool retract_layer_change() const;
Expand Down