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

robot/sim/IKORTest

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2003 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: IKORTest 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.5 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_IKORTEST_
00026 #define _ROBOT_SIM_IKORTEST_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <base/Externalizable>
00031 #include <base/Named>
00032 #include <base/Vector>
00033 #include <base/Time>
00034 #include <base/Trajectory>
00035 #include <base/PathName>
00036 
00037 #include <robot/KinematicChain>
00038 #include <robot/sim/TestBasicEnvironment>
00039 #include <robot/sim/SimulatedBasicEnvironment>
00040 #include <robot/control/kinematics/InverseKinematicsSolver>
00041 #include <robot/control/kinematics/FullSpaceSolver>
00042 #include <robot/control/kinematics/BetaFormConstraints>
00043 #include <robot/control/kinematics/IKOR>
00044 
00045 #include <set>
00046 
00047 
00048 namespace robot {
00049 namespace sim {
00050 
00051 
00052 /// Test case for the IKOR tester
00053 /// Holds the description of a test to be run for IKOR (and optionally the results) -   
00054 /// environment (robot, tools, obstacles); trajectory sequences etc.
00055 /// \todo later, rather than instantiating a TestBasicEnvironment to externalize in, it should be
00056 ///       left to the tester to instantiate.  This will require an EnvironmentDescription heirarchy
00057 ///       to mirror the Environment classes (in robot::sim)
00058 class IKORTest :  public base::Named, public base::Externalizable, public base::ReferencedObject
00059 {
00060 public:
00061   IKORTest(ref<base::VFile> testSpecification,
00062            ref<base::VFileSystem> fs, ref<base::Cache> cache);
00063 
00064   virtual String className() const { return String("IKORTest"); }
00065 
00066   
00067   /// an individual test 
00068   /// IKORTest comprises a sequence of these Tests.  The environment is persistent
00069   ///  accross the tests
00070   class Test : public base::Named, public base::Externalizable
00071   {
00072   public:
00073     Test(const String& name = "");
00074 
00075     virtual String className() const { return String("Test"); }
00076 
00077     
00078     bool initialConfigSpecified; ///< if true, use q as the initial joint configuration, otherwise use the currrent configuration
00079     base::Vector initq;      ///< initial joint configuration
00080     base::Trajectory traj;   ///< trajectory/path for manipulator to follow
00081 
00082     bool toolAttached;
00083     String toolName;
00084 
00085     Robot::CoordFrame frame;      ///< reference frame of specified the trajectory
00086     bool timeIntervalSpecified;   ///< true if an overriding time interval was specified for the trajectory
00087     Vector timeInterval;
00088 
00089     bool maxdxSpecified;         ///< true if a maximum dx length was specified
00090     Real maxdx;                  ///< maximum value of dx length for any trajectory step
00091 
00092     bool orientationControl;
00093 
00094     bool jointWeightsSpecified;
00095     base::Vector jointWeights;   ///< joint params weights 
00096     
00097     
00098     enum SolutionMethod { PseudoInverse, FullSpace };
00099     
00100     SolutionMethod                                                               solutionMethod;
00101     robot::control::kinematics::InverseKinematicsSolver::OptimizationMethod      optMethod;
00102     robot::control::kinematics::InverseKinematicsSolver::OptimizationCriterion   optCriteria;
00103     robot::control::kinematics::InverseKinematicsSolver::OptimizationConstraints optConstraints; 
00104 
00105     bool resultsPresent; ///< are there test results recorded? (either via externalization input or generated by execution)
00106     
00107     // test output records - all indices correspond (except that qs, xs & times have an extra final element at the end)
00108     array<base::Vector> qs;    ///< test output; sequence of 'joint' parameter vectors
00109     array<base::Vector> xs;    ///< test output; sequence of end-effector positions/orientations
00110     array<base::Vector> dxs;   ///< test output; sequence of end-effector displacements
00111     array<base::Vector> dqs;   ///< test output; sequence of 'joint' parameter displacements
00112     array<base::Time> times;   ///< test output; sequence of times
00113     array<base::Matrix> Js;    ///< test output; sequence of J(q) jacobian matrices
00114     
00115     ManipulatorJointTrajectory jtraj; ///< test output trajectory in 'joint' space (dim is chain.dof() - so also includes any platform dofs)
00116     
00117     bool testCompleted; ///< true if the test completed, fasle if an error occured and only partial results are available
00118     String failureString; ///< if !testCompleted, provides the failure error message
00119     
00120     base::PathName outputFileName; ///< output file specified in testspec file
00121     base::PathName inputFilePath;  ///< path from which testspec was loaded
00122 
00123     
00124     // some display related flags (read/written by test result viewers)
00125     
00126     bool displayRangeSpecified; ///< true if a subrange of the result joint trajectory has been specified for display purposes
00127     Int displayStartIndex , displayEndIndex;
00128     
00129     
00130     
00131     
00132     void saveResult(ref<base::VFileSystem> filesystem, base::PathName alternateOutputFileName = base::PathName());
00133                            
00134     // Externalizable
00135     virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const
00136     { return ( (format=="xml") && (version==1.0) ); }
00137     
00138     virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00139 
00140   };
00141 
00142 
00143 
00144   /// the environment in which tests are performed
00145   ref<BasicEnvironment> getEnvironment() { return env; } 
00146   ref<const BasicEnvironment> getEnvironment() const { return env; } 
00147   void setEnvironment(ref<BasicEnvironment> env);
00148 
00149   /// which robot is to be tested?
00150   ref<Robot> getRobot() { return narrow_ref<Robot>(env->getRobot(testRobotIndex)); }
00151   ref<const Robot> getRobot() const { return narrow_ref<const Robot>(env->getRobot(testRobotIndex)); }
00152   
00153   /// which of the robot's manipulators is to be tested?
00154   Int getManipulatorIndex() const { return testManipulatorIndex; }
00155   
00156   Int numTests() const { return tests.size(); }
00157   Test& getTest(Int index) { Assert(index < numTests()); return tests[index]; }
00158   
00159   /// the VFileSystem path from which the test specification was read
00160   base::PathName getTestInputPath() const { return inputPath; }
00161   
00162   /// save the test and any results 
00163   /// Externalizes the entire IKORTest specification with results (if present)
00164   /// Also, if saveTrajFiles is true, the result trajectory of each test is saved in
00165   ///  a seperate file (per test)
00166   void saveResults(bool saveTrajFiles = true, base::PathName alternateOutputFileName = base::PathName());
00167   
00168 
00169   // some display related flags (read/written by test result viewers)
00170   
00171   bool displayObstacles; ///< true if obstacles are selected for display
00172   bool displayAxes;      ///< true if coordinate axes selected for display
00173   bool displayPlatform;  ///< true if the platform should be displayed
00174   bool displayEEPath;    ///< true if the path of the manip/tool is selected for display
00175   Int  displayStepMod;   ///< only display every nth step (1 for all steps)
00176 
00177   /// camera parameters (as in gfx::LookAtCameraManipulator)
00178   base::Point3 lookAtTarget; 
00179   Real alpha, theta, d;
00180   
00181     
00182   // Externalizable
00183   virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const
00184     { return ( (format=="xml") && (version==1.0) ); }
00185 
00186   virtual void externalize(base::Externalizer& e, String format = "", Real version = 1.0);
00187 
00188 protected:
00189   ref<base::VFileSystem> filesystem;
00190   ref<base::Cache> cache;
00191   ref<SimulatedBasicEnvironment> env;
00192   Int testRobotIndex;       ///< which robot from the environment is used for testing 
00193   Int testManipulatorIndex; ///< which manipulator (in case the robot has multiple) is used for testing
00194 
00195 
00196   array<Test> tests;
00197   base::PathName inputPath;
00198 
00199 };
00200 
00201 
00202 } // namespace sim
00203 } // namespace robot
00204 
00205 #endif

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