From 6a53eaefc03a5643e73619672a2fb522e593a519 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 22 Feb 2017 10:09:25 -0500 Subject: [PATCH] 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 --- config/example.cfg | 7 +++++++ klippy/extruder.py | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/config/example.cfg b/config/example.cfg index 3574cd44..9f89d5e0 100644 --- a/config/example.cfg +++ b/config/example.cfg @@ -141,6 +141,13 @@ filament_diameter: 3.500 # during deceleration. It is measured in millimeters per # millimeter/second. The default is 0, which disables pressure # 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 heater_pin: ar4 diff --git a/klippy/extruder.py b/klippy/extruder.py index fc20ccf8..1c64fbf2 100644 --- a/klippy/extruder.py +++ b/klippy/extruder.py @@ -22,6 +22,10 @@ class PrinterExtruder: self.max_e_dist = config.getfloat('max_extrude_only_distance', 50.) self.max_e_velocity = self.max_e_accel = None 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.extrude_pos = 0. 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 return move.max_cruise_v2 def lookahead(self, moves, flush_count, lazy): - pressure_advance = self.pressure_advance - if not pressure_advance: + lookahead_t = self.pressure_advance_lookahead_time + if not lookahead_t: return flush_count # Calculate max_corner_v - the speed the head will accelerate # to after cornering. @@ -73,14 +77,19 @@ class PrinterExtruder: continue cruise_v = move.cruise_v max_corner_v = 0. - sum_t = pressure_advance + sum_t = lookahead_t for j in range(i+1, flush_count): fmove = moves[j] if not fmove.max_start_v2: break - max_corner_v = max(max_corner_v, fmove.cruise_v) - if max_corner_v >= cruise_v: - break + if fmove.cruise_v > max_corner_v: + if sum_t >= fmove.accel_t: + 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 if sum_t <= 0.: break