input_shaper: Limit maximum damping_ratio of the shapers

Numerically optimized versions of *EI shapers have been tuned
for specific ranges of damping ratios and will show poor stability
outside of these designated ranges.

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin
2025-10-04 00:18:21 +02:00
committed by KevinOConnor
parent c570f4e095
commit 768b19e8be
4 changed files with 32 additions and 19 deletions

View File

@@ -11,34 +11,39 @@ from . import shaper_defs
class InputShaperParams:
def __init__(self, axis, config):
self.axis = axis
self.shapers = {s.name : s.init_func for s in shaper_defs.INPUT_SHAPERS}
self.shapers = {s.name : s for s in shaper_defs.INPUT_SHAPERS}
shaper_type = config.get('shaper_type', 'mzv')
self.shaper_type = config.get('shaper_type_' + axis, shaper_type)
if self.shaper_type not in self.shapers:
raise config.error(
'Unsupported shaper type: %s' % (self.shaper_type,))
self.damping_ratio = config.getfloat('damping_ratio_' + axis,
shaper_defs.DEFAULT_DAMPING_RATIO,
minval=0., maxval=1.)
self.damping_ratio = config.getfloat(
'damping_ratio_' + axis,
shaper_defs.DEFAULT_DAMPING_RATIO, minval=0.,
maxval=self.shapers[self.shaper_type].max_damping_ratio)
self.shaper_freq = config.getfloat('shaper_freq_' + axis, 0., minval=0.)
def update(self, gcmd):
axis = self.axis.upper()
self.damping_ratio = gcmd.get_float('DAMPING_RATIO_' + axis,
self.damping_ratio,
minval=0., maxval=1.)
self.shaper_freq = gcmd.get_float('SHAPER_FREQ_' + axis,
self.shaper_freq, minval=0.)
shaper_type = gcmd.get('SHAPER_TYPE', None)
if shaper_type is None:
shaper_type = gcmd.get('SHAPER_TYPE_' + axis, self.shaper_type)
if shaper_type.lower() not in self.shapers:
raise gcmd.error('Unsupported shaper type: %s' % (shaper_type,))
damping_ratio = gcmd.get_float('DAMPING_RATIO_' + axis,
self.damping_ratio, minval=0.)
if damping_ratio > self.shapers[shaper_type.lower()].max_damping_ratio:
raise gcmd.error(
'Too high value of damping_ratio=%.3f for shaper %s'
' on axis %c' % (damping_ratio, shaper_type, axis))
self.shaper_freq = gcmd.get_float('SHAPER_FREQ_' + axis,
self.shaper_freq, minval=0.)
self.damping_ratio = damping_ratio
self.shaper_type = shaper_type.lower()
def get_shaper(self):
if not self.shaper_freq:
A, T = shaper_defs.get_none_shaper()
else:
A, T = self.shapers[self.shaper_type](
A, T = self.shapers[self.shaper_type].init_func(
self.shaper_freq, self.damping_ratio)
return len(A), A, T
def get_status(self):

View File

@@ -9,7 +9,8 @@ SHAPER_VIBRATION_REDUCTION=20.
DEFAULT_DAMPING_RATIO = 0.1
InputShaperCfg = collections.namedtuple(
'InputShaperCfg', ('name', 'init_func', 'min_freq'))
'InputShaperCfg',
('name', 'init_func', 'min_freq', 'max_damping_ratio'))
def get_none_shaper():
return ([], [])
@@ -105,10 +106,16 @@ def get_3hump_ei_shaper(shaper_freq, damping_ratio):
# min_freq for each shaper is chosen to have projected max_accel ~= 1500
INPUT_SHAPERS = [
InputShaperCfg('zv', get_zv_shaper, min_freq=21.),
InputShaperCfg('mzv', get_mzv_shaper, min_freq=23.),
InputShaperCfg('zvd', get_zvd_shaper, min_freq=29.),
InputShaperCfg('ei', get_ei_shaper, min_freq=29.),
InputShaperCfg('2hump_ei', get_2hump_ei_shaper, min_freq=39.),
InputShaperCfg('3hump_ei', get_3hump_ei_shaper, min_freq=48.),
InputShaperCfg(name='zv', init_func=get_zv_shaper,
min_freq=21., max_damping_ratio=0.99),
InputShaperCfg(name='mzv', init_func=get_mzv_shaper,
min_freq=23., max_damping_ratio=0.99),
InputShaperCfg(name='zvd', init_func=get_zvd_shaper,
min_freq=29., max_damping_ratio=0.99),
InputShaperCfg(name='ei', init_func=get_ei_shaper,
min_freq=29., max_damping_ratio=0.4),
InputShaperCfg(name='2hump_ei', init_func=get_2hump_ei_shaper,
min_freq=39., max_damping_ratio=0.3),
InputShaperCfg(name='3hump_ei', init_func=get_3hump_ei_shaper,
min_freq=48., max_damping_ratio=0.2),
]

View File

@@ -70,8 +70,9 @@ max_z_accel: 100
[input_shaper]
shaper_type_x: mzv
shaper_freq_x: 33.2
shaper_type_x: ei
shaper_type_y: ei
shaper_freq_x: 39.3
damping_ratio_y: 0.4
[adxl345]
cs_pin: PK7

View File

@@ -4,4 +4,4 @@ DICTIONARY atmega2560.dict
# Simple command test
SET_INPUT_SHAPER SHAPER_FREQ_X=22.2 DAMPING_RATIO_X=.1 SHAPER_TYPE_X=zv
SET_INPUT_SHAPER SHAPER_FREQ_Y=33.3 DAMPING_RATIO_X=.11 SHAPER_TYPE_X=2hump_ei
SET_INPUT_SHAPER SHAPER_FREQ_Y=33.3 DAMPING_RATIO_Y=.11 SHAPER_TYPE_Y=2hump_ei