|
17 | 17 | try: from extras.AFC_lane import AFCLane |
18 | 18 | except: raise error(ERROR_STR.format(import_lib="AFC_lane", trace=traceback.format_exc())) |
19 | 19 |
|
| 20 | +LARGE_TIME_OFFSET = 99999.9 |
| 21 | + |
20 | 22 | class AFCExtruderStepper(AFCLane): |
21 | 23 | def __init__(self, config): |
22 | 24 | super().__init__(config) |
23 | 25 |
|
24 | 26 | self.extruder_stepper = extruder.ExtruderStepper(config) |
25 | 27 |
|
26 | | - self.motion_queue = None |
| 28 | + # Check for Klipper new motion queuing update |
| 29 | + try: |
| 30 | + self.motion_queuing = self.printer.load_object(config, "motion_queuing") |
| 31 | + except Exception: |
| 32 | + self.motion_queuing = None |
| 33 | + |
27 | 34 | self.next_cmd_time = 0. |
| 35 | + |
28 | 36 | ffi_main, ffi_lib = chelper.get_ffi() |
29 | | - self.trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free) |
30 | | - self.trapq_append = ffi_lib.trapq_append |
31 | | - self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves |
32 | 37 | self.stepper_kinematics = ffi_main.gc( |
33 | 38 | ffi_lib.cartesian_stepper_alloc(b'x'), ffi_lib.free) |
| 39 | + |
| 40 | + if self.motion_queuing is not None: |
| 41 | + self.trapq = self.motion_queuing.allocate_trapq() |
| 42 | + self.trapq_append = self.motion_queuing.lookup_trapq_append() |
| 43 | + else: |
| 44 | + self.trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free) |
| 45 | + self.trapq_append = ffi_lib.trapq_append |
| 46 | + self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves |
| 47 | + |
34 | 48 | self.assist_activate=False |
35 | 49 |
|
36 | 50 | # Current to use while printing, set to a lower current to reduce stepper heat when printing. |
@@ -69,24 +83,32 @@ def _move(self, distance, speed, accel, assist_active=False): |
69 | 83 |
|
70 | 84 |
|
71 | 85 | with self.assist_move(speed, distance < 0, assist_active): |
| 86 | + # Code based off force_move.py manual_move function |
72 | 87 | toolhead = self.printer.lookup_object('toolhead') |
73 | 88 | toolhead.flush_step_generation() |
74 | | - prev_sk = self.extruder_stepper.stepper.set_stepper_kinematics(self.stepper_kinematics) |
75 | | - prev_trapq = self.extruder_stepper.stepper.set_trapq(self.trapq) |
| 89 | + prev_sk = self.extruder_stepper.stepper.set_stepper_kinematics(self.stepper_kinematics) |
| 90 | + prev_trapq = self.extruder_stepper.stepper.set_trapq(self.trapq) |
76 | 91 | self.extruder_stepper.stepper.set_position((0., 0., 0.)) |
77 | 92 | axis_r, accel_t, cruise_t, cruise_v = calc_move_time(distance, speed, accel) |
78 | 93 | print_time = toolhead.get_last_move_time() |
79 | 94 | self.trapq_append(self.trapq, print_time, accel_t, cruise_t, accel_t, |
80 | 95 | 0., 0., 0., axis_r, 0., 0., 0., cruise_v, accel) |
81 | 96 | print_time = print_time + accel_t + cruise_t + accel_t |
82 | | - self.extruder_stepper.stepper.generate_steps(print_time) |
83 | | - self.trapq_finalize_moves(self.trapq, print_time + 99999.9, |
84 | | - print_time + 99999.9) |
85 | | - self.extruder_stepper.stepper.set_trapq(prev_trapq) |
86 | | - self.extruder_stepper.stepper.set_stepper_kinematics(prev_sk) |
87 | | - toolhead.note_mcu_movequeue_activity(print_time) |
| 97 | + |
| 98 | + if self.motion_queuing is None: |
| 99 | + self.extruder_stepper.stepper.generate_steps(print_time) |
| 100 | + self.trapq_finalize_moves(self.trapq, print_time + LARGE_TIME_OFFSET, |
| 101 | + print_time + LARGE_TIME_OFFSET) |
| 102 | + toolhead.note_mcu_movequeue_activity(print_time) |
| 103 | + else: |
| 104 | + self.motion_queuing.note_mcu_movequeue_activity(print_time) |
| 105 | + |
88 | 106 | toolhead.dwell(accel_t + cruise_t + accel_t) |
89 | 107 | toolhead.flush_step_generation() |
| 108 | + self.extruder_stepper.stepper.set_trapq(prev_trapq) |
| 109 | + self.extruder_stepper.stepper.set_stepper_kinematics(prev_sk) |
| 110 | + if self.motion_queuing is not None: |
| 111 | + self.motion_queuing.wipe_trapq(self.trapq) |
90 | 112 | toolhead.wait_moves() |
91 | 113 |
|
92 | 114 | def move(self, distance, speed, accel, assist_active=False): |
|
0 commit comments