stepper: Don't peak into PrinterStepper members

Add additional wrapper functions so that no outside callers need to
peak into the member variables of PrinterStepper.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-06-21 18:15:23 -04:00
parent 9a97a348ae
commit b96542f0e5
7 changed files with 26 additions and 24 deletions

View File

@ -53,7 +53,7 @@ class CartKinematics:
return [self.steppers[2]]
return list(self.steppers)
def get_position(self):
return [s.mcu_stepper.get_commanded_position() for s in self.steppers]
return [s.get_commanded_position() for s in self.steppers]
def set_position(self, newpos, homing_axes):
for i in StepList:
s = self.steppers[i]

View File

@ -14,8 +14,8 @@ class CoreXYKinematics:
stepper.PrinterHomingStepper(config.getsection('stepper_x')),
stepper.PrinterHomingStepper(config.getsection('stepper_y')),
stepper.LookupMultiHomingStepper(config.getsection('stepper_z'))]
self.steppers[0].mcu_endstop.add_stepper(self.steppers[1].mcu_stepper)
self.steppers[1].mcu_endstop.add_stepper(self.steppers[0].mcu_stepper)
self.steppers[0].add_to_endstop(self.steppers[1].get_endstops()[0][0])
self.steppers[1].add_to_endstop(self.steppers[0].get_endstops()[0][0])
max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat(
'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
@ -44,7 +44,7 @@ class CoreXYKinematics:
return [self.steppers[2]]
return list(self.steppers)
def get_position(self):
pos = [s.mcu_stepper.get_commanded_position() for s in self.steppers]
pos = [s.get_commanded_position() for s in self.steppers]
return [0.5 * (pos[0] + pos[1]), 0.5 * (pos[0] - pos[1]), pos[2]]
def set_position(self, newpos, homing_axes):
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])

View File

@ -90,7 +90,7 @@ class DeltaKinematics:
def _actuator_to_cartesian(self, pos):
return actuator_to_cartesian(self.towers, self.arm2, pos)
def get_position(self):
spos = [s.mcu_stepper.get_commanded_position() for s in self.steppers]
spos = [s.get_commanded_position() for s in self.steppers]
return self._actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes):
pos = self._cartesian_to_actuator(newpos)
@ -172,9 +172,8 @@ class DeltaKinematics:
stepper.step_itersolve(self.cmove)
# Helper functions for DELTA_CALIBRATE script
def get_stable_position(self):
return [int((ep - s.mcu_stepper.get_commanded_position())
/ s.mcu_stepper.get_step_dist() + .5)
* s.mcu_stepper.get_step_dist()
return [int((ep - s.get_commanded_position()) / s.get_step_dist() + .5)
* s.get_step_dist()
for ep, s in zip(self.endstops, self.steppers)]
def get_calibrate_params(self):
return {

View File

@ -39,21 +39,21 @@ class StepperBuzz:
# Move stepper
toolhead = self.printer.lookup_object('toolhead')
toolhead.wait_moves()
pos = stepper.mcu_stepper.get_commanded_position()
pos = stepper.get_commanded_position()
print_time = toolhead.get_last_move_time()
if need_motor_enable:
stepper.motor_enable(print_time, 1)
print_time += .1
was_ignore = stepper.mcu_stepper.set_ignore_move(False)
prev_sk = stepper.mcu_stepper.setup_itersolve(self.stepper_kinematics)
was_ignore = stepper.set_ignore_move(False)
prev_sk = stepper.setup_itersolve(self.stepper_kinematics)
for i in range(10):
self.manual_move(print_time, stepper, 0., 1.)
print_time += .3
self.manual_move(print_time, stepper, 1., -1.)
toolhead.reset_print_time(print_time + .7)
print_time = toolhead.get_last_move_time()
stepper.mcu_stepper.setup_itersolve(prev_sk)
stepper.mcu_stepper.set_ignore_move(was_ignore)
stepper.setup_itersolve(prev_sk)
stepper.set_ignore_move(was_ignore)
if need_motor_enable:
print_time += .1
stepper.motor_enable(print_time, 0)

View File

@ -69,7 +69,7 @@ class ZTilt:
except:
logging.exception("z_tilt adjust_steppers")
for s in self.z_steppers:
z.mcu_stepper.set_ignore_move(False)
z.set_ignore_move(False)
raise
def adjust_steppers(self, x_adjust, y_adjust, z_adjust, z_offset):
toolhead = self.printer.lookup_object('toolhead')
@ -78,7 +78,7 @@ class ZTilt:
# Find each stepper adjustment and disable all stepper movements
positions = []
for s, (x, y) in zip(self.z_steppers, self.z_positions):
s.mcu_stepper.set_ignore_move(True)
s.set_ignore_move(True)
stepper_offset = -(x*x_adjust + y*y_adjust)
positions.append((stepper_offset, s))
# Report on movements
@ -94,13 +94,13 @@ class ZTilt:
for i in range(len(positions)-1):
stepper_offset, stepper = positions[i]
next_stepper_offset, next_stepper = positions[i+1]
stepper.mcu_stepper.set_ignore_move(False)
stepper.set_ignore_move(False)
curpos[2] = z_low + next_stepper_offset
toolhead.move(curpos, speed)
toolhead.set_position(curpos)
# Z should now be level - do final cleanup
last_stepper_offset, last_stepper = positions[-1]
last_stepper.mcu_stepper.set_ignore_move(False)
last_stepper.set_ignore_move(False)
curpos[2] -= z_adjust - z_offset
toolhead.set_position(curpos)
self.gcode.reset_last_position()

View File

@ -599,11 +599,10 @@ class GCodeParser:
return
kin = self.toolhead.get_kinematics()
steppers = kin.get_steppers()
mcu_pos = " ".join(["%s:%d" % (s.get_name(),
s.mcu_stepper.get_mcu_position())
mcu_pos = " ".join(["%s:%d" % (s.get_name(), s.get_mcu_position())
for s in steppers])
stepper_pos = " ".join(
["%s:%.6f" % (s.get_name(), s.mcu_stepper.get_commanded_position())
["%s:%.6f" % (s.get_name(), s.get_commanded_position())
for s in steppers])
kinematic_pos = " ".join(["%s:%.6f" % (a, v)
for a, v in zip("XYZE", kin.get_position())])

View File

@ -52,11 +52,16 @@ class PrinterStepper:
# Wrappers
self.step_itersolve = self.mcu_stepper.step_itersolve
self.setup_itersolve = self.mcu_stepper.setup_itersolve
self.set_ignore_move = self.mcu_stepper.set_ignore_move
self.get_mcu_position = self.mcu_stepper.get_mcu_position
self.get_commanded_position = self.mcu_stepper.get_commanded_position
self.get_step_dist = self.mcu_stepper.get_step_dist
def get_name(self, short=False):
if short and self.name.startswith('stepper_'):
return self.name[8:]
return self.name
def add_to_endstop(self, mcu_endstop):
mcu_endstop.add_stepper(self.mcu_stepper)
def _dist_to_time(self, dist, start_velocity, accel):
# Calculate the time it takes to travel a distance with constant accel
time_offset = start_velocity / accel
@ -87,7 +92,7 @@ class PrinterHomingStepper(PrinterStepper):
# Endstop and its position
ppins = config.get_printer().lookup_object('pins')
self.mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
self.mcu_endstop.add_stepper(self.mcu_stepper)
self.add_to_endstop(self.mcu_endstop)
if default_position_endstop is None:
self.position_endstop = config.getfloat('position_endstop')
else:
@ -200,14 +205,13 @@ class PrinterMultiStepper(PrinterHomingStepper):
extra = PrinterStepper(extraconfig)
self.extras.append(extra)
self.all_step_itersolve.append(extra.step_itersolve)
mcu_endstop = self.mcu_endstop
extraendstop = extraconfig.get('endstop_pin', None)
if extraendstop is not None:
ppins = config.get_printer().lookup_object('pins')
mcu_endstop = ppins.setup_pin('endstop', extraendstop)
mcu_endstop.add_stepper(extra.mcu_stepper)
self.endstops.append((mcu_endstop, extra.get_name(short=True)))
else:
self.mcu_endstop.add_stepper(extra.mcu_stepper)
extra.add_to_endstop(mcu_endstop)
self.step_itersolve = self.step_multi_itersolve
def step_multi_itersolve(self, cmove):
for step_itersolve in self.all_step_itersolve: