From f13f7a4c98f7ed1cc565a6c9d21c57848c36313c Mon Sep 17 00:00:00 2001 From: Bea Nance Date: Fri, 26 Jan 2024 16:39:21 -0500 Subject: [PATCH 1/4] store_pa_in_trapq danger flag --- klippy/chelper/kin_extruder.c | 16 +++++++++++++--- klippy/extras/danger_options.py | 1 + klippy/kinematics/extruder.py | 12 ++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) 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/extras/danger_options.py b/klippy/extras/danger_options.py index 7c838f8d2..cfc392933 100644 --- a/klippy/extras/danger_options.py +++ b/klippy/extras/danger_options.py @@ -23,6 +23,7 @@ def __init__(self, config): "homing_elapsed_distance_tolerance", 0.5, minval=0.0 ) self.adc_ignore_limits = config.getboolean("adc_ignore_limits", False) + self.store_pa_in_trapq = config.getboolean("store_pa_in_trapq", False) def load_config(config): diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 5c8428c0d..fa48a0b6d 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -216,6 +216,7 @@ def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd): class PrinterExtruder: def __init__(self, config, extruder_num): self.printer = config.get_printer() + self.danger_options = self.printer.lookup_object("danger_options") self.name = config.get_name() self.last_position = 0.0 # Setup hotend heater @@ -357,9 +358,12 @@ 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.danger_options.store_pa_in_trapq else 0.0 + ) # Queue movement (x is extruder movement, y is pressure advance flag) self.trapq_append( self.trapq, @@ -371,8 +375,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, From 41d889c8fc7ed8487adcbbf28e23d8e677f4876e Mon Sep 17 00:00:00 2001 From: Bea Nance Date: Mon, 29 Jan 2024 15:46:04 -0500 Subject: [PATCH 2/4] rename and move to [extruder] --- klippy/extras/danger_options.py | 1 - klippy/kinematics/extruder.py | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/klippy/extras/danger_options.py b/klippy/extras/danger_options.py index cfc392933..7c838f8d2 100644 --- a/klippy/extras/danger_options.py +++ b/klippy/extras/danger_options.py @@ -23,7 +23,6 @@ def __init__(self, config): "homing_elapsed_distance_tolerance", 0.5, minval=0.0 ) self.adc_ignore_limits = config.getboolean("adc_ignore_limits", False) - self.store_pa_in_trapq = config.getboolean("store_pa_in_trapq", False) def load_config(config): diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index fa48a0b6d..e0fd768f5 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -216,7 +216,6 @@ def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd): class PrinterExtruder: def __init__(self, config, extruder_num): self.printer = config.get_printer() - self.danger_options = self.printer.lookup_object("danger_options") self.name = config.get_name() self.last_position = 0.0 # Setup hotend heater @@ -264,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 ( @@ -361,9 +365,7 @@ def move(self, print_time, move): pressure_advance = 0.0 if axis_r > 0.0 and (move.axes_d[0] or move.axes_d[1]): pressure_advance = self.extruder_stepper.pressure_advance - use_pa_from_trapq = ( - 1.0 if self.danger_options.store_pa_in_trapq else 0.0 - ) + 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, From 399036522ad381fd5e976c94aa9b85ed786df129 Mon Sep 17 00:00:00 2001 From: Bea Nance Date: Mon, 29 Jan 2024 15:54:25 -0500 Subject: [PATCH 3/4] add docs and readme --- README.md | 1 + docs/Config_Reference.md | 5 +++++ 2 files changed, 6 insertions(+) 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] From 6f7576a667e2d1b976ce1cc3ff596c159645d4f0 Mon Sep 17 00:00:00 2001 From: Bea Nance Date: Mon, 29 Jan 2024 17:03:43 -0500 Subject: [PATCH 4/4] add test --- test/klippy/extruders.cfg | 1 + 1 file changed, 1 insertion(+) 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