diff --git a/klippy/cartesian.py b/klippy/cartesian.py index 155d9bf2..b4682b0b 100644 --- a/klippy/cartesian.py +++ b/klippy/cartesian.py @@ -4,7 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import logging -import stepper, homing +import stepper, homing, chelper StepList = (0, 1, 2) @@ -21,6 +21,12 @@ class CartKinematics: 'max_z_accel', max_accel, above=0., maxval=max_accel) self.need_motor_enable = True self.limits = [(1.0, -1.0)] * 3 + # Setup iterative solver + ffi_main, ffi_lib = chelper.get_ffi() + self.cmove = ffi_main.gc(ffi_lib.move_alloc(), ffi_lib.free) + self.move_fill = ffi_lib.move_fill + for a, s in zip('xyz', self.steppers): + s.setup_cartesian_itersolve(a) # Setup stepper max halt velocity max_halt_velocity = toolhead.get_max_axis_halt() self.steppers[0].set_max_jerk(max_halt_velocity, max_accel) @@ -32,9 +38,10 @@ class CartKinematics: self.dual_carriage_steppers = [] if config.has_section('dual_carriage'): dc_config = config.getsection('dual_carriage') - self.dual_carriage_axis = dc_config.getchoice( - 'axis', {'x': 0, 'y': 1}) + dc_axis = dc_config.getchoice('axis', {'x': 'x', 'y': 'y'}) + self.dual_carriage_axis = {'x': 0, 'y': 1}[dc_axis] dc_stepper = stepper.LookupMultiHomingStepper(printer, dc_config) + dc_stepper.setup_cartesian_itersolve(dc_axis) dc_stepper.set_max_jerk(max_halt_velocity, max_accel) self.dual_carriage_steppers = [ self.steppers[self.dual_carriage_axis], dc_stepper] @@ -139,34 +146,15 @@ class CartKinematics: def move(self, print_time, move): if self.need_motor_enable: self._check_motor_enable(print_time, move) + self.move_fill( + self.cmove, print_time, + move.accel_t, move.cruise_t, move.decel_t, + move.start_pos[0], move.start_pos[1], move.start_pos[2], + move.axes_d[0], move.axes_d[1], move.axes_d[2], + move.start_v, move.cruise_v, move.accel) for i in StepList: - axis_d = move.axes_d[i] - if not axis_d: - continue - step_const = self.steppers[i].step_const - move_time = print_time - start_pos = move.start_pos[i] - axis_r = abs(axis_d) / move.move_d - accel = move.accel * axis_r - cruise_v = move.cruise_v * axis_r - - # Acceleration steps - if move.accel_r: - accel_d = move.accel_r * axis_d - step_const(move_time, start_pos, accel_d, - move.start_v * axis_r, accel) - start_pos += accel_d - move_time += move.accel_t - # Cruising steps - if move.cruise_r: - cruise_d = move.cruise_r * axis_d - step_const(move_time, start_pos, cruise_d, cruise_v, 0.) - start_pos += cruise_d - move_time += move.cruise_t - # Deceleration steps - if move.decel_r: - decel_d = move.decel_r * axis_d - step_const(move_time, start_pos, decel_d, cruise_v, -accel) + if move.axes_d[i]: + self.steppers[i].step_itersolve(self.cmove) # Dual carriage support def _activate_carriage(self, carriage): toolhead = self.printer.lookup_object('toolhead')