Skip to content

Commit

Permalink
Implement vibration limit using G4 pauses
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Dec 5, 2012
1 parent bfc3616 commit cf32cd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Slic3r/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ our $Options = {
sidetext => 'Hz',
cli => 'vibration-limit=f',
type => 'f',
default => 0,
default => 15,
},

# print options
Expand Down
15 changes: 8 additions & 7 deletions lib/Slic3r/GCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ sub extrude_path {
}

# only apply vibration limiting to gap fill until the algorithm is more mature
$self->limit_frequency($path->role == EXTR_ROLE_GAPFILL) if 0;
$self->limit_frequency($path->role == EXTR_ROLE_GAPFILL);

# go to first point of extrusion path
$self->speed('travel');
Expand Down Expand Up @@ -344,7 +344,9 @@ sub _G0_G1 {
$gcode .= sprintf " X%.${dec}f Y%.${dec}f",
($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X],
($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #**
$speed_factor = $self->_limit_frequency($point) if $self->limit_frequency;
if ($self->limit_frequency) {
$gcode = $self->_limit_frequency($point) . $gcode;
}
$self->last_pos($point->clone);
}
if (defined $z && (!defined $self->z || $z != $self->z)) {
Expand Down Expand Up @@ -514,14 +516,13 @@ sub _limit_frequency {
my ($point) = @_;

return if $Slic3r::Config->vibration_limit == 0;
my $min_time = 1 / ($Slic3r::Config->vibration_limit * 60);
my $min_time = 1 / ($Slic3r::Config->vibration_limit * 60); # in minutes

# calculate the move vector and move direction
my @move = map unscale $_, @{ Slic3r::Line->new($self->last_pos, $point)->vector->[B] };
my @dir = map { $move[$_] ? (($move[$_] > 0) ? 1 : -1) : 0 } X,Y;

my $factor = 1;
my $segment_time = abs(max(@move)) / $self->speeds->{$self->speed};
my $segment_time = abs(max(@move)) / $self->speeds->{$self->speed}; # in minutes
if ($segment_time > 0) {
my @max_segment_time = ();
foreach my $axis (X,Y) {
Expand All @@ -536,11 +537,11 @@ sub _limit_frequency {

my $min_segment_time = min(@max_segment_time);
if ($min_segment_time < $min_time) {
$factor = $min_segment_time / $min_time;
return sprintf "G4 P%d\n", ($min_time - $min_segment_time) * 60 * 1000;
}
}

return $factor;
return '';
}

1;

0 comments on commit cf32cd6

Please sign in to comment.