mirror of
				https://github.com/Klipper3d/klipper.git
				synced 2025-10-31 10:25:57 +01:00 
			
		
		
		
	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:
		
				
					committed by
					
						 KevinOConnor
						KevinOConnor
					
				
			
			
				
	
			
			
			
						parent
						
							c570f4e095
						
					
				
				
					commit
					768b19e8be
				
			| @@ -11,34 +11,39 @@ from . import shaper_defs | |||||||
| class InputShaperParams: | class InputShaperParams: | ||||||
|     def __init__(self, axis, config): |     def __init__(self, axis, config): | ||||||
|         self.axis = axis |         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') |         shaper_type = config.get('shaper_type', 'mzv') | ||||||
|         self.shaper_type = config.get('shaper_type_' + axis, shaper_type) |         self.shaper_type = config.get('shaper_type_' + axis, shaper_type) | ||||||
|         if self.shaper_type not in self.shapers: |         if self.shaper_type not in self.shapers: | ||||||
|             raise config.error( |             raise config.error( | ||||||
|                     'Unsupported shaper type: %s' % (self.shaper_type,)) |                     'Unsupported shaper type: %s' % (self.shaper_type,)) | ||||||
|         self.damping_ratio = config.getfloat('damping_ratio_' + axis, |         self.damping_ratio = config.getfloat( | ||||||
|                                              shaper_defs.DEFAULT_DAMPING_RATIO, |                 'damping_ratio_' + axis, | ||||||
|                                              minval=0., maxval=1.) |                 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.) |         self.shaper_freq = config.getfloat('shaper_freq_' + axis, 0., minval=0.) | ||||||
|     def update(self, gcmd): |     def update(self, gcmd): | ||||||
|         axis = self.axis.upper() |         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) |         shaper_type = gcmd.get('SHAPER_TYPE', None) | ||||||
|         if shaper_type is None: |         if shaper_type is None: | ||||||
|             shaper_type = gcmd.get('SHAPER_TYPE_' + axis, self.shaper_type) |             shaper_type = gcmd.get('SHAPER_TYPE_' + axis, self.shaper_type) | ||||||
|         if shaper_type.lower() not in self.shapers: |         if shaper_type.lower() not in self.shapers: | ||||||
|             raise gcmd.error('Unsupported shaper type: %s' % (shaper_type,)) |             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() |         self.shaper_type = shaper_type.lower() | ||||||
|     def get_shaper(self): |     def get_shaper(self): | ||||||
|         if not self.shaper_freq: |         if not self.shaper_freq: | ||||||
|             A, T = shaper_defs.get_none_shaper() |             A, T = shaper_defs.get_none_shaper() | ||||||
|         else: |         else: | ||||||
|             A, T = self.shapers[self.shaper_type]( |             A, T = self.shapers[self.shaper_type].init_func( | ||||||
|                     self.shaper_freq, self.damping_ratio) |                     self.shaper_freq, self.damping_ratio) | ||||||
|         return len(A), A, T |         return len(A), A, T | ||||||
|     def get_status(self): |     def get_status(self): | ||||||
|   | |||||||
| @@ -9,7 +9,8 @@ SHAPER_VIBRATION_REDUCTION=20. | |||||||
| DEFAULT_DAMPING_RATIO = 0.1 | DEFAULT_DAMPING_RATIO = 0.1 | ||||||
|  |  | ||||||
| InputShaperCfg = collections.namedtuple( | InputShaperCfg = collections.namedtuple( | ||||||
|         'InputShaperCfg', ('name', 'init_func', 'min_freq')) |         'InputShaperCfg', | ||||||
|  |         ('name', 'init_func', 'min_freq', 'max_damping_ratio')) | ||||||
|  |  | ||||||
| def get_none_shaper(): | def get_none_shaper(): | ||||||
|     return ([], []) |     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 | # min_freq for each shaper is chosen to have projected max_accel ~= 1500 | ||||||
| INPUT_SHAPERS = [ | INPUT_SHAPERS = [ | ||||||
|     InputShaperCfg('zv', get_zv_shaper, min_freq=21.), |     InputShaperCfg(name='zv', init_func=get_zv_shaper, | ||||||
|     InputShaperCfg('mzv', get_mzv_shaper, min_freq=23.), |                    min_freq=21., max_damping_ratio=0.99), | ||||||
|     InputShaperCfg('zvd', get_zvd_shaper, min_freq=29.), |     InputShaperCfg(name='mzv', init_func=get_mzv_shaper, | ||||||
|     InputShaperCfg('ei', get_ei_shaper, min_freq=29.), |                    min_freq=23., max_damping_ratio=0.99), | ||||||
|     InputShaperCfg('2hump_ei', get_2hump_ei_shaper, min_freq=39.), |     InputShaperCfg(name='zvd', init_func=get_zvd_shaper, | ||||||
|     InputShaperCfg('3hump_ei', get_3hump_ei_shaper, min_freq=48.), |                    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), | ||||||
| ] | ] | ||||||
|   | |||||||
| @@ -70,8 +70,9 @@ max_z_accel: 100 | |||||||
| [input_shaper] | [input_shaper] | ||||||
| shaper_type_x: mzv | shaper_type_x: mzv | ||||||
| shaper_freq_x: 33.2 | shaper_freq_x: 33.2 | ||||||
| shaper_type_x: ei | shaper_type_y: ei | ||||||
| shaper_freq_x: 39.3 | shaper_freq_x: 39.3 | ||||||
|  | damping_ratio_y: 0.4 | ||||||
|  |  | ||||||
| [adxl345] | [adxl345] | ||||||
| cs_pin: PK7 | cs_pin: PK7 | ||||||
|   | |||||||
| @@ -4,4 +4,4 @@ DICTIONARY atmega2560.dict | |||||||
|  |  | ||||||
| # Simple command test | # Simple command test | ||||||
| SET_INPUT_SHAPER SHAPER_FREQ_X=22.2 DAMPING_RATIO_X=.1 SHAPER_TYPE_X=zv | 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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user