cartesian: Convert cartesian kinematics to use the iterative solver

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-06-09 14:56:05 -04:00
parent fc4a9e7564
commit 7148ebd565
1 changed files with 18 additions and 30 deletions

View File

@ -4,7 +4,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import logging import logging
import stepper, homing import stepper, homing, chelper
StepList = (0, 1, 2) StepList = (0, 1, 2)
@ -21,6 +21,12 @@ class CartKinematics:
'max_z_accel', max_accel, above=0., maxval=max_accel) 'max_z_accel', max_accel, above=0., maxval=max_accel)
self.need_motor_enable = True self.need_motor_enable = True
self.limits = [(1.0, -1.0)] * 3 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 # Setup stepper max halt velocity
max_halt_velocity = toolhead.get_max_axis_halt() max_halt_velocity = toolhead.get_max_axis_halt()
self.steppers[0].set_max_jerk(max_halt_velocity, max_accel) self.steppers[0].set_max_jerk(max_halt_velocity, max_accel)
@ -32,9 +38,10 @@ class CartKinematics:
self.dual_carriage_steppers = [] self.dual_carriage_steppers = []
if config.has_section('dual_carriage'): if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage') dc_config = config.getsection('dual_carriage')
self.dual_carriage_axis = dc_config.getchoice( dc_axis = dc_config.getchoice('axis', {'x': 'x', 'y': 'y'})
'axis', {'x': 0, 'y': 1}) self.dual_carriage_axis = {'x': 0, 'y': 1}[dc_axis]
dc_stepper = stepper.LookupMultiHomingStepper(printer, dc_config) dc_stepper = stepper.LookupMultiHomingStepper(printer, dc_config)
dc_stepper.setup_cartesian_itersolve(dc_axis)
dc_stepper.set_max_jerk(max_halt_velocity, max_accel) dc_stepper.set_max_jerk(max_halt_velocity, max_accel)
self.dual_carriage_steppers = [ self.dual_carriage_steppers = [
self.steppers[self.dual_carriage_axis], dc_stepper] self.steppers[self.dual_carriage_axis], dc_stepper]
@ -139,34 +146,15 @@ class CartKinematics:
def move(self, print_time, move): def move(self, print_time, move):
if self.need_motor_enable: if self.need_motor_enable:
self._check_motor_enable(print_time, move) 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: for i in StepList:
axis_d = move.axes_d[i] if move.axes_d[i]:
if not axis_d: self.steppers[i].step_itersolve(self.cmove)
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)
# Dual carriage support # Dual carriage support
def _activate_carriage(self, carriage): def _activate_carriage(self, carriage):
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')