andrewmcgr / klipper_tmc_autotune

TMC stepper driver autotuning Klipper python extra

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom motor_constants need to be defined ahead of autotune_tmc" in config

Turge08 opened this issue · comments

If a custom motor constant is defined after the "autotune_tmc" entry in the config, Klipper will throw an error similar to:

"Could not find motor definition '[motor_constants xxxxxxxxxxxxx]' required by TMC autotuning. It is not part of the database, please define it in your config!"

CAUSE: During the "init" part of the tmc_autotune component, it tries to locate the motor definition which hasn't been loaded yet.

RESOLUTION: I haven't done extensive testing with it, but moving the following 2 sections of code from "init" to "handle_ready" appears to work for me.

        try:
            motor = self.printer.lookup_object(self.motor_name)
        except Exception:
            raise config.error(
                "Could not find motor definition '[%s]' required by TMC autotuning. "
                "It is not part of the database, please define it in your config!"
                % (self.motor_name))
        if self.tuning_goal == TuningGoal.AUTO:
            # Very small motors may not run in silent mode.
            self.auto_silent = self.name not in AUTO_PERFORMANCE_MOTORS and motor.T > 0.3
            self.tuning_goal = TuningGoal.SILENT if self.auto_silent else TuningGoal.PERFORMANCE
    def handle_ready(self):
        if self.tmc_init_registers is not None:
            self.tmc_init_registers(print_time=print_time)
        self.fclk = self.tmc_object.mcu_tmc.get_tmc_frequency()
        if self.fclk is None:
            self.fclk = 12.5e6
        try:
            motor = self.printer.lookup_object(self.motor_name)
        except Exception:
            raise config.error(
                "Could not find motor definition '[%s]' required by TMC autotuning. "
                "It is not part of the database, please define it in your config!"
                % (self.motor_name))
        if self.tuning_goal == TuningGoal.AUTO:
            # Very small motors may not run in silent mode.
            self.auto_silent = self.name not in AUTO_PERFORMANCE_MOTORS and motor.T > 0.3
            self.tuning_goal = TuningGoal.SILENT if self.auto_silent else TuningGoal.PERFORMANCE


        self.tune_driver()