evaluate_dbg_jnt_velocity_tests.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 #   http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 
00017 
00018 import os
00019 from pylab import *
00020 
00021 EPS = 0.001
00022 
00023 DO_REVERSE = True # reverse because stop time is equal for both data - start time could be different
00024 
00025 global SAVE_DIR
00026 SAVE_DIR = '/home/fxm-mb/Scripts/Tests/ResultsFmt'
00027 
00028 colors = ('b', 'r', 'y', 'g', 'm', 'c', 'k', )
00029 
00030 def getMeasData(filename):
00031     newData = []
00032     with open(filename) as fp:
00033         for line in fp.readlines():
00034             line = line.strip()
00035             if line.startswith('[') and line.endswith(']'):
00036                 newData.append(eval(line))
00037     if DO_REVERSE: newData.reverse()
00038     return newData
00039 
00040 def evalData(oldData, newData):
00041     allErrors = []
00042     if len(newData) < len(oldData):
00043         minLen = len(newData)
00044     else:
00045         minLen = len(oldData)
00046 
00047     for lv in range(minLen):
00048         tmpNew = newData[lv]
00049         tmpOld = oldData[lv]
00050         jointErrors = []
00051         for idx, newVal in enumerate(tmpNew):
00052             errorVal = abs(newVal - tmpOld[idx])
00053             #if errorVal > EPS:
00054                 # print("Found error greater than eps=%f: In line %d; link %d; error=%f" % (EPS, lv, idx, errorVal))
00055             jointErrors.append(errorVal)
00056         allErrors.append(jointErrors)
00057     if DO_REVERSE: allErrors.reverse()
00058     return allErrors
00059 
00060 def plotErrors(errorData, strTitle):
00061     errorCnt = len(errorData)
00062     fig = figure(figsize=(16.0, 10.0))
00063 
00064     positions = []
00065     if len(errorData[0]) > 7:
00066         position = 210
00067     else:
00068         position = 110
00069     colorIdx = 0
00070     for idx in range(len(errorData[0])):
00071         if 0 == idx % 7:
00072             position += 1
00073             positions.append(position)
00074         colorIdx = idx % 7
00075         fig.add_subplot(position).stem([elem[idx] for elem in errorData], linefmt=colors[colorIdx] + '-', markerfmt= colors[colorIdx] + 'o', label='joint %d' % idx)
00076 
00077     for position in positions:
00078         fig.add_subplot(position).set_xlabel('data set number')
00079         fig.add_subplot(position).set_ylabel('abs. error in rad/s')
00080         fig.add_subplot(position).set_title(strTitle)
00081         fig.add_subplot(position).grid(True)
00082         fig.add_subplot(position).legend()
00083 
00084     fig.subplots_adjust(wspace = 0.2, hspace = 0.5)
00085     fig.tight_layout()
00086     if SAVE_DIR is not None:
00087         fig.savefig(os.path.join(SAVE_DIR, strTitle.replace('.txt', '') + '.eps'))
00088     # show()
00089 
00090 def doEvaluation(filenameNew, filenameOld, titleText):
00091     newData = getMeasData(filenameNew)
00092     oldData = getMeasData(filenameOld)
00093     errorData = evalData(oldData, newData)
00094     plotErrors(errorData, titleText)
00095 
00096 def evaluateFiles(basedir, testdir):
00097     baseTestDir = os.path.join(baseDir, testDir)
00098     if not os.path.exists(baseTestDir):
00099         raise IOError('Could not find directory "%s"' % baseTestDir)
00100 
00101     testResults = []
00102     for root, dirs, files in os.walk(baseTestDir):
00103         for file in files:
00104             if '_new_' in file.lower():
00105                 testResults.append((file, file.replace('_new_', '_old_'), ))
00106 
00107         if len(files) != len(testResults) * 2:
00108             print('<<<< WARN >>>>: Could not process all files in dir %s. Expected %d files but found %d' % (dirs, len(testResults) * 2, len(files)))
00109 
00110     for testResultNewOld in testResults:
00111         filepathNew = os.path.join(baseTestDir, testResultNewOld[0])
00112         filepathOld = os.path.join(baseTestDir, testResultNewOld[1])
00113         if not os.path.exists(filepathNew):
00114             print('Could not find path "%s" -> Trying next files for comparison' % filepathNew)
00115             continue
00116         if not os.path.exists(filepathOld):
00117             print('Could not find path "%s" -> Trying next files for comparison' % filepathOld)
00118             continue
00119 
00120         doEvaluation(filepathNew, filepathOld, testDir + '_' + testResultNewOld[0].replace('_new_', ''))
00121 
00122 
00123 if __name__ == '__main__':
00124     baseDir = "/home/fxm-mb/Scripts/Tests/"
00125     for root, dirs, files in os.walk(baseDir):
00126         for testDir in dirs:
00127             if True: # 'manip_none' in testDir:
00128                 print('Evaluating files in dir %s' % testDir)
00129                 evaluateFiles(baseDir, testDir)


cob_twist_controller
Author(s): Felix Messmer , Marco Bezzon , Christoph Mark , Francisco Moreno
autogenerated on Thu Jun 6 2019 21:19:26