mirror of https://github.com/Desuuuu/klipper.git
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:
parent
eecf3b6ea8
commit
38643f52c9
|
@ -28,7 +28,7 @@ class CartKinematics:
|
||||||
min(max_halt_velocity, self.max_z_velocity), max_accel)
|
min(max_halt_velocity, self.max_z_velocity), max_accel)
|
||||||
def set_position(self, newpos):
|
def set_position(self, newpos):
|
||||||
for i in StepList:
|
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):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
|
|
|
@ -32,7 +32,7 @@ class CoreXYKinematics:
|
||||||
def set_position(self, newpos):
|
def set_position(self, newpos):
|
||||||
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
|
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
|
||||||
for i in StepList:
|
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):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
|
|
|
@ -97,7 +97,7 @@ class DeltaKinematics:
|
||||||
def set_position(self, newpos):
|
def set_position(self, newpos):
|
||||||
pos = self._cartesian_to_actuator(newpos)
|
pos = self._cartesian_to_actuator(newpos)
|
||||||
for i in StepList:
|
for i in StepList:
|
||||||
self.steppers[i].mcu_stepper.set_position(pos[i])
|
self.steppers[i].set_position(pos[i])
|
||||||
self.limit_xy2 = -1.
|
self.limit_xy2 = -1.
|
||||||
def home(self, homing_state):
|
def home(self, homing_state):
|
||||||
# All axes are homed simultaneously
|
# All axes are homed simultaneously
|
||||||
|
|
|
@ -38,41 +38,47 @@ class Homing:
|
||||||
print_time = self.toolhead.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
endstops = []
|
endstops = []
|
||||||
for s in steppers:
|
for s in steppers:
|
||||||
s.mcu_endstop.home_start(print_time, ENDSTOP_SAMPLE_TIME,
|
for mcu_endstop, mcu_stepper, name in s.get_endstops():
|
||||||
ENDSTOP_SAMPLE_COUNT, s.step_dist / speed)
|
mcu_endstop.home_start(
|
||||||
endstops.append((s, s.mcu_stepper.get_mcu_position()))
|
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)
|
self.toolhead.move(self._fill_coord(movepos), speed)
|
||||||
move_end_print_time = self.toolhead.get_last_move_time()
|
move_end_print_time = self.toolhead.get_last_move_time()
|
||||||
self.toolhead.reset_print_time(print_time)
|
self.toolhead.reset_print_time(print_time)
|
||||||
for s, last_pos in endstops:
|
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
|
||||||
s.mcu_endstop.home_finalize(move_end_print_time)
|
mcu_endstop.home_finalize(move_end_print_time)
|
||||||
# Wait for endstops to trigger
|
# Wait for endstops to trigger
|
||||||
for s, last_pos in endstops:
|
for mcu_endstop, mcu_stepper, name, last_pos in endstops:
|
||||||
try:
|
try:
|
||||||
s.mcu_endstop.home_wait()
|
mcu_endstop.home_wait()
|
||||||
except s.mcu_endstop.error as e:
|
except mcu_endstop.error as e:
|
||||||
raise EndstopError("Failed to home stepper %s: %s" % (
|
raise EndstopError("Failed to home stepper %s: %s" % (
|
||||||
s.name, str(e)))
|
name, str(e)))
|
||||||
post_home_pos = s.mcu_stepper.get_mcu_position()
|
post_home_pos = mcu_stepper.get_mcu_position()
|
||||||
if second_home and self.verify_retract and last_pos == post_home_pos:
|
if second_home and self.verify_retract and last_pos == post_home_pos:
|
||||||
raise EndstopError("Endstop %s still triggered after retract" % (
|
raise EndstopError("Endstop %s still triggered after retract" % (
|
||||||
s.name,))
|
name,))
|
||||||
def set_homed_position(self, pos):
|
def set_homed_position(self, pos):
|
||||||
self.toolhead.set_position(self._fill_coord(pos))
|
self.toolhead.set_position(self._fill_coord(pos))
|
||||||
|
|
||||||
def query_endstops(print_time, query_flags, steppers):
|
def query_endstops(print_time, query_flags, steppers):
|
||||||
if query_flags == "get_mcu_position":
|
if query_flags == "get_mcu_position":
|
||||||
# Only the commanded position is requested
|
# Only the commanded position is requested
|
||||||
return [(s.name.upper(), s.mcu_stepper.get_mcu_position())
|
return [(name.upper(), mcu_stepper.get_mcu_position())
|
||||||
for s in steppers]
|
for s in steppers
|
||||||
|
for mcu_endstop, mcu_stepper, name in s.get_endstops()]
|
||||||
for s in steppers:
|
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 = []
|
out = []
|
||||||
for s in steppers:
|
for s in steppers:
|
||||||
try:
|
for mcu_endstop, mcu_stepper, name in s.get_endstops():
|
||||||
out.append((s.name, s.mcu_endstop.query_endstop_wait()))
|
try:
|
||||||
except s.mcu_endstop.error as e:
|
out.append((name, mcu_endstop.query_endstop_wait()))
|
||||||
raise EndstopError(str(e))
|
except mcu_endstop.error as e:
|
||||||
|
raise EndstopError(str(e))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
class EndstopError(Exception):
|
class EndstopError(Exception):
|
||||||
|
|
|
@ -61,6 +61,8 @@ class MCU_stepper:
|
||||||
self._mcu.register_stepqueue(self._stepqueue)
|
self._mcu.register_stepqueue(self._stepqueue)
|
||||||
def get_oid(self):
|
def get_oid(self):
|
||||||
return self._oid
|
return self._oid
|
||||||
|
def get_step_dist(self):
|
||||||
|
return self._step_dist
|
||||||
def set_position(self, pos):
|
def set_position(self, pos):
|
||||||
if pos >= 0.:
|
if pos >= 0.:
|
||||||
steppos = int(pos * self._inv_step_dist + 0.5)
|
steppos = int(pos * self._inv_step_dist + 0.5)
|
||||||
|
|
|
@ -41,6 +41,8 @@ class PrinterStepper:
|
||||||
2. * self.step_dist, max_halt_velocity, max_accel)
|
2. * self.step_dist, max_halt_velocity, max_accel)
|
||||||
min_stop_interval = second_last_step_time - last_step_time
|
min_stop_interval = second_last_step_time - last_step_time
|
||||||
self.mcu_stepper.setup_min_stop_interval(min_stop_interval)
|
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):
|
def motor_enable(self, print_time, enable=0):
|
||||||
if enable and self.need_motor_enable:
|
if enable and self.need_motor_enable:
|
||||||
self.mcu_stepper.reset_step_clock(print_time)
|
self.mcu_stepper.reset_step_clock(print_time)
|
||||||
|
@ -115,6 +117,8 @@ class PrinterHomingStepper(PrinterStepper):
|
||||||
self.homing_stepper_phases = None
|
self.homing_stepper_phases = None
|
||||||
if self.mcu_endstop.get_mcu().is_fileoutput():
|
if self.mcu_endstop.get_mcu().is_fileoutput():
|
||||||
self.homing_endstop_accuracy = self.homing_stepper_phases
|
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):
|
def get_homing_speed(self):
|
||||||
# Round the configured homing speed so that it is an even
|
# Round the configured homing speed so that it is an even
|
||||||
# number of ticks per step.
|
# number of ticks per step.
|
||||||
|
|
Loading…
Reference in New Issue