extruder: Add a SET_EXTRUDER_ROTATION_DISTANCE command

Support altering the extruder distance using the higher-level
rotation_distance.  This is in preparation for removal of the
SET_EXTRUDER_STEP_DISTANCE command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-01-29 14:13:26 -05:00
parent 6d7c03365a
commit 189188e3ca
5 changed files with 55 additions and 23 deletions

View file

@ -18,12 +18,15 @@ MIN_BOTH_EDGE_DURATION = 0.000000200
# 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,
rotation_dist, steps_per_rotation,
step_pulse_duration=None, units_in_radians=False):
self._name = name
self._step_dist = step_dist
self._rotation_dist = rotation_dist
self._steps_per_rotation = steps_per_rotation
self._step_pulse_duration = step_pulse_duration
self._units_in_radians = units_in_radians
self._step_dist = rotation_dist / steps_per_rotation
self._mcu = step_pin_params['chip']
self._oid = oid = self._mcu.create_oid()
self._mcu.register_config_callback(self._build_config)
@ -103,9 +106,12 @@ class MCU_stepper:
return self._oid
def get_step_dist(self):
return self._step_dist
def set_step_dist(self, dist):
def get_rotation_distance(self):
return self._rotation_dist, self._steps_per_rotation
def set_rotation_distance(self, rotation_dist):
mcu_pos = self.get_mcu_position()
self._step_dist = dist
self._rotation_dist = rotation_dist
self._step_dist = rotation_dist / self._steps_per_rotation
self.set_stepper_kinematics(self._stepper_kinematics)
self._set_mcu_position(mcu_pos)
def is_dir_inverted(self):
@ -222,10 +228,12 @@ def PrinterStepper(config, units_in_radians=False):
step_pin_params = ppins.lookup_pin(step_pin, can_invert=True)
dir_pin = config.get('dir_pin')
dir_pin_params = ppins.lookup_pin(dir_pin, can_invert=True)
step_dist = parse_step_distance(config, units_in_radians, True)
rotation_dist, steps_per_rotation = parse_step_distance(
config, units_in_radians, True)
step_pulse_duration = config.getfloat('step_pulse_duration', None,
minval=0., maxval=.001)
mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params, step_dist,
mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params,
rotation_dist, steps_per_rotation,
step_pulse_duration, units_in_radians)
# Register with helper modules
for mname in ['stepper_enable', 'force_move', 'motion_report']:
@ -263,7 +271,7 @@ def parse_step_distance(config, units_in_radians=None, note_valid=False):
raise config.error("full_steps_per_rotation invalid in section '%s'"
% (config.get_name(),))
gearing = parse_gear_ratio(config, note_valid)
return rotation_dist / (full_steps * microsteps * gearing)
return rotation_dist, full_steps * microsteps * gearing
######################################################################