mcu: Enhance itersolve stepper kinematics allocation

Allocate the stepper_kinematics directly in mcu.py - that way the
kinematic classes don't have to interact with the chelper code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-13 11:24:36 -04:00
parent b988596519
commit a31c31aed4
7 changed files with 31 additions and 36 deletions

View File

@ -45,14 +45,14 @@ class StepperBuzz:
stepper.motor_enable(print_time, 1)
print_time += .1
was_ignore = stepper.set_ignore_move(False)
prev_sk = stepper.setup_itersolve(self.stepper_kinematics)
prev_sk = stepper.set_stepper_kinematics(self.stepper_kinematics)
for i in range(10):
self.manual_move(print_time, stepper, 0., 1.)
print_time += .3
self.manual_move(print_time, stepper, 1., -1.)
toolhead.reset_print_time(print_time + .7)
print_time = toolhead.get_last_move_time()
stepper.setup_itersolve(prev_sk)
stepper.set_stepper_kinematics(prev_sk)
stepper.set_ignore_move(was_ignore)
if need_motor_enable:
print_time += .1

View File

@ -4,13 +4,17 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging
import stepper, homing, chelper
import stepper, homing
class CartKinematics:
def __init__(self, toolhead, config):
self.printer = config.get_printer()
# Setup axis rails
self.rails = [stepper.LookupMultiRail(config.getsection('stepper_' + n))
for n in ['x', 'y', 'z']]
for rail, axis in zip(self.rails, 'xyz'):
rail.setup_itersolve('cartesian_stepper_alloc', axis)
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
@ -18,10 +22,6 @@ 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()
for axis, rail in zip('xyz', self.rails):
rail.setup_cartesian_itersolve(axis)
# Setup stepper max halt velocity
max_halt_velocity = toolhead.get_max_axis_halt()
self.rails[0].set_max_jerk(max_halt_velocity, max_accel)
@ -36,7 +36,7 @@ class CartKinematics:
dc_axis = dc_config.getchoice('axis', {'x': 'x', 'y': 'y'})
self.dual_carriage_axis = {'x': 0, 'y': 1}[dc_axis]
dc_rail = stepper.LookupMultiRail(dc_config)
dc_rail.setup_cartesian_itersolve(dc_axis)
dc_rail.setup_itersolve('cartesian_stepper_alloc', dc_axis)
dc_rail.set_max_jerk(max_halt_velocity, max_accel)
self.dual_carriage_rails = [
self.rails[self.dual_carriage_axis], dc_rail]

View File

@ -4,15 +4,20 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, math
import stepper, homing, chelper
import stepper, homing
class CoreXYKinematics:
def __init__(self, toolhead, config):
# Setup axis rails
self.rails = [ stepper.PrinterRail(config.getsection('stepper_x')),
stepper.PrinterRail(config.getsection('stepper_y')),
stepper.LookupMultiRail(config.getsection('stepper_z')) ]
self.rails[0].add_to_endstop(self.rails[1].get_endstops()[0][0])
self.rails[1].add_to_endstop(self.rails[0].get_endstops()[0][0])
self.rails[0].setup_itersolve('corexy_stepper_alloc', '+')
self.rails[1].setup_itersolve('corexy_stepper_alloc', '-')
self.rails[2].setup_itersolve('cartesian_stepper_alloc', 'z')
# Setup boundary checks
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
@ -20,13 +25,6 @@ class CoreXYKinematics:
'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.rails[0].setup_itersolve(ffi_main.gc(
ffi_lib.corexy_stepper_alloc('+'), ffi_lib.free))
self.rails[1].setup_itersolve(ffi_main.gc(
ffi_lib.corexy_stepper_alloc('-'), ffi_lib.free))
self.rails[2].setup_cartesian_itersolve('z')
# Setup stepper max halt velocity
max_halt_velocity = toolhead.get_max_axis_halt()
max_xy_halt_velocity = max_halt_velocity * math.sqrt(2.)

View File

@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import stepper, homing, chelper, mathutil
import stepper, homing, mathutil
# Slow moves once the ratio of tower to XY movement exceeds SLOW_RATIO
SLOW_RATIO = 3.
@ -60,12 +60,8 @@ class DeltaKinematics:
self.towers = [(math.cos(math.radians(angle)) * radius,
math.sin(math.radians(angle)) * radius)
for angle in self.angles]
# Setup iterative solver
ffi_main, ffi_lib = chelper.get_ffi()
for r, a, t in zip(self.rails, self.arm2, self.towers):
sk = ffi_main.gc(ffi_lib.delta_stepper_alloc(a, t[0], t[1]),
ffi_lib.free)
r.setup_itersolve(sk)
r.setup_itersolve('delta_stepper_alloc', a, t[0], t[1])
# Find the point where an XY move could result in excessive
# tower movement
half_min_step_dist = min([r.get_steppers()[0].get_step_dist()

View File

@ -51,8 +51,7 @@ class PrinterExtruder:
ffi_main, ffi_lib = chelper.get_ffi()
self.cmove = ffi_main.gc(ffi_lib.move_alloc(), ffi_lib.free)
self.extruder_move_fill = ffi_lib.extruder_move_fill
sk = ffi_main.gc(ffi_lib.extruder_stepper_alloc(), ffi_lib.free)
self.stepper.setup_itersolve(sk)
self.stepper.setup_itersolve('extruder_stepper_alloc')
# Setup SET_PRESSURE_ADVANCE command
gcode = self.printer.lookup_object('gcode')
if self.name in ('extruder', 'extruder0'):

View File

@ -39,12 +39,10 @@ class MCU_stepper:
self._min_stop_interval = min_stop_interval
def setup_step_distance(self, step_dist):
self._step_dist = step_dist
def setup_itersolve(self, sk):
old_sk = self._stepper_kinematics
self._stepper_kinematics = sk
self._ffi_lib.itersolve_set_stepcompress(
sk, self._stepqueue, self._step_dist)
return old_sk
def setup_itersolve(self, alloc_func, *params):
ffi_main, ffi_lib = chelper.get_ffi()
sk = ffi_main.gc(getattr(ffi_lib, alloc_func)(*params), ffi_lib.free)
self.set_stepper_kinematics(sk)
def build_config(self):
max_error = self._mcu.get_max_stepper_error()
min_stop_interval = max(0., self._min_stop_interval - max_error)
@ -85,6 +83,12 @@ class MCU_stepper:
if mcu_pos >= 0.:
return int(mcu_pos + 0.5)
return int(mcu_pos - 0.5)
def set_stepper_kinematics(self, sk):
old_sk = self._stepper_kinematics
self._stepper_kinematics = sk
self._ffi_lib.itersolve_set_stepcompress(
sk, self._stepqueue, self._step_dist)
return old_sk
def set_ignore_move(self, ignore_move):
was_ignore = (self._itersolve_gen_steps
is not self._ffi_lib.itersolve_gen_steps)

View File

@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, collections
import homing, chelper
import homing
######################################################################
@ -62,6 +62,7 @@ class PrinterStepper:
# Wrappers
self.step_itersolve = self.mcu_stepper.step_itersolve
self.setup_itersolve = self.mcu_stepper.setup_itersolve
self.set_stepper_kinematics = self.mcu_stepper.set_stepper_kinematics
self.set_ignore_move = self.mcu_stepper.set_ignore_move
self.set_position = self.mcu_stepper.set_position
self.get_mcu_position = self.mcu_stepper.get_mcu_position
@ -108,7 +109,6 @@ class PrinterRail:
self.steppers = [stepper]
self.name = stepper.get_name(short=True)
self.step_itersolve = stepper.step_itersolve
self.setup_itersolve = stepper.setup_itersolve
self.get_commanded_position = stepper.get_commanded_position
self.is_motor_enabled = stepper.is_motor_enabled
# Primary endstop and its position
@ -235,11 +235,9 @@ class PrinterRail:
def step_multi_itersolve(self, cmove):
for stepper in self.steppers:
stepper.step_itersolve(cmove)
def setup_cartesian_itersolve(self, axis):
ffi_main, ffi_lib = chelper.get_ffi()
def setup_itersolve(self, alloc_func, *params):
for stepper in self.steppers:
stepper.setup_itersolve(ffi_main.gc(
ffi_lib.cartesian_stepper_alloc(axis), ffi_lib.free))
stepper.setup_itersolve(alloc_func, *params)
def set_max_jerk(self, max_halt_velocity, max_accel):
for stepper in self.steppers:
stepper.set_max_jerk(max_halt_velocity, max_accel)