stepper: Remove set_tag_position() code

Have callers store the stepper positions in a dict.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-05-01 00:27:43 -04:00
parent 77bc5e4388
commit c0d860487a
17 changed files with 62 additions and 66 deletions

View File

@ -331,12 +331,11 @@ Useful steps:
seconds) to a cartesian coordinate (in millimeters), and then seconds) to a cartesian coordinate (in millimeters), and then
calculate the desired stepper position (in millimeters) from that calculate the desired stepper position (in millimeters) from that
cartesian coordinate. cartesian coordinate.
4. Implement the `calc_tag_position()` method in the new kinematics 4. Implement the `calc_position()` method in the new kinematics class.
class. This method calculates the position of the toolhead in This method calculates the position of the toolhead in cartesian
cartesian coordinates from the position of each stepper (as coordinates from the position of each stepper. It does not need to
returned by `stepper.get_tag_position()`). It does not need to be be efficient as it is typically only called during homing and
efficient as it is typically only called during homing and probing probing operations.
operations.
5. Other methods. Implement the `check_move()`, `get_status()`, 5. Other methods. Implement the `check_move()`, `get_status()`,
`get_steppers()`, `home()`, and `set_position()` methods. These `get_steppers()`, `home()`, and `set_position()` methods. These
functions are typically used to provide kinematic specific checks. functions are typically used to provide kinematic specific checks.

View File

@ -233,9 +233,9 @@ class DeltaCalibrate:
toolhead = self.printer.lookup_object('toolhead') toolhead = self.printer.lookup_object('toolhead')
toolhead.flush_step_generation() toolhead.flush_step_generation()
kin = toolhead.get_kinematics() kin = toolhead.get_kinematics()
for s in kin.get_steppers(): kin_spos = {s.get_name(): s.get_commanded_position()
s.set_tag_position(s.get_commanded_position()) for s in kin.get_steppers()}
kin_pos = kin.calc_tag_position() kin_pos = kin.calc_position(kin_spos)
# Convert location to a stable position # Convert location to a stable position
delta_params = kin.get_calibration() delta_params = kin.get_calibration()
stable_pos = tuple(delta_params.calc_stable_position(kin_pos)) stable_pos = tuple(delta_params.calc_stable_position(kin_pos))

View File

@ -102,17 +102,16 @@ class EndstopPhase:
self.name, phase, self.endstop_phase)) self.name, phase, self.endstop_phase))
return delta * self.step_dist return delta * self.step_dist
def handle_home_rails_end(self, homing_state, rails): def handle_home_rails_end(self, homing_state, rails):
kin_spos = homing_state.get_stepper_trigger_positions()
orig_pos = kin_spos.get(self.name)
if orig_pos is None:
return
for rail in rails: for rail in rails:
stepper = rail.get_steppers()[0] stepper = rail.get_steppers()[0]
if stepper.get_name() != self.name: if stepper.get_name() == self.name:
continue offset = self.get_homed_offset(stepper)
orig_pos = rail.get_tag_position() kin_spos[self.name] = self.align_endstop(orig_pos) + offset
offset = self.get_homed_offset(stepper) return
pos = self.align_endstop(orig_pos) + offset
if pos == orig_pos:
return False
rail.set_tag_position(pos)
return True
class EndstopPhases: class EndstopPhases:
def __init__(self, config): def __init__(self, config):

View File

@ -247,12 +247,10 @@ class GCodeMove:
steppers = kin.get_steppers() steppers = kin.get_steppers()
mcu_pos = " ".join(["%s:%d" % (s.get_name(), s.get_mcu_position()) mcu_pos = " ".join(["%s:%d" % (s.get_name(), s.get_mcu_position())
for s in steppers]) for s in steppers])
for s in steppers: cinfo = [(s.get_name(), s.get_commanded_position()) for s in steppers]
s.set_tag_position(s.get_commanded_position()) stepper_pos = " ".join(["%s:%.6f" % (a, v) for a, v in cinfo])
stepper_pos = " ".join(["%s:%.6f" % (s.get_name(), s.get_tag_position()) kinfo = zip("XYZ", kin.calc_position(dict(cinfo)))
for s in steppers]) kin_pos = " ".join(["%s:%.6f" % (a, v) for a, v in kinfo])
kin_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZ", kin.calc_tag_position())])
toolhead_pos = " ".join(["%s:%.6f" % (a, v) for a, v in zip( toolhead_pos = " ".join(["%s:%.6f" % (a, v) for a, v in zip(
"XYZE", toolhead.get_position())]) "XYZE", toolhead.get_position())])
gcode_pos = " ".join(["%s:%.6f" % (a, v) gcode_pos = " ".join(["%s:%.6f" % (a, v)

View File

@ -46,8 +46,8 @@ class HomingMove:
# Note start location # Note start location
self.toolhead.flush_step_generation() self.toolhead.flush_step_generation()
kin = self.toolhead.get_kinematics() kin = self.toolhead.get_kinematics()
for s in kin.get_steppers(): kin_spos = {s.get_name(): s.get_commanded_position()
s.set_tag_position(s.get_commanded_position()) for s in kin.get_steppers()}
start_mcu_pos = [(s, name, s.get_mcu_position()) start_mcu_pos = [(s, name, s.get_mcu_position())
for es, name in self.endstops for es, name in self.endstops
for s in es.get_steppers()] for s in es.get_steppers()]
@ -80,9 +80,10 @@ class HomingMove:
for s, name, spos in start_mcu_pos] for s, name, spos in start_mcu_pos]
if probe_pos: if probe_pos:
for s, name, spos, epos in self.end_mcu_pos: for s, name, spos, epos in self.end_mcu_pos:
md = (epos - spos) * s.get_step_dist() sname = s.get_name()
s.set_tag_position(s.get_tag_position() + md) if sname in kin_spos:
movepos = list(kin.calc_tag_position())[:3] + movepos[3:] kin_spos[sname] += (epos - spos) * s.get_step_dist()
movepos = list(kin.calc_position(kin_spos))[:3] + movepos[3:]
self.toolhead.set_position(movepos) self.toolhead.set_position(movepos)
# Signal homing/probing move complete # Signal homing/probing move complete
try: try:
@ -107,10 +108,13 @@ class Homing:
self.printer = printer self.printer = printer
self.toolhead = printer.lookup_object('toolhead') self.toolhead = printer.lookup_object('toolhead')
self.changed_axes = [] self.changed_axes = []
self.kin_spos = {}
def set_axes(self, axes): def set_axes(self, axes):
self.changed_axes = axes self.changed_axes = axes
def get_axes(self): def get_axes(self):
return self.changed_axes return self.changed_axes
def get_stepper_trigger_positions(self):
return self.kin_spos
def _fill_coord(self, coord): def _fill_coord(self, coord):
# Fill in any None entries in 'coord' with current toolhead position # Fill in any None entries in 'coord' with current toolhead position
thcoord = list(self.toolhead.get_position()) thcoord = list(self.toolhead.get_position())
@ -155,12 +159,13 @@ class Homing:
# Signal home operation complete # Signal home operation complete
self.toolhead.flush_step_generation() self.toolhead.flush_step_generation()
kin = self.toolhead.get_kinematics() kin = self.toolhead.get_kinematics()
for s in kin.get_steppers(): kin_spos = {s.get_name(): s.get_commanded_position()
s.set_tag_position(s.get_commanded_position()) for s in kin.get_steppers()}
ret = self.printer.send_event("homing:home_rails_end", self, rails) self.kin_spos = dict(kin_spos)
if any(ret): self.printer.send_event("homing:home_rails_end", self, rails)
if kin_spos != self.kin_spos:
# Apply any homing offsets # Apply any homing offsets
adjustpos = kin.calc_tag_position() adjustpos = kin.calc_position(self.kin_spos)
for axis in homing_axes: for axis in homing_axes:
movepos[axis] = adjustpos[axis] movepos[axis] = adjustpos[axis]
self.toolhead.set_position(movepos) self.toolhead.set_position(movepos)

View File

@ -82,9 +82,9 @@ class ManualProbeHelper:
return self.last_kinematics_pos return self.last_kinematics_pos
self.toolhead.flush_step_generation() self.toolhead.flush_step_generation()
kin = self.toolhead.get_kinematics() kin = self.toolhead.get_kinematics()
for s in kin.get_steppers(): kin_spos = {s.get_name(): s.get_commanded_position()
s.set_tag_position(s.get_commanded_position()) for s in kin.get_steppers()}
kin_pos = kin.calc_tag_position() kin_pos = kin.calc_position(kin_spos)
self.last_toolhead_pos = toolhead_pos self.last_toolhead_pos = toolhead_pos
self.last_kinematics_pos = kin_pos self.last_kinematics_pos = kin_pos
return kin_pos return kin_pos

View File

@ -51,8 +51,8 @@ class CartKinematics:
dca = self.dual_carriage_axis dca = self.dual_carriage_axis
rails = rails[:dca] + self.dual_carriage_rails + rails[dca+1:] rails = rails[:dca] + self.dual_carriage_rails + rails[dca+1:]
return [s for rail in rails for s in rail.get_steppers()] return [s for rail in rails for s in rail.get_steppers()]
def calc_tag_position(self): def calc_position(self, stepper_positions):
return [rail.get_tag_position() for rail in self.rails] return [stepper_positions[rail.get_name()] for rail in self.rails]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails): for i, rail in enumerate(self.rails):
rail.set_position(newpos) rail.set_position(newpos)

View File

@ -36,8 +36,8 @@ class CoreXYKinematics:
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.) self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=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()]
def calc_tag_position(self): def calc_position(self, stepper_positions):
pos = [rail.get_tag_position() for rail in self.rails] pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [0.5 * (pos[0] + pos[1]), 0.5 * (pos[0] - pos[1]), pos[2]] return [0.5 * (pos[0] + pos[1]), 0.5 * (pos[0] - pos[1]), pos[2]]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails): for i, rail in enumerate(self.rails):

View File

@ -36,8 +36,8 @@ class CoreXZKinematics:
self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=0.) self.axes_max = toolhead.Coord(*[r[1] for r in ranges], e=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()]
def calc_tag_position(self): def calc_position(self, stepper_positions):
pos = [rail.get_tag_position() for rail in self.rails] pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [0.5 * (pos[0] + pos[2]), pos[1], 0.5 * (pos[0] - pos[2])] return [0.5 * (pos[0] + pos[2]), pos[1], 0.5 * (pos[0] - pos[2])]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails): for i, rail in enumerate(self.rails):

View File

@ -92,8 +92,8 @@ class DeltaKinematics:
def _actuator_to_cartesian(self, spos): def _actuator_to_cartesian(self, spos):
sphere_coords = [(t[0], t[1], sp) for t, sp in zip(self.towers, spos)] sphere_coords = [(t[0], t[1], sp) for t, sp in zip(self.towers, spos)]
return mathutil.trilateration(sphere_coords, self.arm2) return mathutil.trilateration(sphere_coords, self.arm2)
def calc_tag_position(self): def calc_position(self, stepper_positions):
spos = [rail.get_tag_position() for rail in self.rails] spos = [stepper_positions[rail.get_name()] for rail in self.rails]
return self._actuator_to_cartesian(spos) return self._actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for rail in self.rails: for rail in self.rails:

View File

@ -37,8 +37,8 @@ class HybridCoreXYKinematics:
self.limits = [(1.0, -1.0)] * 3 self.limits = [(1.0, -1.0)] * 3
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_tag_position(self): def calc_position(self, stepper_positions):
pos = [rail.get_tag_position() for rail in self.rails] pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [pos[0] + pos[1], pos[1], pos[2]] return [pos[0] + pos[1], pos[1], pos[2]]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails): for i, rail in enumerate(self.rails):

View File

@ -37,8 +37,8 @@ class HybridCoreXZKinematics:
self.limits = [(1.0, -1.0)] * 3 self.limits = [(1.0, -1.0)] * 3
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_tag_position(self): def calc_position(self, stepper_positions):
pos = [rail.get_tag_position() for rail in self.rails] pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [pos[0] + pos[2], pos[1], pos[2]] return [pos[0] + pos[2], pos[1], pos[2]]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails): for i, rail in enumerate(self.rails):

View File

@ -9,7 +9,7 @@ class NoneKinematics:
self.axes_minmax = toolhead.Coord(0., 0., 0., 0.) self.axes_minmax = toolhead.Coord(0., 0., 0., 0.)
def get_steppers(self): def get_steppers(self):
return [] return []
def calc_tag_position(self): def calc_position(self, stepper_positions):
return [0, 0, 0] return [0, 0, 0]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
pass pass

View File

@ -38,10 +38,10 @@ class PolarKinematics:
self.axes_max = toolhead.Coord(max_xy, max_xy, max_z, 0.) self.axes_max = toolhead.Coord(max_xy, max_xy, max_z, 0.)
def get_steppers(self): def get_steppers(self):
return list(self.steppers) return list(self.steppers)
def calc_tag_position(self): def calc_position(self, stepper_positions):
bed_angle = self.steppers[0].get_tag_position() bed_angle = stepper_positions[self.steppers[0].get_name()]
arm_pos = self.rails[0].get_tag_position() arm_pos = stepper_positions[self.rails[0].get_name()]
z_pos = self.rails[1].get_tag_position() z_pos = stepper_positions[self.rails[1].get_name()]
return [math.cos(bed_angle) * arm_pos, math.sin(bed_angle) * arm_pos, return [math.cos(bed_angle) * arm_pos, math.sin(bed_angle) * arm_pos,
z_pos] z_pos]
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):

View File

@ -79,8 +79,8 @@ class RotaryDeltaKinematics:
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()]
def calc_tag_position(self): def calc_position(self, stepper_positions):
spos = [rail.get_tag_position() for rail in self.rails] spos = [stepper_positions[rail.get_name()] for rail in self.rails]
return self.calibration.actuator_to_cartesian(spos) return self.calibration.actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for rail in self.rails: for rail in self.rails:

View File

@ -29,10 +29,10 @@ class WinchKinematics:
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)
def calc_tag_position(self): def calc_position(self, stepper_positions):
# Use only first three steppers to calculate cartesian position # Use only first three steppers to calculate cartesian position
spos = [s.get_tag_position() for s in self.steppers[:3]] pos = [stepper_positions[rail.get_name()] for rail in self.steppers[:3]]
return mathutil.trilateration(self.anchors[:3], [sp*sp for sp in spos]) return mathutil.trilateration(self.anchors[:3], [sp*sp for sp in pos])
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
for s in self.steppers: for s in self.steppers:
s.set_position(newpos) s.set_position(newpos)

View File

@ -31,7 +31,7 @@ class MCU_stepper:
"Stepper dir pin must be on same mcu as step pin") "Stepper dir pin must be on same mcu as step pin")
self._dir_pin = dir_pin_params['pin'] self._dir_pin = dir_pin_params['pin']
self._invert_dir = dir_pin_params['invert'] self._invert_dir = dir_pin_params['invert']
self._mcu_position_offset = self._tag_position = 0. self._mcu_position_offset = 0.
self._reset_cmd_tag = self._get_position_cmd = None self._reset_cmd_tag = self._get_position_cmd = None
self._active_callbacks = [] self._active_callbacks = []
ffi_main, ffi_lib = chelper.get_ffi() ffi_main, ffi_lib = chelper.get_ffi()
@ -108,10 +108,6 @@ class MCU_stepper:
if mcu_pos >= 0.: if mcu_pos >= 0.:
return int(mcu_pos + 0.5) return int(mcu_pos + 0.5)
return int(mcu_pos - 0.5) return int(mcu_pos - 0.5)
def get_tag_position(self):
return self._tag_position
def set_tag_position(self, position):
self._tag_position = position
def get_past_mcu_position(self, print_time): def get_past_mcu_position(self, print_time):
clock = self._mcu.print_time_to_clock(print_time) clock = self._mcu.print_time_to_clock(print_time)
ffi_main, ffi_lib = chelper.get_ffi() ffi_main, ffi_lib = chelper.get_ffi()
@ -258,9 +254,8 @@ class PrinterRail:
self.endstops = [] self.endstops = []
self.add_extra_stepper(config) self.add_extra_stepper(config)
mcu_stepper = self.steppers[0] mcu_stepper = self.steppers[0]
self.get_name = mcu_stepper.get_name
self.get_commanded_position = mcu_stepper.get_commanded_position self.get_commanded_position = mcu_stepper.get_commanded_position
self.get_tag_position = mcu_stepper.get_tag_position
self.set_tag_position = mcu_stepper.set_tag_position
self.calc_position_from_coord = mcu_stepper.calc_position_from_coord self.calc_position_from_coord = mcu_stepper.calc_position_from_coord
# Primary endstop position # Primary endstop position
mcu_endstop = self.endstops[0][0] mcu_endstop = self.endstops[0][0]