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

robot/sim/SimulatedKinematicChain

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2002 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: SimulatedKinematicChain 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_SIMULATEDKINEMATICCHAIN_
00026 #define _ROBOT_SIM_SIMULATEDKINEMATICCHAIN_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <base/ReferencedObject>
00031 #include <base/Dimension3>
00032 #include <base/Externalizable>
00033 
00034 #include <physics/SolidSystem>
00035 #include <physics/Solid>
00036 #include <physics/SpatialGroup>
00037 #include <physics/CollidableProvider>
00038 #include <physics/CollisionDetector>
00039 #include <physics/CollisionResponseHandler>
00040 
00041 #include <robot/KinematicChain>
00042 
00043 
00044 namespace robot {
00045 namespace sim {
00046 
00047 /**
00048  * Base for concrete classes that simulate kinematic chains
00049  *  - such as manipulators and tools 
00050  */
00051 class SimulatedKinematicChain : public physics::Spatial, public physics::CollidableProvider, public base::Externalizable
00052 {
00053 public:
00054   SimulatedKinematicChain(bool dynamic=true) 
00055     : dynamic(dynamic) {}
00056   SimulatedKinematicChain(ref<physics::SolidSystem> solidSystem, bool dynamic=true) 
00057     : solidSystem(solidSystem), dynamic(dynamic) {}
00058   
00059 
00060   virtual void setDynamic(bool enabled) { dynamic = enabled; }
00061   
00062   virtual void setSolidSystem(ref<physics::SolidSystem> solidSystem)
00063     { this->solidSystem = solidSystem; }
00064   
00065   /// Set the force (torque for revolute joints) of joint j (first joint j=1)
00066   virtual void setJointForce(Int j, Real f) = 0;
00067 
00068   /// Set the velocity (ang. velocity for revolute joints) of joint j (first joint j=1)
00069   /** NB: As the simulation is force controlled, this will set the target velocity */
00070   virtual void setJointVel(Int j, Real v, Real maxForce=10.0) = 0;
00071   
00072   
00073   /// Set the position (angle for revolute joints) of joint j (first joint j=1)
00074   /** NB: This will instantaneously move the joint to the specified angle - which obviously
00075    *      is not physically realistic.  Consequently, for dynamic simulations, this can
00076    *      cause large forces in the system and possibly numerical instability in the
00077    *      simulation.  It is intended for non-dynamic simulations. 
00078    *  NB: the angle is relative to the theta home position.
00079    */
00080   virtual void setJointPos(Int j, Real p) = 0;
00081    
00082    
00083   /// Get the current theta* angle (revolute) or position d (prismatic) of the joint
00084   /** *NB: the angle is relative to the theta home position. */ 
00085   virtual Real getJointPos(Int j) const = 0;
00086 
00087   /// Get the current joint velocity (ang. velocity for revolute joints)
00088   virtual Real getJointVel(Int j) const = 0;
00089 
00090 
00091 
00092   // Proximity sensor methods
00093   
00094   static const Real maxDist;
00095     
00096   /// get distance to closest object detected by proximity sensors on the link
00097   virtual Real    getClosestObjectDistance(Int link) const = 0;
00098   
00099   /// get the direction vector to the closest object detected by proximity sensors on the link
00100   virtual Vector3 getClosestObjectDirection(Int link) const = 0;
00101   
00102   /// get the distance along the link x-axis of the proximity sensor that detected the closest object to the link
00103   virtual Real    getClosestObjectSensorPosition(Int link) const = 0;
00104 
00105 
00106 protected:
00107   SimulatedKinematicChain(const SimulatedKinematicChain& kc) { Unimplemented; }
00108 
00109   KinematicChain chain;
00110   ref<physics::SolidSystem> solidSystem;
00111 
00112   /// true for a dynamic simulation, fasle for static (no force/torque or velocity control, just position control)
00113   bool dynamic; 
00114 
00115   /// construct an approximation of the manipulator from the D-H parameters (best we can do) 
00116   virtual void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation) = 0;
00117 
00118   /// compute the dimensions of each link's Solid based on the KinematicChain
00119   ///  and fill in linkLengths[1..dof]
00120   virtual array<base::Dimension3> computeLinkDimensions(const array<Real>& linkRadii);
00121   
00122   // used to hold temporary transformation result during computation for placement of links
00123   struct TransformInfo {
00124     base::Transform mountTransform; ///< transform from mount point to world frame  
00125     array<base::Transform> A;       ///< transform from link l frame into link l-1 frame 
00126     array<base::Transform> T;       ///< accumulated transformations for each link (transforms from link l frame to mount frame)
00127     array<base::Transform> SLT;     ///< relative configuration of link's Solid from its origin
00128     base::Vector q;                 ///< joint variable parameter value at which A,T,ST were evaluated
00129     base::Transform mountToBaseSolid;  ///< transform from mount frame to base Solid frame
00130     base::Transform eeToEESolid;       ///< transform from ee frame to ee Solid frame
00131   };
00132   
00133 
00134   /// create the Solids for each link and assemble them into a Spatial tree (and add them to solidSystem)
00135   virtual void createLinks(const array<base::Dimension3>& linkDims) = 0;
00136                  
00137   /// position the links 
00138   virtual void positionLinks(const TransformInfo& transformInfo) = 0;
00139                      
00140   virtual void disableCollisions(const array<ref<physics::Collidable> >& collidables,
00141                                  const array<ref<physics::Collidable> >& proximityCollidables) = 0;
00142                      
00143   virtual void attachJoints(const TransformInfo& transformInfo) = 0;
00144 
00145   array<ref<physics::SpatialGroup> > linkGroups;   ///< a group for each link (which contains the link Solid and the group for the next link)
00146 
00147   array<ref<physics::Solid> > links;   ///< Solids for each link
00148   array<ref<physics::Joint> > joints;  ///< Joint attaching each pair of consecutive links (dynamic simulation only)
00149   array<Real> linkLengths;             ///< Length of each link corresponding with links[]
00150   array<ref<physics::Collidable> > collidables;          ///< collidables for each link Solid
00151   array<ref<physics::Collidable> > proximityCollidables; ///< collidables for each link's proximity sensor
00152 
00153   mutable base::Vector q; ///< current joint parameters (static simulation only)
00154   
00155   
00156   // this CollisionResponseHandler is inserted before the final handler to 
00157   //  filter out collisions between the proximity sensor Collidables and
00158   //  handle them appropriately
00159   class ProximityCollisionResponseHandler : public physics::CollisionResponseHandler
00160   {
00161   public:
00162     ProximityCollisionResponseHandler(ref<SimulatedKinematicChain> kc, ref<physics::CollisionDetector> collisionDetector);
00163 
00164     virtual String className() const { return String("ProximityCollisionResponseHandler"); }
00165     
00166     virtual void reset();
00167     virtual void collide(ref<const physics::Collidable> collidable1, ref<const physics::Collidable> collidable2);
00168     virtual void handleCollision(ref<physics::CollisionState> collisionState); ///< calls KinematicChain::handleCollision()
00169     
00170     protected:
00171       ref<SimulatedKinematicChain> kc;
00172       bool resetCalled;
00173   };
00174 
00175   virtual void handleCollision(ref<physics::CollisionState> collisionState) = 0;  ///< called from ProximityCollisionResponseHandler::handleCollision()
00176   
00177   enum CollidableClasses { SensorCollidableClass = 1 };
00178   
00179   ref<physics::CollidableGroup> proximityCollidableGroup;
00180   
00181   struct ProximityData {
00182     ProximityData() : dist(SimulatedKinematicChain::maxDist+1.0) {}
00183     ProximityData(Real dist, Real intersect, const Vector3& dir)
00184       : dist(dist), intersect(intersect), dir(dir) {}
00185     
00186     Real    dist;      ///< distance to object (> maxInt => no object in proximity)
00187     Real    intersect; ///< distance along link x-axis of sensor
00188     Vector3 dir;       ///< direction of object from sensor
00189   };
00190   
00191   array< ProximityData > linkProximity; 
00192   // !!! this assumes cylindrical/capsule surface
00193   array< Real > linkProximitySurfPosition;     ///< dist from link axis of proximity sensor (i.e. on link sufrace)
00194   
00195   friend class SimulatedRobot;
00196   friend class ProximityCollisionResponseHandler;
00197 };
00198 
00199 
00200 
00201 }
00202 } // robot::sim
00203 
00204 #endif

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