motan: Added pointwise 2-norm motan data analyzer

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin 2022-09-05 22:28:19 +02:00 committed by KevinOConnor
parent 366b0de1c8
commit 5fc5d95ca5
1 changed files with 53 additions and 0 deletions

View File

@ -105,6 +105,59 @@ class GenIntegral:
return data return data
AHandlers["integral"] = GenIntegral AHandlers["integral"] = GenIntegral
# Calculate a pointwise 2-norm of several datasets (e.g. compute velocity or
# accel from its x, y,... components)
class GenNorm2:
ParametersMin = 2
ParametersMax = 3
DataSets = [
('norm2(<dataset1>,<dataset2>)',
'pointwise 2-norm of dataset1 and dataset2'),
('norm2(<dataset1>,<dataset2>,<dataset3>)',
'pointwise 2-norm of 3 datasets'),
]
def __init__(self, amanager, name_parts):
self.amanager = amanager
self.datasets = []
self.datasets.append(name_parts[1])
self.datasets.append(name_parts[2])
if len(name_parts) == 4:
self.datasets.append(name_parts[3])
for dataset in self.datasets:
amanager.setup_dataset(dataset)
def get_label(self):
label = self.amanager.get_label(self.datasets[0])
units = label['units']
datas = ['position', 'velocity', 'acceleration']
data_name = ''
for d in datas:
if d in label['label']:
data_name = d
break
lname = ''
for d in self.datasets:
l = self.amanager.get_label(d)['label']
for r in datas:
l = l.replace(r, '').strip()
if lname:
lname += '+'
lname += l
lname += ' ' + data_name + ' norm2'
return {'label': lname, 'units': units}
def generate_data(self):
seg_time = self.amanager.get_segment_time()
data = []
for dataset in self.datasets:
data.append(self.amanager.get_datasets()[dataset])
res = [0.] * len(data[0])
for i in range(len(data[0])):
norm2 = 0.
for dataset in data:
norm2 += dataset[i] * dataset[i]
res[i] = math.sqrt(norm2)
return res
AHandlers["norm2"] = GenNorm2
# 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