Small script to convert output of reporter toOctave/Matlab
"Erwin Aertbelien" <[email protected]> Wed, 19 Oct 2005 19:59:24 +0200
| Newsgroups | gmane.science.robotics.orocos.user |
|---|---|
| Message-ID | <IGECLABPOPGHFKDEMBAOKEGLCAAA.Erwin.Aertbelien@mech.kuleuven.ac.be> |
1. And now it can be used and extended, as it was intended before :) 2. It expects the format of the reporter, it uses the names mentioned in the header of the report to assign it to matlab variables, so it that sense it accepts all kinds of reports. But it has limitations on the types used in the report (std::vector and MotCon::Twist) 3. A more final solution would be to adapt the reporter extension itself to output a matlab-compatible output file and to (optionally) generate a script to read this data into understandable variables in matlab/octave. Erwin -----Original Message----- From: [email protected] [mailto:[email protected]]On Behalf Of Herman Bruyninckx Sent: woensdag 19 oktober 2005 19:14 Cc: Open RObot COntrol Software Subject: Re: [Orocos] Small script to convert output of reporter toOctave/Matlab On Wed, 19 Oct 2005, Erwin Aertbelien wrote: > Included you'll find a small python script to translate > the output of the reporter extension to Octave/Matlab workspace > with meaningfull variables. > > the script does the following : > - reads report.txt > - writers report.dat > - writers report.m to read out report.dat and present it as variables > in the Octave/matlab workspace. > Thanks! Two small remarks: 1. It seems that your script expects one particular kind of report structure? I mean, I see for example a "Twist" appearing in the script. 2. It would be nice to add an LGPL or other free software license to your script, so that others can extend it. Herman -- K.U.Leuven, Mechanical Eng., Mechatronics & Robotics Research Group <http://people.mech.kuleuven.be/~bruyninc> Tel: +32 16 322480 _______________________________________________ Orocos mailing list [email protected] http://lists.mech.kuleuven.be/mailman/listinfo/orocos Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm _______________________________________________ Orocos mailing list [email protected] http://lists.mech.kuleuven.be/mailman/listinfo/orocos
convert.py
(text/plain, 3.4 KB)
#!/usr/bin/python # # Python script to read an orocos report file and construct # an m-file to read this file. Does not work very well # with nested output structures. If used for other types # then std::vector<double> and MotCon::Twist you probably have # to edit this file. # # # begin : Mon oct. 2005 # copyright : (C) 2005 Erwin Aertbelien # email : [email protected] # # *************************************************************************** # * This library is free software; you can redistribute it and/or * # * modify it under the terms of the GNU Lesser General Public * # * License as published by the Free Software Foundation; either * # * version 2.1 of the License, or (at your option) any later version. * # * * # * This library is distributed in the hope that it will be useful, * # * but WITHOUT ANY WARRANTY; without even the implied warranty of * # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * # * Lesser General Public License for more details. * # * * # * You should have received a copy of the GNU Lesser General Public * # * License along with this library; if not, write to the Free Software * # * Foundation, Inc., 59 Temple Place, * # * Suite 330, Boston, MA 02111-1307 USA * # * * # ***************************************************************************/ import re inp = open('report.txt','r') outp = open('report.dat','w') outpm = open('loadreport.m','w') outpm.write('load report.dat\n') linenr = 0; line1expr = re.compile("\|\s*(\w+)::(\w+)") line3expr = re.compile("\s*(\w*)\s*(\<[^\|]*\>)?\s*\|") pos1 = [] name1a = [] name1b = [] name3a = [] name3b = [] name3c = [] size3 = [] offs3 = [] count = 1 for line in inp: linenr=linenr+1 if (linenr==1): print line iter = line1expr.finditer(line) for match in iter: pos1.append(match.start()) name1a.append(match.group(1)) name1b.append(match.group(2)) print match.group(1) print match.group(2) pos1.append(10000) if (linenr==3): iter = line3expr.finditer(line) for match in iter: #pos1.append(match.start()) if (match.group(1) == ""): name3c.append("time") size3.append(1) offs3.append(0) else : if (match.group(2) == "<std::vector<double>>"): name3c.append(match.group(1)) size3.append(7) offs3.append(1) else : if (match.group(2) == "<MotCon::Twist>"): name3c.append(match.group(1)) size3.append(6) offs3.append(0) else: print "Unknown size of "+match.group(2) pos3 = match.start() if (pos3 >= pos1[count]): count=count+1 name3a.append(name1a[count-1]) name3b.append(name1b[count-1]) if (linenr >5): outp.write(line) print pos1 print name1a print name1b print name3a print name3b print name3c print size3 print offs3 count = 1; for i in range(1,len(name3c)): countstart = count+offs3[i] countend = count+size3[i]-1 outpm.write( name3a[i]+"."+name3b[i]+"."+name3c[i]+"= report(:,"+str(countstart)+":"+str(countend)+");\n") count = countend+1 inp.close() outp.close() outpm.close()