Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per_move_pressure_advance extruder flag #132

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 13 additions & 3 deletions klippy/chelper/kin_extruder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions klippy/kinematics/extruder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading