evaluate_dbg_jnt_velocity_tests.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import os
19 from pylab import figure
20 
21 EPS = 0.001
22 
23 DO_REVERSE = True # reverse because stop time is equal for both data - start time could be different
24 
25 global SAVE_DIR
26 SAVE_DIR = '/home/fxm-mb/Scripts/Tests/ResultsFmt'
27 
28 colors = ('b', 'r', 'y', 'g', 'm', 'c', 'k', )
29 
30 def getMeasData(filename):
31  newData = []
32  with open(filename) as fp:
33  for line in fp.readlines():
34  line = line.strip()
35  if line.startswith('[') and line.endswith(']'):
36  newData.append(eval(line))
37  if DO_REVERSE: newData.reverse()
38  return newData
39 
40 def evalData(oldData, newData):
41  allErrors = []
42  if len(newData) < len(oldData):
43  minLen = len(newData)
44  else:
45  minLen = len(oldData)
46 
47  for lv in range(minLen):
48  tmpNew = newData[lv]
49  tmpOld = oldData[lv]
50  jointErrors = []
51  for idx, newVal in enumerate(tmpNew):
52  errorVal = abs(newVal - tmpOld[idx])
53  #if errorVal > EPS:
54  # print("Found error greater than eps=%f: In line %d; link %d; error=%f" % (EPS, lv, idx, errorVal))
55  jointErrors.append(errorVal)
56  allErrors.append(jointErrors)
57  if DO_REVERSE: allErrors.reverse()
58  return allErrors
59 
60 def plotErrors(errorData, strTitle):
61  errorCnt = len(errorData)
62  fig = figure(figsize=(16.0, 10.0))
63 
64  positions = []
65  if len(errorData[0]) > 7:
66  position = 210
67  else:
68  position = 110
69  colorIdx = 0
70  for idx in range(len(errorData[0])):
71  if 0 == idx % 7:
72  position += 1
73  positions.append(position)
74  colorIdx = idx % 7
75  fig.add_subplot(position).stem([elem[idx] for elem in errorData], linefmt=colors[colorIdx] + '-', markerfmt= colors[colorIdx] + 'o', label='joint %d' % idx)
76 
77  for position in positions:
78  fig.add_subplot(position).set_xlabel('data set number')
79  fig.add_subplot(position).set_ylabel('abs. error in rad/s')
80  fig.add_subplot(position).set_title(strTitle)
81  fig.add_subplot(position).grid(True)
82  fig.add_subplot(position).legend()
83 
84  fig.subplots_adjust(wspace = 0.2, hspace = 0.5)
85  fig.tight_layout()
86  if SAVE_DIR is not None:
87  fig.savefig(os.path.join(SAVE_DIR, strTitle.replace('.txt', '') + '.eps'))
88  # show()
89 
90 def doEvaluation(filenameNew, filenameOld, titleText):
91  newData = getMeasData(filenameNew)
92  oldData = getMeasData(filenameOld)
93  errorData = evalData(oldData, newData)
94  plotErrors(errorData, titleText)
95 
96 def evaluateFiles(basedir, testdir):
97  baseTestDir = os.path.join(baseDir, testDir)
98  if not os.path.exists(baseTestDir):
99  raise IOError('Could not find directory "%s"' % baseTestDir)
100 
101  testResults = []
102  for root, dirs, files in os.walk(baseTestDir):
103  for file in files:
104  if '_new_' in file.lower():
105  testResults.append((file, file.replace('_new_', '_old_'), ))
106 
107  if len(files) != len(testResults) * 2:
108  print('<<<< WARN >>>>: Could not process all files in dir %s. Expected %d files but found %d' % (dirs, len(testResults) * 2, len(files)))
109 
110  for testResultNewOld in testResults:
111  filepathNew = os.path.join(baseTestDir, testResultNewOld[0])
112  filepathOld = os.path.join(baseTestDir, testResultNewOld[1])
113  if not os.path.exists(filepathNew):
114  print('Could not find path "%s" -> Trying next files for comparison' % filepathNew)
115  continue
116  if not os.path.exists(filepathOld):
117  print('Could not find path "%s" -> Trying next files for comparison' % filepathOld)
118  continue
119 
120  doEvaluation(filepathNew, filepathOld, testDir + '_' + testResultNewOld[0].replace('_new_', ''))
121 
122 
123 if __name__ == '__main__':
124  baseDir = "/home/fxm-mb/Scripts/Tests/"
125  for root, dirs, files in os.walk(baseDir):
126  for testDir in dirs:
127  if True: # 'manip_none' in testDir:
128  print('Evaluating files in dir %s' % testDir)
129  evaluateFiles(baseDir, testDir)
def doEvaluation(filenameNew, filenameOld, titleText)


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Apr 8 2021 02:40:00