mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-15 18:58:03 -06:00
stepper: Replace PrinterHomingStepper with PrinterRail
Update the code to use the term "rail" when dealing with a motor controlled "axis". A rail has a series of steppers and endstops that control that motor controlled "axis". Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
93d0526a77
commit
0791c69499
7 changed files with 200 additions and 194 deletions
|
@ -1,6 +1,6 @@
|
|||
# Code for handling the kinematics of linear delta robots
|
||||
#
|
||||
# Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging
|
||||
|
@ -15,16 +15,16 @@ class DeltaKinematics:
|
|||
def __init__(self, toolhead, config):
|
||||
stepper_configs = [config.getsection('stepper_' + n)
|
||||
for n in ['a', 'b', 'c']]
|
||||
stepper_a = stepper.PrinterHomingStepper(
|
||||
rail_a = stepper.PrinterRail(
|
||||
stepper_configs[0], need_position_minmax = False)
|
||||
a_endstop = stepper_a.get_homing_info().position_endstop
|
||||
stepper_b = stepper.PrinterHomingStepper(
|
||||
a_endstop = rail_a.get_homing_info().position_endstop
|
||||
rail_b = stepper.PrinterRail(
|
||||
stepper_configs[1], need_position_minmax = False,
|
||||
default_position_endstop=a_endstop)
|
||||
stepper_c = stepper.PrinterHomingStepper(
|
||||
rail_c = stepper.PrinterRail(
|
||||
stepper_configs[2], need_position_minmax = False,
|
||||
default_position_endstop=a_endstop)
|
||||
self.steppers = [stepper_a, stepper_b, stepper_c]
|
||||
self.rails = [rail_a, rail_b, rail_c]
|
||||
self.need_motor_enable = self.need_home = True
|
||||
self.radius = radius = config.getfloat('delta_radius', above=0.)
|
||||
arm_length_a = stepper_configs[0].getfloat('arm_length', above=radius)
|
||||
|
@ -32,12 +32,12 @@ class DeltaKinematics:
|
|||
sconfig.getfloat('arm_length', arm_length_a, above=radius)
|
||||
for sconfig in stepper_configs]
|
||||
self.arm2 = [arm**2 for arm in arm_lengths]
|
||||
self.endstops = [(s.get_homing_info().position_endstop
|
||||
self.endstops = [(rail.get_homing_info().position_endstop
|
||||
+ math.sqrt(arm2 - radius**2))
|
||||
for s, arm2 in zip(self.steppers, self.arm2)]
|
||||
for rail, arm2 in zip(self.rails, self.arm2)]
|
||||
self.limit_xy2 = -1.
|
||||
self.max_z = min([s.get_homing_info().position_endstop
|
||||
for s in self.steppers])
|
||||
self.max_z = min([rail.get_homing_info().position_endstop
|
||||
for rail in self.rails])
|
||||
self.min_z = config.getfloat('minimum_z_position', 0, maxval=self.max_z)
|
||||
self.limit_z = min([ep - arm
|
||||
for ep, arm in zip(self.endstops, arm_lengths)])
|
||||
|
@ -50,8 +50,8 @@ class DeltaKinematics:
|
|||
'max_z_velocity', self.max_velocity,
|
||||
above=0., maxval=self.max_velocity)
|
||||
max_halt_velocity = toolhead.get_max_axis_halt()
|
||||
for s in self.steppers:
|
||||
s.set_max_jerk(max_halt_velocity, self.max_accel)
|
||||
for rail in self.rails:
|
||||
rail.set_max_jerk(max_halt_velocity, self.max_accel)
|
||||
# Determine tower locations in cartesian space
|
||||
self.angles = [sconfig.getfloat('angle', angle)
|
||||
for sconfig, angle in zip(stepper_configs,
|
||||
|
@ -63,13 +63,14 @@ class DeltaKinematics:
|
|||
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 s, a, t in zip(self.steppers, self.arm2, self.towers):
|
||||
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)
|
||||
s.setup_itersolve(sk)
|
||||
r.setup_itersolve(sk)
|
||||
# Find the point where an XY move could result in excessive
|
||||
# tower movement
|
||||
half_min_step_dist = min([s.get_step_dist() for s in self.steppers]) * .5
|
||||
half_min_step_dist = min([r.get_steppers()[0].get_step_dist()
|
||||
for r in self.rails]) * .5
|
||||
min_arm_length = min(arm_lengths)
|
||||
def ratio_to_dist(ratio):
|
||||
return (ratio * math.sqrt(min_arm_length**2 / (ratio**2 + 1.)
|
||||
|
@ -84,8 +85,8 @@ class DeltaKinematics:
|
|||
% (math.sqrt(self.max_xy2), math.sqrt(self.slow_xy2),
|
||||
math.sqrt(self.very_slow_xy2)))
|
||||
self.set_position([0., 0., 0.], ())
|
||||
def get_steppers(self, flags=""):
|
||||
return list(self.steppers)
|
||||
def get_rails(self, flags=""):
|
||||
return list(self.rails)
|
||||
def _cartesian_to_actuator(self, coord):
|
||||
return [math.sqrt(self.arm2[i] - (self.towers[i][0] - coord[0])**2
|
||||
- (self.towers[i][1] - coord[1])**2) + coord[2]
|
||||
|
@ -93,21 +94,21 @@ class DeltaKinematics:
|
|||
def _actuator_to_cartesian(self, pos):
|
||||
return actuator_to_cartesian(self.towers, self.arm2, pos)
|
||||
def get_position(self):
|
||||
spos = [s.get_commanded_position() for s in self.steppers]
|
||||
spos = [rail.get_commanded_position() for rail in self.rails]
|
||||
return self._actuator_to_cartesian(spos)
|
||||
def set_position(self, newpos, homing_axes):
|
||||
pos = self._cartesian_to_actuator(newpos)
|
||||
for i in StepList:
|
||||
self.steppers[i].set_position(pos[i])
|
||||
self.rails[i].set_position(pos[i])
|
||||
self.limit_xy2 = -1.
|
||||
if tuple(homing_axes) == StepList:
|
||||
self.need_home = False
|
||||
def home(self, homing_state):
|
||||
# All axes are homed simultaneously
|
||||
homing_state.set_axes([0, 1, 2])
|
||||
endstops = [es for s in self.steppers for es in s.get_endstops()]
|
||||
endstops = [es for rail in self.rails for es in rail.get_endstops()]
|
||||
# Initial homing - assume homing speed same for all steppers
|
||||
hi = self.steppers[0].get_homing_info()
|
||||
hi = self.rails[0].get_homing_info()
|
||||
homing_speed = min(hi.speed, self.max_z_velocity)
|
||||
homepos = [0., 0., self.max_z, None]
|
||||
coord = list(homepos)
|
||||
|
@ -121,17 +122,17 @@ class DeltaKinematics:
|
|||
homing_state.home(coord, homepos, endstops,
|
||||
homing_speed/2.0, second_home=True)
|
||||
# Set final homed position
|
||||
spos = [ep + s.get_homed_offset()
|
||||
for ep, s in zip(self.endstops, self.steppers)]
|
||||
spos = [ep + rail.get_homed_offset()
|
||||
for ep, rail in zip(self.endstops, self.rails)]
|
||||
homing_state.set_homed_position(self._actuator_to_cartesian(spos))
|
||||
def motor_off(self, print_time):
|
||||
self.limit_xy2 = -1.
|
||||
for stepper in self.steppers:
|
||||
stepper.motor_enable(print_time, 0)
|
||||
for rail in self.rails:
|
||||
rail.motor_enable(print_time, 0)
|
||||
self.need_motor_enable = self.need_home = True
|
||||
def _check_motor_enable(self, print_time):
|
||||
for i in StepList:
|
||||
self.steppers[i].motor_enable(print_time, 1)
|
||||
self.rails[i].motor_enable(print_time, 1)
|
||||
self.need_motor_enable = False
|
||||
def check_move(self, move):
|
||||
end_pos = move.end_pos
|
||||
|
@ -171,18 +172,19 @@ class DeltaKinematics:
|
|||
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 stepper in self.steppers:
|
||||
stepper.step_itersolve(self.cmove)
|
||||
for rail in self.rails:
|
||||
rail.step_itersolve(self.cmove)
|
||||
# Helper functions for DELTA_CALIBRATE script
|
||||
def get_stable_position(self):
|
||||
steppers = [rail.get_steppers()[0] for rail in self.rails]
|
||||
return [int((ep - s.get_commanded_position()) / s.get_step_dist() + .5)
|
||||
* s.get_step_dist()
|
||||
for ep, s in zip(self.endstops, self.steppers)]
|
||||
for ep, s in zip(self.endstops, steppers)]
|
||||
def get_calibrate_params(self):
|
||||
return {
|
||||
'endstop_a': self.steppers[0].position_endstop,
|
||||
'endstop_b': self.steppers[1].position_endstop,
|
||||
'endstop_c': self.steppers[2].position_endstop,
|
||||
'endstop_a': self.rails[0].position_endstop,
|
||||
'endstop_b': self.rails[1].position_endstop,
|
||||
'endstop_c': self.rails[2].position_endstop,
|
||||
'angle_a': self.angles[0], 'angle_b': self.angles[1],
|
||||
'angle_c': self.angles[2], 'radius': self.radius,
|
||||
'arm_a': self.arm_lengths[0], 'arm_b': self.arm_lengths[1],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue