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>
This commit is contained in:
parent
4a41d228eb
commit
7dcc778b6c
|
@ -10,7 +10,8 @@
|
|||
step_pin: ar54
|
||||
dir_pin: ar55
|
||||
enable_pin: !ar38
|
||||
step_distance: 0.001963495
|
||||
microsteps: 16
|
||||
gear_ratio: 80:16
|
||||
|
||||
[stepper_arm]
|
||||
step_pin: ar60
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
step_pin: ar54
|
||||
dir_pin: ar55
|
||||
enable_pin: !ar38
|
||||
step_distance: 0.001963495
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar2
|
||||
homing_speed: 50
|
||||
position_endstop: 252
|
||||
|
@ -21,14 +22,16 @@ lower_arm_length: 320.000
|
|||
step_pin: ar60
|
||||
dir_pin: ar61
|
||||
enable_pin: !ar56
|
||||
step_distance: 0.001963495
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar15
|
||||
|
||||
[stepper_c]
|
||||
step_pin: ar46
|
||||
dir_pin: ar48
|
||||
enable_pin: !ar62
|
||||
step_distance: 0.001963495
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar19
|
||||
|
||||
[extruder]
|
||||
|
|
|
@ -6,6 +6,12 @@ All dates in this document are approximate.
|
|||
|
||||
# Changes
|
||||
|
||||
20201218: Rotary delta and polar printers must now specify a
|
||||
`gear_ratio` for their rotary steppers, and they may no longer specify
|
||||
a `step_distance` parameter. See the
|
||||
[config reference](Config_Reference.md#stepper) for the format of the
|
||||
new gear_ratio paramter.
|
||||
|
||||
20201213: It is not valid to specify a Z "position_endstop" when using
|
||||
"probe:z_virtual_endstop". An error will now be raised if a Z
|
||||
"position_endstop" is specified with "probe:z_virtual_endstop".
|
||||
|
|
|
@ -127,9 +127,24 @@ enable_pin:
|
|||
# Enable pin (default is enable high; use ! to indicate enable
|
||||
# low). If this parameter is not provided then the stepper motor
|
||||
# driver must always be enabled.
|
||||
step_distance:
|
||||
# Distance in mm that each step causes the axis to travel. This
|
||||
rotation_distance:
|
||||
# Distance (in mm) that the axis travels with one full rotation of
|
||||
# the stepper motor. This parameter must be provided.
|
||||
microsteps:
|
||||
# The number of microsteps the stepper motor driver uses. This
|
||||
# parameter must be provided.
|
||||
#full_steps_per_rotation: 200
|
||||
# The number of full steps for one rotation of the stepper motor.
|
||||
# Set this to 200 for a 1.8 degree stepper motor or set to 400 for a
|
||||
# 0.9 degree motor. The default is 200.
|
||||
#gear_ratio:
|
||||
# The gear ratio if the stepper motor is connected to the axis via a
|
||||
# gearbox. For example, one may specify "5:1" if a 5 to 1 gearbox is
|
||||
# in use. If the axis has multiple gearboxes one may specify a comma
|
||||
# separated list of gear ratios (for example, "57:11, 2:1"). If a
|
||||
# gear_ratio is specified then rotation_distance specifies the
|
||||
# distance the axis travels for one full rotation of the final gear.
|
||||
# The default is to not use a gear ratio.
|
||||
endstop_pin:
|
||||
# Endstop switch detection pin. This parameter must be provided for
|
||||
# the X, Y, and Z steppers on cartesian style printers.
|
||||
|
@ -367,11 +382,11 @@ kinematics: polar
|
|||
# The stepper_bed section is used to describe the stepper controlling
|
||||
# the bed.
|
||||
[stepper_bed]
|
||||
step_distance:
|
||||
# On a polar printer the step_distance is the amount each step pulse
|
||||
# moves the bed in radians (for example, a 1.8 degree stepper with
|
||||
# 16 micro-steps would be 2 * pi * (1.8 / 360) / 16 == 0.001963495).
|
||||
# This parameter must be provided.
|
||||
gear_ratio:
|
||||
# A gear_ratio must be specified and rotation_distance may not be
|
||||
# specified. For example, if the bed has an 80 toothed pulley driven
|
||||
# by a stepper with a 16 toothed pulley then one would specify a
|
||||
# gear ratio of "80:16". This parameter must be provided.
|
||||
max_z_velocity:
|
||||
# This sets the maximum velocity (in mm/s) of movement along the z
|
||||
# axis. This setting can be used to restrict the maximum speed of
|
||||
|
@ -429,11 +444,13 @@ shoulder_height:
|
|||
# right arm (at 30 degrees). This section also controls the homing
|
||||
# parameters (homing_speed, homing_retract_dist) for all arms.
|
||||
[stepper_a]
|
||||
step_distance:
|
||||
# On a rotary delta printer the step_distance is the amount each
|
||||
# step pulse moves the upper arm in radians (for example, a directly
|
||||
# connected 1.8 degree stepper with 16 micro-steps would be 2 * pi *
|
||||
# (1.8 / 360) / 16 == 0.001963495). This parameter must be provided.
|
||||
gear_ratio:
|
||||
# A gear_ratio must be specified and rotation_distance may not be
|
||||
# specified. For example, if the arm has an 80 toothed pulley driven
|
||||
# by a pulley with 16 teeth, which is in turn connected to a 60
|
||||
# toothed pulley driven by a stepper with a 16 toothed pulley, then
|
||||
# one would specify a gear ratio of "80:16, 60:16". This parameter
|
||||
# must be provided.
|
||||
position_endstop:
|
||||
# Distance (in mm) between the nozzle and the bed when the nozzle is
|
||||
# in the center of the build area and the endstop triggers. This
|
||||
|
@ -501,10 +518,10 @@ kinematics: winch
|
|||
# cable winch. A minimum of 3 and a maximum of 26 cable winches may be
|
||||
# defined (stepper_a to stepper_z) though it is common to define 4.
|
||||
[stepper_a]
|
||||
step_distance:
|
||||
# The step_distance is the nominal distance (in mm) the toolhead
|
||||
# moves towards the cable winch on each step pulse. This parameter
|
||||
# must be provided.
|
||||
rotation_distance:
|
||||
# The rotation_distance is the nominal distance (in mm) the toolhead
|
||||
# moves towards the cable winch for each full rotation of the
|
||||
# stepper motor. This parameter must be provided.
|
||||
anchor_x:
|
||||
anchor_y:
|
||||
anchor_z:
|
||||
|
@ -541,7 +558,8 @@ tuning pressure advance.
|
|||
step_pin:
|
||||
dir_pin:
|
||||
enable_pin:
|
||||
step_distance:
|
||||
microsteps:
|
||||
rotation_distance:
|
||||
# See the "stepper" section for a description of the above parameters.
|
||||
nozzle_diameter:
|
||||
# Diameter of the nozzle orifice (in mm). This parameter must be
|
||||
|
@ -1613,7 +1631,8 @@ at 1 (for example, "stepper_z1", "stepper_z2", etc.).
|
|||
#step_pin:
|
||||
#dir_pin:
|
||||
#enable_pin:
|
||||
#step_distance:
|
||||
#microsteps:
|
||||
#rotation_distance:
|
||||
# See the "stepper" section for the definition of the above parameters.
|
||||
#endstop_pin:
|
||||
# If an endstop_pin is defined for the additional stepper then the
|
||||
|
@ -1670,7 +1689,8 @@ axis:
|
|||
#step_pin:
|
||||
#dir_pin:
|
||||
#enable_pin:
|
||||
#step_distance:
|
||||
#microsteps:
|
||||
#rotation_distance:
|
||||
#endstop_pin:
|
||||
#position_endstop:
|
||||
#position_min:
|
||||
|
@ -1695,7 +1715,8 @@ more information.
|
|||
#step_pin:
|
||||
#dir_pin:
|
||||
#enable_pin:
|
||||
#step_distance:
|
||||
#microsteps:
|
||||
#rotation_distance:
|
||||
# See the "stepper" section for the definition of the above
|
||||
# parameters.
|
||||
```
|
||||
|
@ -1715,7 +1736,8 @@ normal printer kinematics.
|
|||
#step_pin:
|
||||
#dir_pin:
|
||||
#enable_pin:
|
||||
#step_distance:
|
||||
#microsteps:
|
||||
#rotation_distance:
|
||||
# See the "stepper" section for a description of these parameters.
|
||||
#velocity:
|
||||
# Set the default velocity (in mm/s) for the stepper. This value
|
||||
|
@ -2531,10 +2553,6 @@ cs_pin:
|
|||
#spi_software_miso_pin:
|
||||
# See the "common SPI settings" section for a description of the
|
||||
# above parameters.
|
||||
microsteps:
|
||||
# The number of microsteps to configure the driver to use. Valid
|
||||
# values are 1, 2, 4, 8, 16, 32, 64, 128, 256. This parameter must
|
||||
# be provided.
|
||||
#interpolate: True
|
||||
# If true, enable step interpolation (the driver will internally
|
||||
# step at a rate of 256 micro-steps). The default is True.
|
||||
|
@ -2601,10 +2619,6 @@ uart_pin:
|
|||
# A comma separated list of pins to set prior to accessing the
|
||||
# tmc2208 UART. This may be useful for configuring an analog mux for
|
||||
# UART communication. The default is to not configure any pins.
|
||||
microsteps:
|
||||
# The number of microsteps to configure the driver to use. Valid
|
||||
# values are 1, 2, 4, 8, 16, 32, 64, 128, 256. This parameter must
|
||||
# be provided.
|
||||
#interpolate: True
|
||||
# If true, enable step interpolation (the driver will internally
|
||||
# step at a rate of 256 micro-steps). The default is True.
|
||||
|
@ -2654,7 +2668,6 @@ by the name of the corresponding stepper config section (for example,
|
|||
uart_pin:
|
||||
#tx_pin:
|
||||
#select_pins:
|
||||
#microsteps:
|
||||
#interpolate: True
|
||||
run_current:
|
||||
#hold_current:
|
||||
|
@ -2715,10 +2728,6 @@ cs_pin:
|
|||
#spi_software_miso_pin:
|
||||
# See the "common SPI settings" section for a description of the
|
||||
# above parameters.
|
||||
microsteps:
|
||||
# The number of microsteps to configure the driver to use. Valid
|
||||
# values are 1, 2, 4, 8, 16, 32, 64, 128, 256. This parameter must
|
||||
# be provided.
|
||||
#interpolate: True
|
||||
# If true, enable step interpolation (the driver will internally
|
||||
# step at a rate of 256 micro-steps). This only works if microsteps
|
||||
|
@ -2786,10 +2795,6 @@ cs_pin:
|
|||
#spi_software_miso_pin:
|
||||
# See the "common SPI settings" section for a description of the
|
||||
# above parameters.
|
||||
microsteps:
|
||||
# The number of microsteps to configure the driver to use. Valid
|
||||
# values are 1, 2, 4, 8, 16, 32, 64, 128, 256. This parameter must
|
||||
# be provided.
|
||||
#interpolate: True
|
||||
# If true, enable step interpolation (the driver will internally
|
||||
# step at a rate of 256 micro-steps). The default is True.
|
||||
|
|
|
@ -100,7 +100,7 @@ then it generally indicates that the "dir_pin" for the axis needs to
|
|||
be inverted. This is done by adding a '!' to the "dir_pin" in the
|
||||
printer config file (or removing it if one is already there). If the
|
||||
motor moves significantly more or significantly less than one
|
||||
millimeter then verify the "step_distance" setting.
|
||||
millimeter then verify the "rotation_distance" setting.
|
||||
|
||||
Run the above test for each stepper motor defined in the config
|
||||
file. (Set the STEPPER parameter of the STEPPER_BUZZ command to the
|
||||
|
|
|
@ -262,9 +262,9 @@ around 10000 steps per second. If it is requested to move at a speed
|
|||
that would require a higher step rate then Marlin will generally just
|
||||
step as fast as it can. Klipper is able to achieve much higher step
|
||||
rates, but the stepper motor may not have sufficient torque to move at
|
||||
a higher speed. So, for a Z axis with a very precise step_distance the
|
||||
actual obtainable max_z_velocity may be smaller than what is
|
||||
configured in Marlin.
|
||||
a higher speed. So, for a Z axis with a high gearing ratio or high
|
||||
microsteps setting the actual obtainable max_z_velocity may be smaller
|
||||
than what is configured in Marlin.
|
||||
|
||||
### My TMC motor driver turns off in the middle of a print
|
||||
|
||||
|
|
|
@ -172,8 +172,10 @@ The following standard commands are supported:
|
|||
[SMOOTH_TIME=<pressure_advance_smooth_time>]`: Set pressure advance
|
||||
parameters. If EXTRUDER is not specified, it defaults to the active
|
||||
extruder.
|
||||
- `SET_EXTRUDER_STEP_DISTANCE [EXTRUDER=<config_name>] [DISTANCE=<distance>]`:
|
||||
Set a new value for the provided extruder's step_distance. Value is
|
||||
- `SET_EXTRUDER_STEP_DISTANCE [EXTRUDER=<config_name>]
|
||||
[DISTANCE=<distance>]`: Set a new value for the provided extruder's
|
||||
"step distance". The "step distance" is
|
||||
`rotation_distance/(full_steps_per_rotation*microsteps)`. Value is
|
||||
not retained on Klipper reset. Use with caution, small changes can
|
||||
result in excessive pressure between extruder and hot end. Do proper
|
||||
calibration steps with filament before use. If 'DISTANCE' value is
|
||||
|
|
|
@ -114,11 +114,12 @@ Recv: // probe accuracy results: maximum 2.519448, minimum 2.506948, range 0.012
|
|||
Ideally the tool will report an identical maximum and minimum value.
|
||||
(That is, ideally the probe obtains an identical result on all ten
|
||||
probes.) However, it's normal for the minimum and maximum values to
|
||||
differ by one Z step_distance or up to 5 microns (.005mm). The
|
||||
distance between the minimum and the maximum value is called the
|
||||
range. So, in the above example, since the printer uses a Z
|
||||
step_distance of .0125, a range of 0.012500 would be considered
|
||||
normal.
|
||||
differ by one Z "step distance" or up to 5 microns (.005mm). A "step
|
||||
distance" is
|
||||
`rotation_distance/(full_steps_per_rotation*microsteps)`. The distance
|
||||
between the minimum and the maximum value is called the range. So, in
|
||||
the above example, since the printer uses a Z step distance of .0125,
|
||||
a range of 0.012500 would be considered normal.
|
||||
|
||||
If the results of the test show a range value that is greater than 25
|
||||
microns (.025mm) then the probe does not have sufficient accuracy for
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -183,7 +183,7 @@ def PrinterStepper(config, units_in_radians=False):
|
|||
step_pin_params = ppins.lookup_pin(step_pin, can_invert=True)
|
||||
dir_pin = config.get('dir_pin')
|
||||
dir_pin_params = ppins.lookup_pin(dir_pin, can_invert=True)
|
||||
step_dist = config.getfloat('step_distance', above=0.)
|
||||
step_dist = parse_step_distance(config, units_in_radians, True)
|
||||
mcu_stepper = MCU_stepper(name, step_pin_params, dir_pin_params, step_dist,
|
||||
units_in_radians)
|
||||
# Support for stepper enable pin handling
|
||||
|
@ -194,6 +194,47 @@ def PrinterStepper(config, units_in_radians=False):
|
|||
force_move.register_stepper(mcu_stepper)
|
||||
return mcu_stepper
|
||||
|
||||
# Parse stepper gear_ratio config parameter
|
||||
def parse_gear_ratio(config, note_valid):
|
||||
gear_ratio = config.get('gear_ratio', None, note_valid=note_valid)
|
||||
if gear_ratio is None:
|
||||
return 1.
|
||||
result = 1.
|
||||
try:
|
||||
gears = gear_ratio.split(',')
|
||||
for gear in gears:
|
||||
g1, g2 = [float(v.strip()) for v in gear.split(':')]
|
||||
result *= g1 / g2
|
||||
except:
|
||||
raise config.error("Unable to parse gear_ratio: %s" % (gear_ratio,))
|
||||
return result
|
||||
|
||||
# Obtain "step distance" information from a config section
|
||||
def parse_step_distance(config, units_in_radians=None, note_valid=False):
|
||||
if units_in_radians is None:
|
||||
# Caller doesn't know if units are in radians - infer it
|
||||
rd = config.get('rotation_distance', None, note_valid=False)
|
||||
gr = config.get('gear_ratio', None, note_valid=False)
|
||||
units_in_radians = rd is None and gr is not None
|
||||
if units_in_radians:
|
||||
rotation_dist = 2. * math.pi
|
||||
config.get('gear_ratio', note_valid=note_valid)
|
||||
else:
|
||||
rotation_dist = config.getfloat('rotation_distance', None,
|
||||
above=0., note_valid=note_valid)
|
||||
if rotation_dist is None:
|
||||
# Older config format with step_distance
|
||||
return config.getfloat('step_distance', above=0., note_valid=note_valid)
|
||||
# Newer config format with rotation_distance
|
||||
microsteps = config.getint('microsteps', minval=1, note_valid=note_valid)
|
||||
full_steps = config.getint('full_steps_per_rotation', 200, minval=1,
|
||||
note_valid=note_valid)
|
||||
if full_steps % 4:
|
||||
raise config.error("full_steps_per_rotation invalid in section '%s'"
|
||||
% (config.get_name(),))
|
||||
gearing = parse_gear_ratio(config, note_valid)
|
||||
return rotation_dist / (full_steps * microsteps * gearing)
|
||||
|
||||
|
||||
######################################################################
|
||||
# Stepper controlled rails
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
step_pin: ar54
|
||||
dir_pin: ar55
|
||||
enable_pin: !ar38
|
||||
step_distance: 0.000010
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar2
|
||||
homing_speed: 50
|
||||
#position_endstop: 252
|
||||
|
@ -14,14 +15,16 @@ lower_arm_length: 320.000
|
|||
step_pin: ar60
|
||||
dir_pin: ar61
|
||||
enable_pin: !ar56
|
||||
step_distance: 0.000010
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar15
|
||||
|
||||
[stepper_c]
|
||||
step_pin: ar46
|
||||
dir_pin: ar48
|
||||
enable_pin: !ar62
|
||||
step_distance: 0.000010
|
||||
microsteps: 16
|
||||
gear_ratio: 107.000:16, 60:16
|
||||
endstop_pin: ^ar19
|
||||
|
||||
[mcu]
|
||||
|
|
Loading…
Reference in New Issue