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 [self.steppers[2]]
return list(self.steppers) return list(self.steppers)
def get_position(self): 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): def set_position(self, newpos, homing_axes):
for i in StepList: for i in StepList:
s = self.steppers[i] s = self.steppers[i]

View File

@ -14,8 +14,8 @@ class CoreXYKinematics:
stepper.PrinterHomingStepper(config.getsection('stepper_x')), stepper.PrinterHomingStepper(config.getsection('stepper_x')),
stepper.PrinterHomingStepper(config.getsection('stepper_y')), stepper.PrinterHomingStepper(config.getsection('stepper_y')),
stepper.LookupMultiHomingStepper(config.getsection('stepper_z'))] stepper.LookupMultiHomingStepper(config.getsection('stepper_z'))]
self.steppers[0].mcu_endstop.add_stepper(self.steppers[1].mcu_stepper) self.steppers[0].add_to_endstop(self.steppers[1].get_endstops()[0][0])
self.steppers[1].mcu_endstop.add_stepper(self.steppers[0].mcu_stepper) self.steppers[1].add_to_endstop(self.steppers[0].get_endstops()[0][0])
max_velocity, max_accel = toolhead.get_max_velocity() max_velocity, max_accel = toolhead.get_max_velocity()
self.max_z_velocity = config.getfloat( self.max_z_velocity = config.getfloat(
'max_z_velocity', max_velocity, above=0., maxval=max_velocity) 'max_z_velocity', max_velocity, above=0., maxval=max_velocity)
@ -44,7 +44,7 @@ class CoreXYKinematics:
return [self.steppers[2]] return [self.steppers[2]]
return list(self.steppers) return list(self.steppers)
def get_position(self): 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]] 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):
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2]) 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): def _actuator_to_cartesian(self, pos):
return actuator_to_cartesian(self.towers, self.arm2, pos) return actuator_to_cartesian(self.towers, self.arm2, pos)
def get_position(self): 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) return self._actuator_to_cartesian(spos)
def set_position(self, newpos, homing_axes): def set_position(self, newpos, homing_axes):
pos = self._cartesian_to_actuator(newpos) pos = self._cartesian_to_actuator(newpos)
@ -172,9 +172,8 @@ class DeltaKinematics:
stepper.step_itersolve(self.cmove) stepper.step_itersolve(self.cmove)
# Helper functions for DELTA_CALIBRATE script # Helper functions for DELTA_CALIBRATE script
def get_stable_position(self): def get_stable_position(self):
return [int((ep - s.mcu_stepper.get_commanded_position()) return [int((ep - s.get_commanded_position()) / s.get_step_dist() + .5)
/ s.mcu_stepper.get_step_dist() + .5) * s.get_step_dist()
* s.mcu_stepper.get_step_dist()
for ep, s in zip(self.endstops, self.steppers)] for ep, s in zip(self.endstops, self.steppers)]
def get_calibrate_params(self): def get_calibrate_params(self):
return { return {

View File

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

View File

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

View File

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

View File

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