stepper: Track if using units of radians instead of millimeters

The STEPPER_BUZZ command needs to know if the axis is using radians
instead of millimeters so that it can move a more appropriate
distance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-12-04 18:42:59 -05:00
parent bcf10aa990
commit 97d976fc53
3 changed files with 23 additions and 9 deletions

View file

@ -16,9 +16,11 @@ class error(Exception):
# Interface to low-level mcu and chelper code
class MCU_stepper:
def __init__(self, name, step_pin_params, dir_pin_params, step_dist):
def __init__(self, name, step_pin_params, dir_pin_params, step_dist,
units_in_radians=False):
self._name = name
self._step_dist = step_dist
self._units_in_radians = units_in_radians
self._mcu = step_pin_params['chip']
self._oid = oid = self._mcu.create_oid()
self._mcu.register_config_callback(self._build_config)
@ -47,6 +49,9 @@ class MCU_stepper:
if short and self._name.startswith('stepper_'):
return self._name[8:]
return self._name
def units_in_radians(self):
# Returns true if distances are in radians instead of millimeters
return self._units_in_radians
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
@ -159,7 +164,7 @@ class MCU_stepper:
raise error("Internal error in stepcompress")
# Helper code to build a stepper object from a config section
def PrinterStepper(config):
def PrinterStepper(config, units_in_radians=False):
printer = config.get_printer()
name = config.get_name()
# Stepper definition
@ -169,7 +174,8 @@ def PrinterStepper(config):
dir_pin = config.get('dir_pin')
dir_pin_params = ppins.lookup_pin(dir_pin, can_invert=True)
step_dist = config.getfloat('step_distance', above=0.)
mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params, step_dist)
mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params, step_dist,
units_in_radians)
# Support for stepper enable pin handling
stepper_enable = printer.try_load_module(config, 'stepper_enable')
stepper_enable.register_stepper(mcu_stepper, config.get('enable_pin', None))
@ -187,8 +193,9 @@ def PrinterStepper(config):
# endstops.
class PrinterRail:
def __init__(self, config, need_position_minmax=True,
default_position_endstop=None):
default_position_endstop=None, units_in_radians=False):
# Primary stepper and endstop
self.stepper_units_in_radians = units_in_radians
self.steppers = []
self.endstops = []
self.add_extra_stepper(config)
@ -250,7 +257,7 @@ class PrinterRail:
def get_endstops(self):
return list(self.endstops)
def add_extra_stepper(self, config):
stepper = PrinterStepper(config)
stepper = PrinterStepper(config, self.stepper_units_in_radians)
self.steppers.append(stepper)
if self.endstops and config.get('endstop_pin', None) is None:
# No endstop defined - use primary endstop