mirror of https://github.com/Desuuuu/klipper.git
kinematics: Calculate axis_minimum/axis_maximum in advance
Calculate the get_status() axis_minimum and axis_maximum fields in advance so that they don't need to be calculated on each get_status() call. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
f79187d726
commit
c8434ec54b
|
@ -1,10 +1,10 @@
|
|||
# Code for handling the kinematics of cartesian robots
|
||||
#
|
||||
# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging
|
||||
import stepper, homing
|
||||
import stepper
|
||||
|
||||
class CartKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -23,17 +23,20 @@ class CartKinematics:
|
|||
self._motor_off)
|
||||
# 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)
|
||||
self.max_z_accel = config.getfloat(
|
||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.max_z_velocity = config.getfloat('max_z_velocity', max_velocity,
|
||||
above=0., maxval=max_velocity)
|
||||
self.max_z_accel = config.getfloat('max_z_accel', max_accel,
|
||||
above=0., maxval=max_accel)
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
ranges = [r.get_range() for r in self.rails]
|
||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
||||
# Setup stepper max halt velocity
|
||||
max_halt_velocity = toolhead.get_max_axis_halt()
|
||||
self.rails[0].set_max_jerk(max_halt_velocity, max_accel)
|
||||
self.rails[1].set_max_jerk(max_halt_velocity, max_accel)
|
||||
self.rails[2].set_max_jerk(
|
||||
min(max_halt_velocity, self.max_z_velocity), max_accel)
|
||||
self.rails[2].set_max_jerk(min(max_halt_velocity, self.max_z_velocity),
|
||||
max_accel)
|
||||
# Check for dual carriage support
|
||||
if config.has_section('dual_carriage'):
|
||||
dc_config = config.getsection('dual_carriage')
|
||||
|
@ -118,14 +121,10 @@ class CartKinematics:
|
|||
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
|
||||
def get_status(self, eventtime):
|
||||
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
|
||||
axes_min = [0.0, 0.0, 0.0, 0.0]
|
||||
axes_max = [0.0, 0.0, 0.0, 0.0]
|
||||
for pos, rail in enumerate(self.rails):
|
||||
axes_min[pos], axes_max[pos] = rail.get_range()
|
||||
return {
|
||||
'homed_axes': "".join(axes),
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
# Dual carriage support
|
||||
def _activate_carriage(self, carriage):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Code for handling the kinematics of corexy robots
|
||||
#
|
||||
# Copyright (C) 2017-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2017-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging, math
|
||||
import stepper, homing
|
||||
import stepper
|
||||
|
||||
class CoreXYKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -31,6 +31,9 @@ class CoreXYKinematics:
|
|||
self.max_z_accel = config.getfloat(
|
||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
ranges = [r.get_range() for r in self.rails]
|
||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
||||
# Setup stepper max halt velocity
|
||||
max_halt_velocity = toolhead.get_max_axis_halt()
|
||||
max_xy_halt_velocity = max_halt_velocity * math.sqrt(2.)
|
||||
|
@ -95,14 +98,10 @@ class CoreXYKinematics:
|
|||
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
|
||||
def get_status(self, eventtime):
|
||||
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
|
||||
axes_min = [0.0, 0.0, 0.0, 0.0]
|
||||
axes_max = [0.0, 0.0, 0.0, 0.0]
|
||||
for pos, rail in enumerate(self.rails):
|
||||
axes_min[pos], axes_max[pos] = rail.get_range()
|
||||
return {
|
||||
'homed_axes': "".join(axes),
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
|
||||
def load_kinematics(toolhead, config):
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging, math
|
||||
import stepper, homing
|
||||
import stepper
|
||||
|
||||
class CoreXZKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -31,6 +31,9 @@ class CoreXZKinematics:
|
|||
self.max_z_accel = config.getfloat(
|
||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.limits = [(1.0, -1.0)] * 3
|
||||
ranges = [r.get_range() for r in self.rails]
|
||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
||||
# Setup stepper max halt velocity
|
||||
max_halt_velocity = toolhead.get_max_axis_halt()
|
||||
max_xy_halt_velocity = max_halt_velocity * math.sqrt(2.)
|
||||
|
@ -94,14 +97,10 @@ class CoreXZKinematics:
|
|||
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
|
||||
def get_status(self, eventtime):
|
||||
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
|
||||
axes_min = [0.0, 0.0, 0.0, 0.0]
|
||||
axes_max = [0.0, 0.0, 0.0, 0.0]
|
||||
for pos, rail in enumerate(self.rails):
|
||||
axes_min[pos], axes_max[pos] = rail.get_range()
|
||||
return {
|
||||
'homed_axes': "".join(axes),
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
|
||||
def load_kinematics(toolhead, config):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Code for handling the kinematics of linear delta robots
|
||||
#
|
||||
# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging
|
||||
import stepper, mathutil, homing
|
||||
import stepper, mathutil
|
||||
|
||||
# Slow moves once the ratio of tower to XY movement exceeds SLOW_RATIO
|
||||
SLOW_RATIO = 3.
|
||||
|
@ -68,25 +68,28 @@ class DeltaKinematics:
|
|||
self.limit_z = min([ep - arm
|
||||
for ep, arm in zip(self.abs_endstops, arm_lengths)])
|
||||
logging.info(
|
||||
"Delta max build height %.2fmm (radius tapered above %.2fmm)" % (
|
||||
self.max_z, self.limit_z))
|
||||
"Delta max build height %.2fmm (radius tapered above %.2fmm)"
|
||||
% (self.max_z, self.limit_z))
|
||||
# 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()
|
||||
for r in self.rails]) * .5
|
||||
min_arm_length = min(arm_lengths)
|
||||
def ratio_to_dist(ratio):
|
||||
def ratio_to_xy(ratio):
|
||||
return (ratio * math.sqrt(min_arm_length**2 / (ratio**2 + 1.)
|
||||
- half_min_step_dist**2)
|
||||
+ half_min_step_dist)
|
||||
self.slow_xy2 = (ratio_to_dist(SLOW_RATIO) - radius)**2
|
||||
self.very_slow_xy2 = (ratio_to_dist(2. * SLOW_RATIO) - radius)**2
|
||||
+ half_min_step_dist - radius)
|
||||
self.slow_xy2 = ratio_to_xy(SLOW_RATIO)**2
|
||||
self.very_slow_xy2 = ratio_to_xy(2. * SLOW_RATIO)**2
|
||||
self.max_xy2 = min(print_radius, min_arm_length - radius,
|
||||
ratio_to_dist(4. * SLOW_RATIO) - radius)**2
|
||||
ratio_to_xy(4. * SLOW_RATIO))**2
|
||||
max_xy = math.sqrt(self.max_xy2)
|
||||
logging.info("Delta max build radius %.2fmm (moves slowed past %.2fmm"
|
||||
" and %.2fmm)" % (
|
||||
math.sqrt(self.max_xy2), math.sqrt(self.slow_xy2),
|
||||
math.sqrt(self.very_slow_xy2)))
|
||||
" and %.2fmm)"
|
||||
% (max_xy, math.sqrt(self.slow_xy2),
|
||||
math.sqrt(self.very_slow_xy2)))
|
||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, self.min_z, 0.)
|
||||
self.axes_max = toolhead.Coord(max_xy, max_xy, self.max_z, 0.)
|
||||
self.set_position([0., 0., 0.], ())
|
||||
def get_steppers(self):
|
||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||
|
@ -146,13 +149,10 @@ class DeltaKinematics:
|
|||
limit_xy2 = -1.
|
||||
self.limit_xy2 = min(limit_xy2, self.slow_xy2)
|
||||
def get_status(self, eventtime):
|
||||
max_xy = math.sqrt(self.max_xy2)
|
||||
axes_min = [-max_xy, -max_xy, self.min_z, 0.]
|
||||
axes_max = [max_xy, max_xy, self.max_z, 0.]
|
||||
return {
|
||||
'homed_axes': '' if self.need_home else 'xyz',
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
def get_calibration(self):
|
||||
endstops = [rail.get_homing_info().position_endstop
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# Dummy "none" kinematics support (for developer testing)
|
||||
#
|
||||
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import homing
|
||||
|
||||
class NoneKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
pass
|
||||
self.axes_minmax = toolhead.Coord(0., 0., 0., 0.)
|
||||
def get_steppers(self):
|
||||
return []
|
||||
def calc_tag_position(self):
|
||||
|
@ -19,11 +18,10 @@ class NoneKinematics:
|
|||
def check_move(self, move):
|
||||
pass
|
||||
def get_status(self, eventtime):
|
||||
axes_lim = [0.0, 0.0, 0.0, 0.0]
|
||||
return {
|
||||
'homed_axes': '',
|
||||
'axis_minimum': homing.Coord(*axes_lim),
|
||||
'axis_maximum': homing.Coord(*axes_lim)
|
||||
'axis_minimum': self.axes_minmax,
|
||||
'axis_maximum': self.axes_minmax,
|
||||
}
|
||||
|
||||
def load_kinematics(toolhead, config):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Code for handling the kinematics of polar robots
|
||||
#
|
||||
# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging, math
|
||||
import stepper, homing
|
||||
import stepper
|
||||
|
||||
class PolarKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -32,6 +32,10 @@ class PolarKinematics:
|
|||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||
self.limit_z = (1.0, -1.0)
|
||||
self.limit_xy2 = -1.
|
||||
max_xy = self.rails[0].get_range()[1]
|
||||
min_z, max_z = self.rails[1].get_range()
|
||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, min_z, 0.)
|
||||
self.axes_max = toolhead.Coord(max_xy, max_xy, max_z, 0.)
|
||||
# Setup stepper max halt velocity
|
||||
max_halt_velocity = toolhead.get_max_axis_halt()
|
||||
stepper_bed.set_max_jerk(max_halt_velocity, max_accel)
|
||||
|
@ -108,14 +112,10 @@ class PolarKinematics:
|
|||
def get_status(self, eventtime):
|
||||
xy_home = "xy" if self.limit_xy2 >= 0. else ""
|
||||
z_home = "z" if self.limit_z[0] <= self.limit_z[1] else ""
|
||||
lim_xy = self.rails[0].get_range()
|
||||
lim_z = self.rails[1].get_range()
|
||||
axes_min = [lim_xy[0], lim_xy[0], lim_z[0], 0.]
|
||||
axes_max = [lim_xy[1], lim_xy[1], lim_z[1], 0.]
|
||||
return {
|
||||
'homed_axes': xy_home + z_home,
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
|
||||
def load_kinematics(toolhead, config):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Code for handling the kinematics of rotary delta robots
|
||||
#
|
||||
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2019-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import math, logging
|
||||
import stepper, mathutil, chelper, homing
|
||||
import stepper, mathutil, chelper
|
||||
|
||||
class RotaryDeltaKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -76,6 +76,9 @@ class RotaryDeltaKinematics:
|
|||
logging.info(
|
||||
"Delta max build height %.2fmm (radius tapered above %.2fmm)"
|
||||
% (self.max_z, self.limit_z))
|
||||
max_xy = math.sqrt(self.max_xy2)
|
||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, self.min_z, 0.)
|
||||
self.axes_max = toolhead.Coord(max_xy, max_xy, self.max_z, 0.)
|
||||
self.set_position([0., 0., 0.], ())
|
||||
def get_steppers(self):
|
||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||
|
@ -122,13 +125,10 @@ class RotaryDeltaKinematics:
|
|||
limit_xy2 = -1.
|
||||
self.limit_xy2 = limit_xy2
|
||||
def get_status(self, eventtime):
|
||||
max_xy = math.sqrt(self.max_xy2)
|
||||
axes_min = [-max_xy, -max_xy, self.min_z, 0.]
|
||||
axes_max = [max_xy, max_xy, self.max_z, 0.]
|
||||
return {
|
||||
'homed_axes': '' if self.need_home else 'XYZ',
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
def get_calibration(self):
|
||||
return self.calibration
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# Code for handling the kinematics of cable winch robots
|
||||
#
|
||||
# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2018-2021 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import stepper, mathutil, homing
|
||||
import stepper, mathutil
|
||||
|
||||
class WinchKinematics:
|
||||
def __init__(self, toolhead, config):
|
||||
|
@ -28,6 +28,9 @@ class WinchKinematics:
|
|||
for s in self.steppers:
|
||||
s.set_max_jerk(max_halt_velocity, max_accel)
|
||||
# Setup boundary checks
|
||||
acoords = zip(*self.anchors)
|
||||
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.)
|
||||
self.set_position([0., 0., 0.], ())
|
||||
def get_steppers(self):
|
||||
return list(self.steppers)
|
||||
|
@ -47,15 +50,10 @@ class WinchKinematics:
|
|||
pass
|
||||
def get_status(self, eventtime):
|
||||
# XXX - homed_checks and rail limits not implemented
|
||||
axes_min = [0.0, 0.0, 0.0, 0.0]
|
||||
axes_max = [0.0, 0.0, 0.0, 0.0]
|
||||
for pos, axis in enumerate('xyz'):
|
||||
axes_min[pos] = min([a[pos] for a in self.anchors])
|
||||
axes_max[pos] = max([a[pos] for a in self.anchors])
|
||||
return {
|
||||
'homed_axes': 'xyz',
|
||||
'axis_minimum': homing.Coord(*axes_min),
|
||||
'axis_maximum': homing.Coord(*axes_max)
|
||||
'axis_minimum': self.axes_min,
|
||||
'axis_maximum': self.axes_max,
|
||||
}
|
||||
|
||||
def load_kinematics(toolhead, config):
|
||||
|
|
|
@ -196,6 +196,7 @@ class DripModeEndSignal(Exception):
|
|||
|
||||
# Main code to track events (and their timing) on the printer toolhead
|
||||
class ToolHead:
|
||||
Coord = homing.Coord
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.reactor = self.printer.get_reactor()
|
||||
|
@ -502,7 +503,7 @@ class ToolHead:
|
|||
res.update({ 'print_time': print_time,
|
||||
'estimated_print_time': estimated_print_time,
|
||||
'extruder': self.extruder.get_name(),
|
||||
'position': homing.Coord(*self.commanded_pos),
|
||||
'position': self.Coord(*self.commanded_pos),
|
||||
'max_velocity': self.max_velocity,
|
||||
'max_accel': self.max_accel,
|
||||
'max_accel_to_decel': self.requested_accel_to_decel,
|
||||
|
|
Loading…
Reference in New Issue