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
calculate the desired stepper position (in millimeters) from that
cartesian coordinate.
4. Implement the `calc_tag_position()` method in the new kinematics
class. This method calculates the position of the toolhead in
cartesian coordinates from the position of each stepper (as
returned by `stepper.get_tag_position()`). It does not need to be
efficient as it is typically only called during homing and probing
operations.
4. Implement the `calc_position()` method in the new kinematics class.
This method calculates the position of the toolhead in cartesian
coordinates from the position of each stepper. It does not need to
be efficient as it is typically only called during homing and
probing operations.
5. Other methods. Implement the `check_move()`, `get_status()`,
`get_steppers()`, `home()`, and `set_position()` methods. These
functions are typically used to provide kinematic specific checks.

View File

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

View File

@ -102,17 +102,16 @@ class EndstopPhase:
self.name, phase, self.endstop_phase))
return delta * self.step_dist
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:
stepper = rail.get_steppers()[0]
if stepper.get_name() != self.name:
continue
orig_pos = rail.get_tag_position()
offset = self.get_homed_offset(stepper)
pos = self.align_endstop(orig_pos) + offset
if pos == orig_pos:
return False
rail.set_tag_position(pos)
return True
if stepper.get_name() == self.name:
offset = self.get_homed_offset(stepper)
kin_spos[self.name] = self.align_endstop(orig_pos) + offset
return
class EndstopPhases:
def __init__(self, config):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,8 +37,8 @@ class HybridCoreXYKinematics:
self.limits = [(1.0, -1.0)] * 3
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def calc_tag_position(self):
pos = [rail.get_tag_position() for rail in self.rails]
def calc_position(self, stepper_positions):
pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [pos[0] + pos[1], pos[1], pos[2]]
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):

View File

@ -37,8 +37,8 @@ class HybridCoreXZKinematics:
self.limits = [(1.0, -1.0)] * 3
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def calc_tag_position(self):
pos = [rail.get_tag_position() for rail in self.rails]
def calc_position(self, stepper_positions):
pos = [stepper_positions[rail.get_name()] for rail in self.rails]
return [pos[0] + pos[2], pos[1], pos[2]]
def set_position(self, newpos, homing_axes):
for i, rail in enumerate(self.rails):

View File

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

View File

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

View File

@ -79,8 +79,8 @@ class RotaryDeltaKinematics:
self.set_position([0., 0., 0.], ())
def get_steppers(self):
return [s for rail in self.rails for s in rail.get_steppers()]
def calc_tag_position(self):
spos = [rail.get_tag_position() for rail in self.rails]
def calc_position(self, stepper_positions):
spos = [stepper_positions[rail.get_name()] for rail in self.rails]
return self.calibration.actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes):
for rail in self.rails:

View File

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

View File

@ -31,7 +31,7 @@ class MCU_stepper:
"Stepper dir pin must be on same mcu as step pin")
self._dir_pin = dir_pin_params['pin']
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._active_callbacks = []
ffi_main, ffi_lib = chelper.get_ffi()
@ -108,10 +108,6 @@ class MCU_stepper:
if mcu_pos >= 0.:
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):
clock = self._mcu.print_time_to_clock(print_time)
ffi_main, ffi_lib = chelper.get_ffi()
@ -258,9 +254,8 @@ class PrinterRail:
self.endstops = []
self.add_extra_stepper(config)
mcu_stepper = self.steppers[0]
self.get_name = mcu_stepper.get_name
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
# Primary endstop position
mcu_endstop = self.endstops[0][0]