stepper: Add get_endstops() / set_position wrappers

Add wrappers around mcu_endstop and mcu_stepper so that the kinematic
classes do not need to directly access these low-level classes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-11-07 12:29:51 -05:00
parent eecf3b6ea8
commit 38643f52c9
6 changed files with 33 additions and 21 deletions

View File

@ -28,7 +28,7 @@ class CartKinematics:
min(max_halt_velocity, self.max_z_velocity), max_accel)
def set_position(self, newpos):
for i in StepList:
self.steppers[i].mcu_stepper.set_position(newpos[i])
self.steppers[i].set_position(newpos[i])
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():

View File

@ -32,7 +32,7 @@ class CoreXYKinematics:
def set_position(self, newpos):
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
for i in StepList:
self.steppers[i].mcu_stepper.set_position(pos[i])
self.steppers[i].set_position(pos[i])
def home(self, homing_state):
# Each axis is homed independently and in order
for axis in homing_state.get_axes():

View File

@ -97,7 +97,7 @@ class DeltaKinematics:
def set_position(self, newpos):
pos = self._cartesian_to_actuator(newpos)
for i in StepList:
self.steppers[i].mcu_stepper.set_position(pos[i])
self.steppers[i].set_position(pos[i])
self.limit_xy2 = -1.
def home(self, homing_state):
# All axes are homed simultaneously

View File

@ -38,40 +38,46 @@ class Homing:
print_time = self.toolhead.get_last_move_time()
endstops = []
for s in steppers:
s.mcu_endstop.home_start(print_time, ENDSTOP_SAMPLE_TIME,
ENDSTOP_SAMPLE_COUNT, s.step_dist / speed)
endstops.append((s, s.mcu_stepper.get_mcu_position()))
for mcu_endstop, mcu_stepper, name in s.get_endstops():
mcu_endstop.home_start(
print_time, ENDSTOP_SAMPLE_TIME, ENDSTOP_SAMPLE_COUNT,
mcu_stepper.get_step_dist() / speed)
endstops.append((mcu_endstop, mcu_stepper, name,
mcu_stepper.get_mcu_position()))
self.toolhead.move(self._fill_coord(movepos), speed)
move_end_print_time = self.toolhead.get_last_move_time()
self.toolhead.reset_print_time(print_time)
for s, last_pos in endstops:
s.mcu_endstop.home_finalize(move_end_print_time)
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
mcu_endstop.home_finalize(move_end_print_time)
# Wait for endstops to trigger
for s, last_pos in endstops:
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
try:
s.mcu_endstop.home_wait()
except s.mcu_endstop.error as e:
mcu_endstop.home_wait()
except mcu_endstop.error as e:
raise EndstopError("Failed to home stepper %s: %s" % (
s.name, str(e)))
post_home_pos = s.mcu_stepper.get_mcu_position()
name, str(e)))
post_home_pos = mcu_stepper.get_mcu_position()
if second_home and self.verify_retract and last_pos == post_home_pos:
raise EndstopError("Endstop %s still triggered after retract" % (
s.name,))
name,))
def set_homed_position(self, pos):
self.toolhead.set_position(self._fill_coord(pos))
def query_endstops(print_time, query_flags, steppers):
if query_flags == "get_mcu_position":
# Only the commanded position is requested
return [(s.name.upper(), s.mcu_stepper.get_mcu_position())
for s in steppers]
return [(name.upper(), mcu_stepper.get_mcu_position())
for s in steppers
for mcu_endstop, mcu_stepper, name in s.get_endstops()]
for s in steppers:
s.mcu_endstop.query_endstop(print_time)
for mcu_endstop, mcu_stepper, name in s.get_endstops():
mcu_endstop.query_endstop(print_time)
out = []
for s in steppers:
for mcu_endstop, mcu_stepper, name in s.get_endstops():
try:
out.append((s.name, s.mcu_endstop.query_endstop_wait()))
except s.mcu_endstop.error as e:
out.append((name, mcu_endstop.query_endstop_wait()))
except mcu_endstop.error as e:
raise EndstopError(str(e))
return out

View File

@ -61,6 +61,8 @@ class MCU_stepper:
self._mcu.register_stepqueue(self._stepqueue)
def get_oid(self):
return self._oid
def get_step_dist(self):
return self._step_dist
def set_position(self, pos):
if pos >= 0.:
steppos = int(pos * self._inv_step_dist + 0.5)

View File

@ -41,6 +41,8 @@ class PrinterStepper:
2. * self.step_dist, max_halt_velocity, max_accel)
min_stop_interval = second_last_step_time - last_step_time
self.mcu_stepper.setup_min_stop_interval(min_stop_interval)
def set_position(self, pos):
self.mcu_stepper.set_position(pos)
def motor_enable(self, print_time, enable=0):
if enable and self.need_motor_enable:
self.mcu_stepper.reset_step_clock(print_time)
@ -115,6 +117,8 @@ class PrinterHomingStepper(PrinterStepper):
self.homing_stepper_phases = None
if self.mcu_endstop.get_mcu().is_fileoutput():
self.homing_endstop_accuracy = self.homing_stepper_phases
def get_endstops(self):
return [(self.mcu_endstop, self.mcu_stepper, self.name)]
def get_homing_speed(self):
# Round the configured homing speed so that it is an even
# number of ticks per step.