Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 23, 2024
2 parents 8922443 + 6224b77 commit ddb35cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
28 changes: 23 additions & 5 deletions autotune_tmc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math, logging, os
from enum import Enum
from inspect import signature
from . import tmc

# Autotune config parameters
Expand Down Expand Up @@ -32,10 +33,10 @@
FAST_STANDSTILL = True
SMALL_HYSTERESIS = False
SEMIN = 2
SEMAX = 2
SEMAX = 4
SEUP = 3
SEDN = 2
SEIMIN = 0 # If we drop to 1/4 current, high accels don't work right
SEIMIN = 1 # If we drop to 1/4 current, high accels don't work right
SFILT = 0
IHOLDDELAY = 12
IRUNDELAY = 0
Expand Down Expand Up @@ -88,7 +89,11 @@ def __init__(self, config):
raise config.error(
"Could not find any TMC driver config section for '%s' required by TMC autotuning"
% (self.name))

# TMCtstepHelper may have two signatures, let's pick an implementation
if 'pstepper' in signature(tmc.TMCtstepHelper).parameters:
self._set_driver_velocity_field = self._set_driver_velocity_field_new
else:
self._set_driver_velocity_field = self._set_driver_velocity_field_old
# AutotuneTMC config parameters
self.motor = config.get('motor')
self.motor_name = "motor_constants " + self.motor
Expand Down Expand Up @@ -250,7 +255,19 @@ def _set_driver_field(self, field, arg):
val = tmco.fields.set_field(field, arg)
tmco.mcu_tmc.set_register(register, val, None)

def _set_driver_velocity_field(self, field, velocity):
def _set_driver_velocity_field_new(self, field, velocity):
tmco = self.tmc_object
register = tmco.fields.lookup_register(field, None)
# Just bail if the field doesn't exist.
if register is None:
return
arg = tmc.TMCtstepHelper(tmco.mcu_tmc, velocity,
pstepper=self.tmc_cmdhelper.stepper)
logging.info("autotune_tmc set %s %s=%s(%s)",
self.name, field, repr(arg), repr(velocity))
tmco.fields.set_field(field, arg)

def _set_driver_velocity_field_old(self, field, velocity):
tmco = self.tmc_object
register = tmco.fields.lookup_register(field, None)
# Just bail if the field doesn't exist.
Expand Down Expand Up @@ -309,7 +326,8 @@ def _pwmthrs(self, vmaxpwm, coolthrs):
else:
# We do not have SG4, so this makes the world safe for
# sensorless homing in the presence of CoolStep
return 0.5 * coolthrs
# return 0.5 * coolthrs
return 0.5 * vmaxpwm

def _setup_pwm(self, tgoal, pwmthrs):
motor = self.motor_object
Expand Down
7 changes: 7 additions & 0 deletions motor_database.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ holding_torque: 0.10
max_current: 1.0
steps_per_revolution: 200

[motor_constants ldo-36sth20-1004ahg-9T]
resistance: 2.4
inductance: 0.0014
holding_torque: 0.10
max_current: 1.0
steps_per_revolution: 200

[motor_constants ldo-36sth20-1004ahg]
resistance: 2.1
inductance: 0.0016
Expand Down

0 comments on commit ddb35cc

Please sign in to comment.