diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-01-05 20:19:43 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-12-18 10:30:32 -0500 |
commit | 7dcc778b6c25a4956cbf0180423eeb3e450e1243 (patch) | |
tree | c66610b89967662f335c36a6a770038d3bfa1a0c /klippy/extras/tmc.py | |
parent | 4a41d228eb8e486919587c9f7e4f79c934572529 (diff) | |
download | kutter-7dcc778b6c25a4956cbf0180423eeb3e450e1243.tar.gz kutter-7dcc778b6c25a4956cbf0180423eeb3e450e1243.tar.xz kutter-7dcc778b6c25a4956cbf0180423eeb3e450e1243.zip |
stepper: Calculate step_distance from rotation_distance
Add support for automatically calculating the internal step_distance
from new config parameters - rotation_distance, microsteps,
full_steps_per_rotation, and gear_ratio.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/tmc.py')
-rw-r--r-- | klippy/extras/tmc.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py index 7b9280dd..c14a5f0f 100644 --- a/klippy/extras/tmc.py +++ b/klippy/extras/tmc.py @@ -1,9 +1,10 @@ # Common helper code for TMC stepper drivers # -# Copyright (C) 2018-2019 Kevin O'Connor <kevin@koconnor.net> +# Copyright (C) 2018-2020 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. import logging, collections +import stepper ###################################################################### @@ -263,9 +264,14 @@ class TMCMicrostepHelper: def __init__(self, config, mcu_tmc): self.mcu_tmc = mcu_tmc self.fields = mcu_tmc.get_fields() + stepper_name = " ".join(config.get_name().split()[1:]) + stepper_config = ms_config = config.getsection(stepper_name) + if stepper_config.get('microsteps', None, note_valid=False) is None: + # Older config format with microsteps in tmc config section + ms_config = config steps = {'256': 0, '128': 1, '64': 2, '32': 3, '16': 4, '8': 5, '4': 6, '2': 7, '1': 8} - mres = config.getchoice('microsteps', steps) + mres = ms_config.getchoice('microsteps', steps) self.fields.set_field("MRES", mres) self.fields.set_field("intpol", config.getboolean("interpolate", True)) def get_microsteps(self): @@ -287,7 +293,7 @@ def TMCStealthchopHelper(config, mcu_tmc, tmc_freq): if velocity: stepper_name = " ".join(config.get_name().split()[1:]) stepper_config = config.getsection(stepper_name) - step_dist = stepper_config.getfloat('step_distance', note_valid=False) + step_dist = stepper.parse_step_distance(stepper_config) step_dist_256 = step_dist / (1 << fields.get_field("MRES")) threshold = int(tmc_freq * step_dist_256 / velocity + .5) fields.set_field("TPWMTHRS", max(0, min(0xfffff, threshold))) |