extruder: Allow configuration of pressure advance lookahead time

Instead of defaulting the pressure advance lookahead time to be the
same as the pressure_advance variable, allow it to be configured.
Default the new config setting (pressure_advance_lookahead_time) to
10ms.

Also, make the setting more accurate if a future move is accelerating
in the middle of the lookahead window.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-02-22 10:09:25 -05:00
parent 4bc114336c
commit 6a53eaefc0
2 changed files with 22 additions and 6 deletions

View File

@ -141,6 +141,13 @@ filament_diameter: 3.500
# during deceleration. It is measured in millimeters per # during deceleration. It is measured in millimeters per
# millimeter/second. The default is 0, which disables pressure # millimeter/second. The default is 0, which disables pressure
# advance. # advance.
#pressure_advance_lookahead_time: 0.010
# A time (in seconds) to "look ahead" at future extrusion moves when
# calculating pressure advance. This is used to reduce the
# application of pressure advance during cornering moves that would
# otherwise cause retraction followed immediately by pressure
# buildup. This setting only applies if pressure_advance is
# non-zero. The default is 0.010 (10 milliseconds).
# #
# The remaining variables describe the extruder heater # The remaining variables describe the extruder heater
heater_pin: ar4 heater_pin: ar4

View File

@ -22,6 +22,10 @@ class PrinterExtruder:
self.max_e_dist = config.getfloat('max_extrude_only_distance', 50.) self.max_e_dist = config.getfloat('max_extrude_only_distance', 50.)
self.max_e_velocity = self.max_e_accel = None self.max_e_velocity = self.max_e_accel = None
self.pressure_advance = config.getfloat('pressure_advance', 0.) self.pressure_advance = config.getfloat('pressure_advance', 0.)
self.pressure_advance_lookahead_time = 0.
if self.pressure_advance:
self.pressure_advance_lookahead_time = config.getfloat(
'pressure_advance_lookahead_time', 0.010)
self.need_motor_enable = True self.need_motor_enable = True
self.extrude_pos = 0. self.extrude_pos = 0.
def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel): def set_max_jerk(self, max_xy_halt_velocity, max_velocity, max_accel):
@ -62,8 +66,8 @@ class PrinterExtruder:
move.extrude_r = prev_move.extrude_r move.extrude_r = prev_move.extrude_r
return move.max_cruise_v2 return move.max_cruise_v2
def lookahead(self, moves, flush_count, lazy): def lookahead(self, moves, flush_count, lazy):
pressure_advance = self.pressure_advance lookahead_t = self.pressure_advance_lookahead_time
if not pressure_advance: if not lookahead_t:
return flush_count return flush_count
# Calculate max_corner_v - the speed the head will accelerate # Calculate max_corner_v - the speed the head will accelerate
# to after cornering. # to after cornering.
@ -73,14 +77,19 @@ class PrinterExtruder:
continue continue
cruise_v = move.cruise_v cruise_v = move.cruise_v
max_corner_v = 0. max_corner_v = 0.
sum_t = pressure_advance sum_t = lookahead_t
for j in range(i+1, flush_count): for j in range(i+1, flush_count):
fmove = moves[j] fmove = moves[j]
if not fmove.max_start_v2: if not fmove.max_start_v2:
break break
max_corner_v = max(max_corner_v, fmove.cruise_v) if fmove.cruise_v > max_corner_v:
if max_corner_v >= cruise_v: if sum_t >= fmove.accel_t:
break max_corner_v = fmove.cruise_v
else:
max_corner_v = max(
max_corner_v, fmove.start_v + fmove.accel * sum_t)
if max_corner_v >= cruise_v:
break
sum_t -= fmove.accel_t + fmove.cruise_t + fmove.decel_t sum_t -= fmove.accel_t + fmove.cruise_t + fmove.decel_t
if sum_t <= 0.: if sum_t <= 0.:
break break