mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-12-16 05:09:56 +01:00
gcode: Change Coord() class to initialize from a list or tuple
Instead of passing arguments as parameters, pass them as a list (or tuple). This simplifies the callers and makes it easier to pass additional parameters. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -107,9 +107,9 @@ class GCodeMove:
|
|||||||
'extrude_factor': self.extrude_factor,
|
'extrude_factor': self.extrude_factor,
|
||||||
'absolute_coordinates': self.absolute_coord,
|
'absolute_coordinates': self.absolute_coord,
|
||||||
'absolute_extrude': self.absolute_extrude,
|
'absolute_extrude': self.absolute_extrude,
|
||||||
'homing_origin': self.Coord(*self.homing_position[:4]),
|
'homing_origin': self.Coord(self.homing_position[:4]),
|
||||||
'position': self.Coord(*self.last_position[:4]),
|
'position': self.Coord(self.last_position[:4]),
|
||||||
'gcode_position': self.Coord(*move_position),
|
'gcode_position': self.Coord(move_position),
|
||||||
}
|
}
|
||||||
def reset_last_position(self):
|
def reset_last_position(self):
|
||||||
if self.is_printer_ready:
|
if self.is_printer_ready:
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class PrinterMotionReport:
|
|||||||
self.next_status_time = 0.
|
self.next_status_time = 0.
|
||||||
gcode = self.printer.lookup_object('gcode')
|
gcode = self.printer.lookup_object('gcode')
|
||||||
self.last_status = {
|
self.last_status = {
|
||||||
'live_position': gcode.Coord(0., 0., 0., 0.),
|
'live_position': gcode.Coord((0., 0., 0.)),
|
||||||
'live_velocity': 0., 'live_extruder_velocity': 0.,
|
'live_velocity': 0., 'live_extruder_velocity': 0.,
|
||||||
'steppers': [], 'trapq': [],
|
'steppers': [], 'trapq': [],
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ class PrinterMotionReport:
|
|||||||
evelocity = velocity
|
evelocity = velocity
|
||||||
# Report status
|
# Report status
|
||||||
self.last_status = dict(self.last_status)
|
self.last_status = dict(self.last_status)
|
||||||
self.last_status['live_position'] = toolhead.Coord(*(xyzpos + epos))
|
self.last_status['live_position'] = toolhead.Coord(xyzpos + epos)
|
||||||
self.last_status['live_velocity'] = xyzvelocity
|
self.last_status['live_velocity'] = xyzvelocity
|
||||||
self.last_status['live_extruder_velocity'] = evelocity
|
self.last_status['live_extruder_velocity'] = evelocity
|
||||||
return self.last_status
|
return self.last_status
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ class CommandError(Exception):
|
|||||||
# Custom "tuple" class for coordinates - add easy access to x, y, z components
|
# Custom "tuple" class for coordinates - add easy access to x, y, z components
|
||||||
class Coord(tuple):
|
class Coord(tuple):
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
def __new__(cls, x, y, z, e, *args):
|
def __new__(cls, t):
|
||||||
return tuple.__new__(cls, (x, y, z, e) + args)
|
if len(t) < 4:
|
||||||
def __getnewargs__(self):
|
t = tuple(t) + (0,) * (4 - len(t))
|
||||||
return tuple(self)
|
return tuple.__new__(cls, t)
|
||||||
x = property(operator.itemgetter(0))
|
x = property(operator.itemgetter(0))
|
||||||
y = property(operator.itemgetter(1))
|
y = property(operator.itemgetter(1))
|
||||||
z = property(operator.itemgetter(2))
|
z = property(operator.itemgetter(2))
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class CartKinematics:
|
|||||||
for rail, axis in zip(self.rails, 'xyz'):
|
for rail, axis in zip(self.rails, 'xyz'):
|
||||||
rail.setup_itersolve('cartesian_stepper_alloc', axis.encode())
|
rail.setup_itersolve('cartesian_stepper_alloc', axis.encode())
|
||||||
ranges = [r.get_range() for r in self.rails]
|
ranges = [r.get_range() for r in self.rails]
|
||||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
self.axes_min = toolhead.Coord([r[0] for r in ranges])
|
||||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
self.axes_max = toolhead.Coord([r[1] for r in ranges])
|
||||||
self.dc_module = None
|
self.dc_module = None
|
||||||
if config.has_section('dual_carriage'):
|
if config.has_section('dual_carriage'):
|
||||||
dc_config = config.getsection('dual_carriage')
|
dc_config = config.getsection('dual_carriage')
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ class CoreXYKinematics:
|
|||||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
ranges = [r.get_range() for r in self.rails]
|
ranges = [r.get_range() for r in self.rails]
|
||||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
self.axes_min = toolhead.Coord([r[0] for r in ranges])
|
||||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
self.axes_max = toolhead.Coord([r[1] for r in ranges])
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||||
def calc_position(self, stepper_positions):
|
def calc_position(self, stepper_positions):
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ class CoreXZKinematics:
|
|||||||
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
'max_z_accel', max_accel, above=0., maxval=max_accel)
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
ranges = [r.get_range() for r in self.rails]
|
ranges = [r.get_range() for r in self.rails]
|
||||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
self.axes_min = toolhead.Coord([r[0] for r in ranges])
|
||||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
self.axes_max = toolhead.Coord([r[1] for r in ranges])
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||||
def calc_position(self, stepper_positions):
|
def calc_position(self, stepper_positions):
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ class DeltaKinematics:
|
|||||||
" and %.2fmm)"
|
" and %.2fmm)"
|
||||||
% (max_xy, math.sqrt(self.slow_xy2),
|
% (max_xy, math.sqrt(self.slow_xy2),
|
||||||
math.sqrt(self.very_slow_xy2)))
|
math.sqrt(self.very_slow_xy2)))
|
||||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, self.min_z, 0.)
|
self.axes_min = toolhead.Coord((-max_xy, -max_xy, self.min_z))
|
||||||
self.axes_max = toolhead.Coord(max_xy, max_xy, self.max_z, 0.)
|
self.axes_max = toolhead.Coord((max_xy, max_xy, self.max_z))
|
||||||
self.set_position([0., 0., 0.], "")
|
self.set_position([0., 0., 0.], "")
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ class DeltesianKinematics:
|
|||||||
above=0., maxval=max_velocity)
|
above=0., maxval=max_velocity)
|
||||||
self.max_z_accel = config.getfloat('max_z_accel', max_accel,
|
self.max_z_accel = config.getfloat('max_z_accel', max_accel,
|
||||||
above=0., maxval=max_accel)
|
above=0., maxval=max_accel)
|
||||||
self.axes_min = toolhead.Coord(*[l[0] for l in self.limits], e=0.)
|
self.axes_min = toolhead.Coord([l[0] for l in self.limits])
|
||||||
self.axes_max = toolhead.Coord(*[l[1] for l in self.limits], e=0.)
|
self.axes_max = toolhead.Coord([l[1] for l in self.limits])
|
||||||
self.homed_axis = [False] * 3
|
self.homed_axis = [False] * 3
|
||||||
self.set_position([0., 0., 0.], "")
|
self.set_position([0., 0., 0.], "")
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
|
|||||||
@@ -306,8 +306,8 @@ class GenericCartesianKinematics:
|
|||||||
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
|
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
|
||||||
ranges = [c.get_rail().get_range()
|
ranges = [c.get_rail().get_range()
|
||||||
for c in self.get_primary_carriages()]
|
for c in self.get_primary_carriages()]
|
||||||
axes_min = gcode.Coord(*[r[0] for r in ranges], e=0.)
|
axes_min = gcode.Coord([r[0] for r in ranges])
|
||||||
axes_max = gcode.Coord(*[r[1] for r in ranges], e=0.)
|
axes_max = gcode.Coord([r[1] for r in ranges])
|
||||||
return {
|
return {
|
||||||
'homed_axes': "".join(axes),
|
'homed_axes': "".join(axes),
|
||||||
'axis_minimum': axes_min,
|
'axis_minimum': axes_min,
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ class HybridCoreXYKinematics:
|
|||||||
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
|
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
|
||||||
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
|
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
|
||||||
ranges = [r.get_range() for r in self.rails]
|
ranges = [r.get_range() for r in self.rails]
|
||||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
self.axes_min = toolhead.Coord([r[0] for r in ranges])
|
||||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
self.axes_max = toolhead.Coord([r[1] for r in ranges])
|
||||||
self.dc_module = None
|
self.dc_module = None
|
||||||
if config.has_section('dual_carriage'):
|
if config.has_section('dual_carriage'):
|
||||||
dc_config = config.getsection('dual_carriage')
|
dc_config = config.getsection('dual_carriage')
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ class HybridCoreXZKinematics:
|
|||||||
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
|
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
|
||||||
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
|
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
|
||||||
ranges = [r.get_range() for r in self.rails]
|
ranges = [r.get_range() for r in self.rails]
|
||||||
self.axes_min = toolhead.Coord(*[r[0] for r in ranges], e=0.)
|
self.axes_min = toolhead.Coord([r[0] for r in ranges])
|
||||||
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.)
|
self.axes_max = toolhead.Coord([r[1] for r in ranges])
|
||||||
self.dc_module = None
|
self.dc_module = None
|
||||||
if config.has_section('dual_carriage'):
|
if config.has_section('dual_carriage'):
|
||||||
dc_config = config.getsection('dual_carriage')
|
dc_config = config.getsection('dual_carriage')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class NoneKinematics:
|
class NoneKinematics:
|
||||||
def __init__(self, toolhead, config):
|
def __init__(self, toolhead, config):
|
||||||
self.axes_minmax = toolhead.Coord(0., 0., 0., 0.)
|
self.axes_minmax = toolhead.Coord((0., 0., 0.))
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return []
|
return []
|
||||||
def calc_position(self, stepper_positions):
|
def calc_position(self, stepper_positions):
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ class PolarKinematics:
|
|||||||
self.limit_xy2 = -1.
|
self.limit_xy2 = -1.
|
||||||
max_xy = self.rails[0].get_range()[1]
|
max_xy = self.rails[0].get_range()[1]
|
||||||
min_z, max_z = self.rails[1].get_range()
|
min_z, max_z = self.rails[1].get_range()
|
||||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, min_z, 0.)
|
self.axes_min = toolhead.Coord((-max_xy, -max_xy, min_z))
|
||||||
self.axes_max = toolhead.Coord(max_xy, max_xy, max_z, 0.)
|
self.axes_max = toolhead.Coord((max_xy, max_xy, max_z))
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return list(self.steppers)
|
return list(self.steppers)
|
||||||
def calc_position(self, stepper_positions):
|
def calc_position(self, stepper_positions):
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ class RotaryDeltaKinematics:
|
|||||||
"Delta max build height %.2fmm (radius tapered above %.2fmm)"
|
"Delta max build height %.2fmm (radius tapered above %.2fmm)"
|
||||||
% (self.max_z, self.limit_z))
|
% (self.max_z, self.limit_z))
|
||||||
max_xy = math.sqrt(self.max_xy2)
|
max_xy = math.sqrt(self.max_xy2)
|
||||||
self.axes_min = toolhead.Coord(-max_xy, -max_xy, self.min_z, 0.)
|
self.axes_min = toolhead.Coord((-max_xy, -max_xy, self.min_z))
|
||||||
self.axes_max = toolhead.Coord(max_xy, max_xy, self.max_z, 0.)
|
self.axes_max = toolhead.Coord((max_xy, max_xy, self.max_z))
|
||||||
self.set_position([0., 0., 0.], "")
|
self.set_position([0., 0., 0.], "")
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return [s for rail in self.rails for s in rail.get_steppers()]
|
return [s for rail in self.rails for s in rail.get_steppers()]
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class WinchKinematics:
|
|||||||
s.set_trapq(toolhead.get_trapq())
|
s.set_trapq(toolhead.get_trapq())
|
||||||
# Setup boundary checks
|
# Setup boundary checks
|
||||||
acoords = list(zip(*self.anchors))
|
acoords = list(zip(*self.anchors))
|
||||||
self.axes_min = toolhead.Coord(*[min(a) for a in acoords], e=0.)
|
self.axes_min = toolhead.Coord([min(a) for a in acoords])
|
||||||
self.axes_max = toolhead.Coord(*[max(a) for a in acoords], e=0.)
|
self.axes_max = toolhead.Coord([max(a) for a in acoords])
|
||||||
self.set_position([0., 0., 0.], "")
|
self.set_position([0., 0., 0.], "")
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return list(self.steppers)
|
return list(self.steppers)
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ class ToolHead:
|
|||||||
'stalls': self.print_stall,
|
'stalls': self.print_stall,
|
||||||
'estimated_print_time': estimated_print_time,
|
'estimated_print_time': estimated_print_time,
|
||||||
'extruder': extruder.get_name(),
|
'extruder': extruder.get_name(),
|
||||||
'position': self.Coord(*self.commanded_pos[:4]),
|
'position': self.Coord(self.commanded_pos[:4]),
|
||||||
'max_velocity': self.max_velocity,
|
'max_velocity': self.max_velocity,
|
||||||
'max_accel': self.max_accel,
|
'max_accel': self.max_accel,
|
||||||
'minimum_cruise_ratio': self.min_cruise_ratio,
|
'minimum_cruise_ratio': self.min_cruise_ratio,
|
||||||
|
|||||||
Reference in New Issue
Block a user