tmc: Query the stepper step_distance from the stepper object
Don't obtain the step_distance from the config, instead obtain step_distance from the instantiated stepper object. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
c36fe76d69
commit
67b2852249
|
@ -53,6 +53,10 @@ class ForceMove:
|
||||||
def register_stepper(self, stepper):
|
def register_stepper(self, stepper):
|
||||||
name = stepper.get_name()
|
name = stepper.get_name()
|
||||||
self.steppers[name] = stepper
|
self.steppers[name] = stepper
|
||||||
|
def lookup_stepper(self, name):
|
||||||
|
if name not in self.steppers:
|
||||||
|
raise self.printer.config_error("Unknown stepper %s" % (name,))
|
||||||
|
return self.steppers[name]
|
||||||
def force_enable(self, stepper):
|
def force_enable(self, stepper):
|
||||||
toolhead = self.printer.lookup_object('toolhead')
|
toolhead = self.printer.lookup_object('toolhead')
|
||||||
print_time = toolhead.get_last_move_time()
|
print_time = toolhead.get_last_move_time()
|
||||||
|
|
|
@ -274,17 +274,17 @@ class TMCMicrostepHelper:
|
||||||
return (1023 - mscnt) >> self.fields.get_field("MRES")
|
return (1023 - mscnt) >> self.fields.get_field("MRES")
|
||||||
|
|
||||||
# Helper to configure "stealthchop" mode
|
# Helper to configure "stealthchop" mode
|
||||||
def TMCStealthchopHelper(config, mcu_tmc, tmc_freq):
|
class TMCStealthchopHelper:
|
||||||
fields = mcu_tmc.get_fields()
|
def __init__(self, config, mcu_tmc, tmc_freq):
|
||||||
|
self.name = config.get_name()
|
||||||
|
self.fields = fields = mcu_tmc.get_fields()
|
||||||
|
self.tmc_freq = tmc_freq
|
||||||
|
printer = config.get_printer()
|
||||||
|
self.force_move = printer.try_load_module(config, "force_move")
|
||||||
en_pwm_mode = False
|
en_pwm_mode = False
|
||||||
velocity = config.getfloat('stealthchop_threshold', 0., minval=0.)
|
self.velocity = config.getfloat('stealthchop_threshold', 0., minval=0.)
|
||||||
if velocity:
|
if self.velocity:
|
||||||
stepper_name = " ".join(config.get_name().split()[1:])
|
printer.register_event_handler("connect", self.handle_connect)
|
||||||
stepper_config = config.getsection(stepper_name)
|
|
||||||
step_dist = stepper_config.getfloat('step_distance')
|
|
||||||
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)))
|
|
||||||
en_pwm_mode = True
|
en_pwm_mode = True
|
||||||
reg = fields.lookup_register("en_pwm_mode", None)
|
reg = fields.lookup_register("en_pwm_mode", None)
|
||||||
if reg is not None:
|
if reg is not None:
|
||||||
|
@ -292,3 +292,10 @@ def TMCStealthchopHelper(config, mcu_tmc, tmc_freq):
|
||||||
else:
|
else:
|
||||||
# TMC2208 uses en_spreadCycle
|
# TMC2208 uses en_spreadCycle
|
||||||
fields.set_field("en_spreadCycle", not en_pwm_mode)
|
fields.set_field("en_spreadCycle", not en_pwm_mode)
|
||||||
|
def handle_connect(self):
|
||||||
|
stepper_name = " ".join(self.name.split()[1:])
|
||||||
|
stepper = self.force_move.lookup_stepper(stepper_name)
|
||||||
|
step_dist = stepper.get_step_dist()
|
||||||
|
step_dist_256 = step_dist / (1 << fields.get_field("MRES"))
|
||||||
|
threshold = int(self.tmc_freq * step_dist_256 / self.velocity + .5)
|
||||||
|
self.fields.set_field("TPWMTHRS", max(0, min(0xfffff, threshold)))
|
||||||
|
|
Loading…
Reference in New Issue