Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/sim/SimulatedManipulatorDescription.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2004 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: SimulatedManipulatorDescription.cpp 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.1 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <robot/sim/SimulatedManipulatorDescription>
00026 
00027 #include <base/Application>
00028 #include <base/Externalizer>
00029 #include <base/externalization_error>
00030 
00031 using robot::sim::SimulatedManipulatorDescription;
00032 
00033 using base::Externalizer;
00034 using base::externalization_error;
00035 using base::Application;
00036 using base::PathName;
00037 using base::VFile;
00038 using base::dom::DOMNode;
00039 using base::dom::DOMElement;
00040 
00041 
00042 /// \todo output of XML init config, geom & prox info
00043 void SimulatedManipulatorDescription::externalize(base::Externalizer& e, String format, Real version)
00044 {
00045   if (format == "") format = "xml";
00046 
00047   if (!formatSupported(format,version,e.ioType()))
00048     throw std::invalid_argument(Exception(String("format ")+format+" v"+base::realToString(version)+" unsupported"));
00049 
00050   if (e.isOutput()) {
00051 
00052     DOMElement*  manipElem = e.createElement("manipulator");
00053     outputElementXML(e, manipElem, format, version);
00054     e.appendElement(manipElem);
00055 
00056   } else { // input
00057       
00058     DOMNode* context = e.context();
00059     DOMElement* manipElem = e.getFirstElement(context, "manipulator");
00060 
00061     // handle link
00062     String link = e.getElementAttribute(manipElem,"link",false);
00063     if (link != "") {
00064   
00065       ref<VFile> linkFile = Application::getInstance()->universe()->cache()->findFile(link,e.getArchivePath());
00066       load(linkFile,format,version);
00067     }
00068     else {
00069       inputElementXML(e,manipElem, format, version);
00070     }
00071     
00072     // handle any simulation specific stuff present
00073     
00074     // read in initial configuration
00075     DOMElement* configElem = e.getFirstChildElement(manipElem, "initialconfig",false);
00076     bool initialConfigSpecified = (configElem != 0);
00077     if (initialConfigSpecified) {
00078       String configText = e.getContainedText(configElem);
00079       q = e.toVector(configText);
00080       for(Int i=0; i<q.size(); i++) // convert from Deg to Rad
00081         q[i] = Math::degToRad(q[i]);
00082     }
00083     
00084     if (!initialConfigSpecified) {
00085       q = zeroVector(kinematicChain.dof());
00086     }
00087     else
00088       if (q.size() != kinematicChain.dof())
00089         throw new externalization_error(Exception("initialconfig element has vector of wrong dimension ("+base::intToString(q.size())
00090                                            +"); must be equal to manipulator dof ("+base::intToString(kinematicChain.dof())+")"));
00091     
00092     // read in link geometry (if any)
00093     DOMElement* geomElem = e.getFirstChildElement(manipElem, "geometry",false);
00094     linkGeometrySpecified = (geomElem != 0);
00095     if (linkGeometrySpecified) {
00096       // !!! for now just assume a vector of link radii
00097       String geomText = e.getContainedText(geomElem);
00098       Vector r( e.toVector(geomText) );
00099       linkRadii.resize(r.size());
00100       for(Int i=0; i<r.size(); i++) linkRadii[i] = r[i];
00101     }
00102     
00103     
00104     if (linkGeometrySpecified)
00105       if (linkRadii.size() != kinematicChain.size()+1)
00106         throw new externalization_error(Exception("geometry element has wrong number of link radii ("+base::intToString(linkRadii.size())
00107                                            +"); must be equal to number of links + the base ("+base::intToString(kinematicChain.size()+1)+")"));
00108     
00109 
00110     // read in proximity sensor flag
00111     DOMElement* proxElem = e.getFirstChildElement(manipElem, "proximitysensors",false);
00112     hasProxSensors = (proxElem != 0);
00113     if (hasProxSensors) {
00114       String rangeText = e.getElementAttribute(proxElem, "range", true);
00115       proxSensorRange = base::stringToReal(rangeText);
00116     }
00117 
00118     
00119     e.removeElement(manipElem);
00120 
00121   }
00122 }
00123 

Generated on Thu Jul 29 15:56:40 2004 for OpenSim by doxygen 1.3.6