tmc: SET_TMC_FIELD VELOCITY
Ability to specify `VELOCITY` as a parameter for SET_TMC_FIELD. Useful for configuring at runtime the TSTEP based fields of the driver. Signed-off-by: Alex Voinea <voinea.dragos.alexandru@gmail.com>
This commit is contained in:
parent
0469710a69
commit
73f4c6cd00
|
@ -1236,13 +1236,16 @@ if StealthChop2 is used, the stepper must be held at standstill for >130ms so
|
|||
that the driver executes the AT#1 calibration.
|
||||
|
||||
#### SET_TMC_FIELD
|
||||
`SET_TMC_FIELD STEPPER=<name> FIELD=<field> VALUE=<value>`: This will
|
||||
alter the value of the specified register field of the TMC driver.
|
||||
`SET_TMC_FIELD STEPPER=<name> FIELD=<field> VALUE=<value> VELOCITY=<value>`:
|
||||
This will alter the value of the specified register field of the TMC driver.
|
||||
This command is intended for low-level diagnostics and debugging only
|
||||
because changing the fields during run-time can lead to undesired and
|
||||
potentially dangerous behavior of your printer. Permanent changes
|
||||
should be made using the printer configuration file instead. No sanity
|
||||
checks are performed for the given values.
|
||||
A VELOCITY can also be specified instead of a VALUE. This velocity is
|
||||
converted to the 20bit TSTEP based value representation. Only use the VELOCITY
|
||||
argument for fields that represent velocities.
|
||||
|
||||
### [toolhead]
|
||||
|
||||
|
|
|
@ -258,7 +258,18 @@ class TMCCommandHelper:
|
|||
reg_name = self.fields.lookup_register(field_name, None)
|
||||
if reg_name is None:
|
||||
raise gcmd.error("Unknown field name '%s'" % (field_name,))
|
||||
value = gcmd.get_int('VALUE')
|
||||
value = gcmd.get_int('VALUE', None)
|
||||
velocity = gcmd.get_float('VELOCITY', None, minval=0.)
|
||||
tmc_frequency = self.mcu_tmc.get_tmc_frequency()
|
||||
if tmc_frequency is None and velocity is not None:
|
||||
raise gcmd.error("VELOCITY parameter not supported by this driver")
|
||||
if (value is None) == (velocity is None):
|
||||
raise gcmd.error("Specify either VALUE or VELOCITY")
|
||||
if velocity is not None:
|
||||
step_dist = self.stepper.get_step_dist()
|
||||
mres = self.fields.get_field("mres")
|
||||
value = TMCtstepHelper(step_dist, mres, tmc_frequency,
|
||||
velocity)
|
||||
reg_val = self.fields.set_field(field_name, value)
|
||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
||||
self.mcu_tmc.set_register(reg_name, reg_val, print_time)
|
||||
|
|
|
@ -248,13 +248,14 @@ def lookup_tmc_spi_chain(config):
|
|||
|
||||
# Helper code for working with TMC devices via SPI
|
||||
class MCU_TMC_SPI:
|
||||
def __init__(self, config, name_to_reg, fields):
|
||||
def __init__(self, config, name_to_reg, fields, tmc_frequency):
|
||||
self.printer = config.get_printer()
|
||||
self.name = config.get_name().split()[-1]
|
||||
self.tmc_spi, self.chain_pos = lookup_tmc_spi_chain(config)
|
||||
self.mutex = self.tmc_spi.mutex
|
||||
self.name_to_reg = name_to_reg
|
||||
self.fields = fields
|
||||
self.tmc_frequency = tmc_frequency
|
||||
def get_fields(self):
|
||||
return self.fields
|
||||
def get_register(self, reg_name):
|
||||
|
@ -271,6 +272,8 @@ class MCU_TMC_SPI:
|
|||
return
|
||||
raise self.printer.command_error(
|
||||
"Unable to write tmc spi '%s' register %s" % (self.name, reg_name))
|
||||
def get_tmc_frequency(self):
|
||||
return self.tmc_frequency
|
||||
|
||||
|
||||
######################################################################
|
||||
|
@ -281,7 +284,8 @@ class TMC2130:
|
|||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = MCU_TMC_SPI(config, Registers, self.fields)
|
||||
self.mcu_tmc = MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
# Allow virtual pins to be created
|
||||
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||
# Register commands
|
||||
|
|
|
@ -186,7 +186,8 @@ class TMC2208:
|
|||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
|
||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, 0,
|
||||
TMC_FREQUENCY)
|
||||
self.fields.set_field("pdn_disable", True)
|
||||
# Register commands
|
||||
current_helper = tmc2130.TMCCurrentHelper(config, self.mcu_tmc)
|
||||
|
|
|
@ -58,7 +58,8 @@ class TMC2209:
|
|||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields,
|
||||
FieldFormatters)
|
||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, 3)
|
||||
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, 3,
|
||||
TMC_FREQUENCY)
|
||||
# Setup fields for UART
|
||||
self.fields.set_field("pdn_disable", True)
|
||||
self.fields.set_field("senddelay", 2) # Avoid tx errors on shared uart
|
||||
|
|
|
@ -343,7 +343,8 @@ class TMC2240:
|
|||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
# Allow virtual pins to be created
|
||||
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||
# Register commands
|
||||
|
|
|
@ -221,6 +221,8 @@ class MCU_TMC2660_SPI:
|
|||
msg = [((val >> 16) | reg) & 0xff, (val >> 8) & 0xff, val & 0xff]
|
||||
with self.mutex:
|
||||
self.spi.spi_send(msg, minclock)
|
||||
def get_tmc_frequency(self):
|
||||
return None
|
||||
|
||||
|
||||
######################################################################
|
||||
|
|
|
@ -316,7 +316,8 @@ class TMC5160:
|
|||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
# Allow virtual pins to be created
|
||||
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||
# Register commands
|
||||
|
|
|
@ -210,7 +210,7 @@ def lookup_tmc_uart_bitbang(config, max_addr):
|
|||
|
||||
# Helper code for communicating via TMC uart
|
||||
class MCU_TMC_uart:
|
||||
def __init__(self, config, name_to_reg, fields, max_addr=0):
|
||||
def __init__(self, config, name_to_reg, fields, max_addr, tmc_frequency):
|
||||
self.printer = config.get_printer()
|
||||
self.name = config.get_name().split()[-1]
|
||||
self.name_to_reg = name_to_reg
|
||||
|
@ -219,6 +219,7 @@ class MCU_TMC_uart:
|
|||
self.instance_id, self.addr, self.mcu_uart = lookup_tmc_uart_bitbang(
|
||||
config, max_addr)
|
||||
self.mutex = self.mcu_uart.mutex
|
||||
self.tmc_frequency = tmc_frequency
|
||||
def get_fields(self):
|
||||
return self.fields
|
||||
def _do_get_register(self, reg_name):
|
||||
|
@ -250,3 +251,5 @@ class MCU_TMC_uart:
|
|||
return
|
||||
raise self.printer.command_error(
|
||||
"Unable to write tmc uart '%s' register %s" % (self.name, reg_name))
|
||||
def get_tmc_frequency(self):
|
||||
return self.tmc_frequency
|
||||
|
|
Loading…
Reference in New Issue