2018-07-13 06:28:58 +03:00
|
|
|
# Code for handling the kinematics of cable winch robots
|
|
|
|
#
|
2021-01-08 19:52:28 +03:00
|
|
|
# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
|
2018-07-13 06:28:58 +03:00
|
|
|
#
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
2021-01-08 19:52:28 +03:00
|
|
|
import stepper, mathutil
|
2018-07-13 06:28:58 +03:00
|
|
|
|
|
|
|
class WinchKinematics:
|
|
|
|
def __init__(self, toolhead, config):
|
|
|
|
# Setup steppers at each anchor
|
|
|
|
self.steppers = []
|
|
|
|
self.anchors = []
|
|
|
|
for i in range(26):
|
|
|
|
name = 'stepper_' + chr(ord('a') + i)
|
|
|
|
if i >= 3 and not config.has_section(name):
|
|
|
|
break
|
|
|
|
stepper_config = config.getsection(name)
|
|
|
|
s = stepper.PrinterStepper(stepper_config)
|
|
|
|
self.steppers.append(s)
|
|
|
|
a = tuple([stepper_config.getfloat('anchor_' + n) for n in 'xyz'])
|
|
|
|
self.anchors.append(a)
|
|
|
|
s.setup_itersolve('winch_stepper_alloc', *a)
|
2019-10-29 06:35:22 +03:00
|
|
|
s.set_trapq(toolhead.get_trapq())
|
2019-11-07 18:59:35 +03:00
|
|
|
toolhead.register_step_generator(s.generate_steps)
|
2018-07-13 06:28:58 +03:00
|
|
|
# Setup boundary checks
|
2021-01-18 06:54:16 +03:00
|
|
|
acoords = list(zip(*self.anchors))
|
2021-01-08 19:52:28 +03:00
|
|
|
self.axes_min = toolhead.Coord(*[min(a) for a in acoords], e=0.)
|
|
|
|
self.axes_max = toolhead.Coord(*[max(a) for a in acoords], e=0.)
|
2018-07-13 06:28:58 +03:00
|
|
|
self.set_position([0., 0., 0.], ())
|
2020-01-14 05:39:55 +03:00
|
|
|
def get_steppers(self):
|
2018-07-13 06:28:58 +03:00
|
|
|
return list(self.steppers)
|
2019-11-14 01:59:40 +03:00
|
|
|
def calc_tag_position(self):
|
2018-07-13 06:28:58 +03:00
|
|
|
# Use only first three steppers to calculate cartesian position
|
2019-11-14 01:59:40 +03:00
|
|
|
spos = [s.get_tag_position() for s in self.steppers[:3]]
|
2018-07-13 06:28:58 +03:00
|
|
|
return mathutil.trilateration(self.anchors[:3], [sp*sp for sp in spos])
|
|
|
|
def set_position(self, newpos, homing_axes):
|
|
|
|
for s in self.steppers:
|
|
|
|
s.set_position(newpos)
|
|
|
|
def home(self, homing_state):
|
|
|
|
# XXX - homing not implemented
|
|
|
|
homing_state.set_axes([0, 1, 2])
|
|
|
|
homing_state.set_homed_position([0., 0., 0.])
|
|
|
|
def check_move(self, move):
|
|
|
|
# XXX - boundary checks and speed limits not implemented
|
|
|
|
pass
|
2019-11-25 03:16:21 +03:00
|
|
|
def get_status(self, eventtime):
|
2019-08-06 21:19:29 +03:00
|
|
|
# XXX - homed_checks and rail limits not implemented
|
2020-12-28 01:37:32 +03:00
|
|
|
return {
|
|
|
|
'homed_axes': 'xyz',
|
2021-01-08 19:52:28 +03:00
|
|
|
'axis_minimum': self.axes_min,
|
|
|
|
'axis_maximum': self.axes_max,
|
2020-12-28 01:37:32 +03:00
|
|
|
}
|
2018-07-13 06:28:58 +03:00
|
|
|
|
|
|
|
def load_kinematics(toolhead, config):
|
|
|
|
return WinchKinematics(toolhead, config)
|