aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/chelper/kin_extruder.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-11-05 15:42:19 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-11-06 15:51:51 -0500
commit076a66f791414b0eaf9a9a9c8907b20be327385a (patch)
tree24285d2628f5840eb4023af34da1d8580d4fb50d /klippy/chelper/kin_extruder.c
parent7ca86f17232e5e0653de512b6322c301b153919c (diff)
downloadkutter-076a66f791414b0eaf9a9a9c8907b20be327385a.tar.gz
kutter-076a66f791414b0eaf9a9a9c8907b20be327385a.tar.xz
kutter-076a66f791414b0eaf9a9a9c8907b20be327385a.zip
trapq: Use separate 'move' entries for accel, cruise, and decel phases
Only track a single acceleration movement in a 'struct move' instance. Break the classic trapezoid movement (accel, cruise, decel) into three separate movements. This simplifies the calculation logic. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/chelper/kin_extruder.c')
-rw-r--r--klippy/chelper/kin_extruder.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/klippy/chelper/kin_extruder.c b/klippy/chelper/kin_extruder.c
index 37c00c8b..e5e440f4 100644
--- a/klippy/chelper/kin_extruder.c
+++ b/klippy/chelper/kin_extruder.c
@@ -32,30 +32,49 @@ extruder_stepper_alloc(void)
void __visible
extruder_add_move(struct trapq *tq, double print_time
, double accel_t, double cruise_t, double decel_t
- , double start_pos
+ , double start_e_pos
, double start_v, double cruise_v, double accel
, double extra_accel_v, double extra_decel_v)
{
- struct move *m = move_alloc();
+ struct coord start_pos, axes_r;
+ start_pos.x = start_e_pos;
+ axes_r.x = 1.;
+ start_pos.y = start_pos.z = axes_r.y = axes_r.z = 0.;
- // Setup velocity trapezoid
- m->print_time = print_time;
- m->move_t = accel_t + cruise_t + decel_t;
- m->accel_t = accel_t;
- m->cruise_t = cruise_t;
- m->cruise_start_d = accel_t * (.5 * (cruise_v + start_v) + extra_accel_v);
- m->decel_start_d = m->cruise_start_d + cruise_t * cruise_v;
+ if (accel_t) {
+ struct move *m = move_alloc();
+ m->print_time = print_time;
+ m->move_t = accel_t;
+ m->start_v = start_v + extra_accel_v;
+ m->half_accel = .5 * accel;
+ m->start_pos = start_pos;
+ m->axes_r = axes_r;
+ trapq_add_move(tq, m);
- // Setup for accel/cruise/decel phases
- m->cruise_v = cruise_v;
- m->accel.c1 = start_v + extra_accel_v;
- m->accel.c2 = .5 * accel;
- m->decel.c1 = cruise_v + extra_decel_v;
- m->decel.c2 = -m->accel.c2;
+ print_time += accel_t;
+ start_pos.x += move_get_distance(m, accel_t);
+ }
+ if (cruise_t) {
+ struct move *m = move_alloc();
+ m->print_time = print_time;
+ m->move_t = cruise_t;
+ m->start_v = cruise_v;
+ m->half_accel = 0.;
+ m->start_pos = start_pos;
+ m->axes_r = axes_r;
+ trapq_add_move(tq, m);
- // Setup start distance
- m->start_pos.x = start_pos;
- m->axes_r.x = 1.;
-
- trapq_add_move(tq, m);
+ print_time += cruise_t;
+ start_pos.x += move_get_distance(m, cruise_t);
+ }
+ if (decel_t) {
+ struct move *m = move_alloc();
+ m->print_time = print_time;
+ m->move_t = decel_t;
+ m->start_v = cruise_v + extra_decel_v;
+ m->half_accel = -.5 * accel;
+ m->start_pos = start_pos;
+ m->axes_r = axes_r;
+ trapq_add_move(tq, m);
+ }
}