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:
Kevin O'Connor
2025-09-26 22:31:55 -04:00
parent 01b3a6a8e4
commit d0b1b832dd
16 changed files with 33 additions and 33 deletions

View File

@@ -107,9 +107,9 @@ class GCodeMove:
'extrude_factor': self.extrude_factor,
'absolute_coordinates': self.absolute_coord,
'absolute_extrude': self.absolute_extrude,
'homing_origin': self.Coord(*self.homing_position[:4]),
'position': self.Coord(*self.last_position[:4]),
'gcode_position': self.Coord(*move_position),
'homing_origin': self.Coord(self.homing_position[:4]),
'position': self.Coord(self.last_position[:4]),
'gcode_position': self.Coord(move_position),
}
def reset_last_position(self):
if self.is_printer_ready:

View File

@@ -151,7 +151,7 @@ class PrinterMotionReport:
self.next_status_time = 0.
gcode = self.printer.lookup_object('gcode')
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.,
'steppers': [], 'trapq': [],
}
@@ -236,7 +236,7 @@ class PrinterMotionReport:
evelocity = velocity
# Report 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_extruder_velocity'] = evelocity
return self.last_status

View File

@@ -11,10 +11,10 @@ class CommandError(Exception):
# Custom "tuple" class for coordinates - add easy access to x, y, z components
class Coord(tuple):
__slots__ = ()
def __new__(cls, x, y, z, e, *args):
return tuple.__new__(cls, (x, y, z, e) + args)
def __getnewargs__(self):
return tuple(self)
def __new__(cls, t):
if len(t) < 4:
t = tuple(t) + (0,) * (4 - len(t))
return tuple.__new__(cls, t)
x = property(operator.itemgetter(0))
y = property(operator.itemgetter(1))
z = property(operator.itemgetter(2))

View File

@@ -18,8 +18,8 @@ class CartKinematics:
for rail, axis in zip(self.rails, 'xyz'):
rail.setup_itersolve('cartesian_stepper_alloc', axis.encode())
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.)
self.axes_min = toolhead.Coord([r[0] for r in ranges])
self.axes_max = toolhead.Coord([r[1] for r in ranges])
self.dc_module = None
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')

View File

@@ -28,8 +28,8 @@ class CoreXYKinematics:
'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.)
self.axes_min = toolhead.Coord([r[0] for r in ranges])
self.axes_max = toolhead.Coord([r[1] for r in ranges])
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def calc_position(self, stepper_positions):

View File

@@ -28,8 +28,8 @@ class CoreXZKinematics:
'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.)
self.axes_min = toolhead.Coord([r[0] for r in ranges])
self.axes_max = toolhead.Coord([r[1] for r in ranges])
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def calc_position(self, stepper_positions):

View File

@@ -85,8 +85,8 @@ class DeltaKinematics:
" 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.axes_min = toolhead.Coord((-max_xy, -max_xy, self.min_z))
self.axes_max = toolhead.Coord((max_xy, max_xy, self.max_z))
self.set_position([0., 0., 0.], "")
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]

View File

@@ -83,8 +83,8 @@ class DeltesianKinematics:
above=0., maxval=max_velocity)
self.max_z_accel = config.getfloat('max_z_accel', max_accel,
above=0., maxval=max_accel)
self.axes_min = toolhead.Coord(*[l[0] for l in self.limits], e=0.)
self.axes_max = toolhead.Coord(*[l[1] 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])
self.homed_axis = [False] * 3
self.set_position([0., 0., 0.], "")
def get_steppers(self):

View File

@@ -306,8 +306,8 @@ class GenericCartesianKinematics:
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
ranges = [c.get_rail().get_range()
for c in self.get_primary_carriages()]
axes_min = gcode.Coord(*[r[0] for r in ranges], e=0.)
axes_max = gcode.Coord(*[r[1] 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])
return {
'homed_axes': "".join(axes),
'axis_minimum': axes_min,

View File

@@ -21,8 +21,8 @@ class HybridCoreXYKinematics:
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
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.)
self.axes_min = toolhead.Coord([r[0] for r in ranges])
self.axes_max = toolhead.Coord([r[1] for r in ranges])
self.dc_module = None
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')

View File

@@ -21,8 +21,8 @@ class HybridCoreXZKinematics:
self.rails[1].setup_itersolve('cartesian_stepper_alloc', b'y')
self.rails[2].setup_itersolve('cartesian_stepper_alloc', b'z')
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.)
self.axes_min = toolhead.Coord([r[0] for r in ranges])
self.axes_max = toolhead.Coord([r[1] for r in ranges])
self.dc_module = None
if config.has_section('dual_carriage'):
dc_config = config.getsection('dual_carriage')

View File

@@ -6,7 +6,7 @@
class NoneKinematics:
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):
return []
def calc_position(self, stepper_positions):

View File

@@ -31,8 +31,8 @@ class PolarKinematics:
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.)
self.axes_min = toolhead.Coord((-max_xy, -max_xy, min_z))
self.axes_max = toolhead.Coord((max_xy, max_xy, max_z))
def get_steppers(self):
return list(self.steppers)
def calc_position(self, stepper_positions):

View File

@@ -71,8 +71,8 @@ class RotaryDeltaKinematics:
"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.axes_min = toolhead.Coord((-max_xy, -max_xy, self.min_z))
self.axes_max = toolhead.Coord((max_xy, max_xy, self.max_z))
self.set_position([0., 0., 0.], "")
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]

View File

@@ -23,8 +23,8 @@ class WinchKinematics:
s.set_trapq(toolhead.get_trapq())
# Setup boundary checks
acoords = list(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.axes_min = toolhead.Coord([min(a) for a in acoords])
self.axes_max = toolhead.Coord([max(a) for a in acoords])
self.set_position([0., 0., 0.], "")
def get_steppers(self):
return list(self.steppers)

View File

@@ -500,7 +500,7 @@ class ToolHead:
'stalls': self.print_stall,
'estimated_print_time': estimated_print_time,
'extruder': extruder.get_name(),
'position': self.Coord(*self.commanded_pos[:4]),
'position': self.Coord(self.commanded_pos[:4]),
'max_velocity': self.max_velocity,
'max_accel': self.max_accel,
'minimum_cruise_ratio': self.min_cruise_ratio,