diff --git a/README.md b/README.md index 52e2b45c8..78f0d1cf1 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ If I want my printer to light itself on fire, I should be able to make my printe - [adxl345: improve ACCELEROMETER_QUERY command](https://github.com/DangerKlippers/danger-klipper/pull/124) +- [extruder: add flag to use the PA constant from a trapq move vs a cached value](https://github.com/DangerKlippers/danger-klipper/pull/132) If you're feeling adventurous, take a peek at the extra features in the bleeding-edge branch: - [dmbutyugin's advanced-features branch](https://github.com/DangerKlippers/danger-klipper/pull/69) [dmbutyugin/advanced-features](https://github.com/dmbutyugin/klipper/commits/advanced-features) diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md index 87038e690..7c5e3d459 100644 --- a/docs/Config_Reference.md +++ b/docs/Config_Reference.md @@ -987,6 +987,11 @@ max_temp: # heater and sensor hardware failures. Set this range just wide # enough so that reasonable temperatures do not result in an error. # These parameters must be provided. +per_move_pressure_advance: False +# If true, uses pressure advance constant from trapq when processing moves +# This causes changes to pressure advance be taken into account immediately, +# for all moves in the current queue, rather than ~250ms later once the queue gets flushed + ``` ### [heater_bed] diff --git a/klippy/chelper/kin_extruder.c b/klippy/chelper/kin_extruder.c index b8d1cc221..6f11060a9 100644 --- a/klippy/chelper/kin_extruder.c +++ b/klippy/chelper/kin_extruder.c @@ -59,10 +59,20 @@ pa_move_integrate(struct move *m, double pressure_advance start = 0.; if (end > m->move_t) end = m->move_t; + // figure out what to use for pressure advance + // use_pa_from_trapq is passed in via the move's axes_r.z field + // if this is True (not 0), we use the pressure advance value in the axes_r.y + // otherwise, we use the one passed in as an arg to this function (the stored one) + int use_pa_from_trapq = m->axes_r.z != 0.; + if (use_pa_from_trapq) { + pressure_advance = m->axes_r.y; + } + else { + int can_pressure_advance = m->axes_r.y != 0.; + if (!can_pressure_advance) + pressure_advance = 0.; + } // Calculate base position and velocity with pressure advance - int can_pressure_advance = m->axes_r.y != 0.; - if (!can_pressure_advance) - pressure_advance = 0.; base += pressure_advance * m->start_v; double start_v = m->start_v + pressure_advance * 2. * m->half_accel; // Calculate definitive integral diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 5c8428c0d..e0fd768f5 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -263,6 +263,11 @@ def __init__(self, config, extruder_num): self.trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free) self.trapq_append = ffi_lib.trapq_append self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves + + self.per_move_pressure_advance = config.getboolean( + "per_move_pressure_advance", False + ) + # Setup extruder stepper self.extruder_stepper = None if ( @@ -357,9 +362,10 @@ def move(self, print_time, move): accel = move.accel * axis_r start_v = move.start_v * axis_r cruise_v = move.cruise_v * axis_r - can_pressure_advance = False + pressure_advance = 0.0 if axis_r > 0.0 and (move.axes_d[0] or move.axes_d[1]): - can_pressure_advance = True + pressure_advance = self.extruder_stepper.pressure_advance + use_pa_from_trapq = 1.0 if self.per_move_pressure_advance else 0.0 # Queue movement (x is extruder movement, y is pressure advance flag) self.trapq_append( self.trapq, @@ -371,8 +377,8 @@ def move(self, print_time, move): 0.0, 0.0, 1.0, - can_pressure_advance, - 0.0, + pressure_advance, + use_pa_from_trapq, start_v, cruise_v, accel, diff --git a/test/klippy/extruders.cfg b/test/klippy/extruders.cfg index d7123d08e..47d61e579 100644 --- a/test/klippy/extruders.cfg +++ b/test/klippy/extruders.cfg @@ -48,6 +48,7 @@ pid_Ki: 1.08 pid_Kd: 114 min_temp: 0 max_temp: 210 +per_move_pressure_advance: True [extruder_stepper my_extra_stepper] extruder: extruder