motan: Added smoothing motan data analyzer

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin 2023-06-21 21:52:19 +02:00 committed by KevinOConnor
parent 5fc5d95ca5
commit 73d017aa89
1 changed files with 38 additions and 0 deletions

View File

@ -158,6 +158,44 @@ class GenNorm2:
return res return res
AHandlers["norm2"] = GenNorm2 AHandlers["norm2"] = GenNorm2
class GenSmoothed:
ParametersMin = 1
ParametersMax = 2
DataSets = [
('smooth(<dataset>)', 'Generate moving weighted average of a dataset'),
('smooth(<dataset>,<smooth_time>)',
'Generate moving weighted average of a dataset with a given'
' smoothing time that defines the window size'),
]
def __init__(self, amanager, name_parts):
self.amanager = amanager
self.source = name_parts[1]
amanager.setup_dataset(self.source)
self.smooth_time = 0.01
if len(name_parts) > 2:
self.smooth_time = float(name_parts[2])
def get_label(self):
label = self.amanager.get_label(self.source)
return {'label': 'Smoothed ' + label['label'], 'units': label['units']}
def generate_data(self):
seg_time = self.amanager.get_segment_time()
src = self.amanager.get_datasets()[self.source]
n = len(src)
data = [0.] * n
hst = 0.5 * self.smooth_time
seg_half_len = round(hst / seg_time)
inv_norm = 1. / sum([min(k + 1, seg_half_len + seg_half_len - k)
for k in range(2 * seg_half_len)])
for i in range(n):
j = max(0, i - seg_half_len)
je = min(n, i + seg_half_len)
avg_val = 0.
for k, v in enumerate(src[j:je]):
avg_val += v * min(k + 1, seg_half_len + seg_half_len - k)
data[i] = avg_val * inv_norm
return data
AHandlers["smooth"] = GenSmoothed
# Calculate a kinematic stepper position from the toolhead requested position # Calculate a kinematic stepper position from the toolhead requested position
class GenKinematicPosition: class GenKinematicPosition:
ParametersMin = ParametersMax = 1 ParametersMin = ParametersMax = 1