extruder: Don't store pressure_advance value in trapq moves

Store the pressure_advance value in "struct extruder_stepper" instead
of in the trapq's "struct move".  This makes it possible for multiple
stepper motors to have different pressure advance values while still
using the same trapq.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-01-11 13:21:07 -05:00
parent 34a1ce4837
commit 29724a7411
3 changed files with 26 additions and 19 deletions

View File

@ -133,8 +133,8 @@ defs_kin_winch = """
defs_kin_extruder = """
struct stepper_kinematics *extruder_stepper_alloc(void);
void extruder_set_smooth_time(struct stepper_kinematics *sk
, double smooth_time);
void extruder_set_pressure_advance(struct stepper_kinematics *sk
, double pressure_advance, double smooth_time);
"""
defs_kin_shaper = """

View File

@ -52,15 +52,17 @@ extruder_integrate_time(double base, double start_v, double half_accel
// Calculate the definitive integral of extruder for a given move
static double
pa_move_integrate(struct move *m, double base, double start, double end,
double time_offset)
pa_move_integrate(struct move *m, double pressure_advance
, double base, double start, double end, double time_offset)
{
if (start < 0.)
start = 0.;
if (end > m->move_t)
end = m->move_t;
// Calculate base position and velocity with pressure advance
double pressure_advance = m->axes_r.y;
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
@ -72,34 +74,36 @@ pa_move_integrate(struct move *m, double base, double start, double end,
// Calculate the definitive integral of the extruder over a range of moves
static double
pa_range_integrate(struct move *m, double move_time, double hst)
pa_range_integrate(struct move *m, double move_time
, double pressure_advance, double hst)
{
// Calculate integral for the current move
double res = 0., start = move_time - hst, end = move_time + hst;
double start_base = m->start_pos.x;
res += pa_move_integrate(m, 0., start, move_time, start);
res -= pa_move_integrate(m, 0., move_time, end, end);
res += pa_move_integrate(m, pressure_advance, 0., start, move_time, start);
res -= pa_move_integrate(m, pressure_advance, 0., move_time, end, end);
// Integrate over previous moves
struct move *prev = m;
while (unlikely(start < 0.)) {
prev = list_prev_entry(prev, node);
start += prev->move_t;
double base = prev->start_pos.x - start_base;
res += pa_move_integrate(prev, base, start, prev->move_t, start);
res += pa_move_integrate(prev, pressure_advance, base, start
, prev->move_t, start);
}
// Integrate over future moves
while (unlikely(end > m->move_t)) {
end -= m->move_t;
m = list_next_entry(m, node);
double base = m->start_pos.x - start_base;
res -= pa_move_integrate(m, base, 0., end, end);
res -= pa_move_integrate(m, pressure_advance, base, 0., end, end);
}
return res;
}
struct extruder_stepper {
struct stepper_kinematics sk;
double half_smooth_time, inv_half_smooth_time2;
double pressure_advance, half_smooth_time, inv_half_smooth_time2;
};
static double
@ -112,12 +116,13 @@ extruder_calc_position(struct stepper_kinematics *sk, struct move *m
// Pressure advance not enabled
return m->start_pos.x + move_get_distance(m, move_time);
// Apply pressure advance and average over smooth_time
double area = pa_range_integrate(m, move_time, hst);
double area = pa_range_integrate(m, move_time, es->pressure_advance, hst);
return m->start_pos.x + area * es->inv_half_smooth_time2;
}
void __visible
extruder_set_smooth_time(struct stepper_kinematics *sk, double smooth_time)
extruder_set_pressure_advance(struct stepper_kinematics *sk
, double pressure_advance, double smooth_time)
{
struct extruder_stepper *es = container_of(sk, struct extruder_stepper, sk);
double hst = smooth_time * .5;
@ -126,6 +131,7 @@ extruder_set_smooth_time(struct stepper_kinematics *sk, double smooth_time)
if (! hst)
return;
es->inv_half_smooth_time2 = 1. / (hst * hst);
es->pressure_advance = pressure_advance;
}
struct stepper_kinematics * __visible

View File

@ -54,7 +54,6 @@ class PrinterExtruder:
self.stepper.set_stepper_kinematics(self.sk_extruder)
self.stepper.set_trapq(self.trapq)
toolhead.register_step_generator(self.stepper.generate_steps)
self.extruder_set_smooth_time = ffi_lib.extruder_set_smooth_time
self._set_pressure_advance(pressure_advance, smooth_time)
# Register commands
gcode = self.printer.lookup_object('gcode')
@ -86,7 +85,9 @@ class PrinterExtruder:
toolhead = self.printer.lookup_object("toolhead")
toolhead.note_step_generation_scan_time(new_smooth_time * .5,
old_delay=old_smooth_time * .5)
self.extruder_set_smooth_time(self.sk_extruder, new_smooth_time)
ffi_main, ffi_lib = chelper.get_ffi()
espa = ffi_lib.extruder_set_pressure_advance
espa(self.sk_extruder, pressure_advance, new_smooth_time)
self.pressure_advance = pressure_advance
self.pressure_advance_smooth_time = smooth_time
def get_status(self, eventtime):
@ -145,14 +146,14 @@ class PrinterExtruder:
accel = move.accel * axis_r
start_v = move.start_v * axis_r
cruise_v = move.cruise_v * axis_r
pressure_advance = 0.
can_pressure_advance = False
if axis_r > 0. and (move.axes_d[0] or move.axes_d[1]):
pressure_advance = self.pressure_advance
# Queue movement (x is extruder movement, y is pressure advance)
can_pressure_advance = True
# Queue movement (x is extruder movement, y is pressure advance flag)
self.trapq_append(self.trapq, print_time,
move.accel_t, move.cruise_t, move.decel_t,
move.start_pos[3], 0., 0.,
1., pressure_advance, 0.,
1., can_pressure_advance, 0.,
start_v, cruise_v, accel)
def find_past_position(self, print_time):
mcu_pos = self.stepper.get_past_mcu_position(print_time)