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

robot/sim/SimulatedSerialManipulator

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: SimulatedSerialManipulator 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.18 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_SIMULATEDSERIALMANIPULATOR_
00026 #define _ROBOT_SIM_SIMULATEDSERIALMANIPULATOR_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <robot/sim/SimulatedKinematicChain>
00031 
00032 #include <physics/SolidSystem>
00033 #include <physics/Solid>
00034 #include <physics/Motor>
00035 #include <physics/Spatial>
00036 #include <physics/SpatialGroup>
00037 #include <physics/CollidableProvider>
00038 #include <physics/CollisionDetector>
00039 #include <physics/CollisionResponseHandler>
00040 
00041 #include <robot/sim/SimulatedManipulatorDescription>
00042 #include <robot/sim/SimulatedTool>
00043 
00044 
00045 namespace robot {
00046 namespace sim {
00047 
00048 /**
00049  * Represents a a simulated manipulator according to a supplied 
00050  * D-H parameter specification.
00051  *  Simulated using gfx/physics.
00052  */
00053 class SimulatedSerialManipulator : public SimulatedKinematicChain
00054 {
00055 public:
00056   SimulatedSerialManipulator(bool dynamic=true);
00057   SimulatedSerialManipulator(ref<physics::SolidSystem> solidSystem, bool dynamic=true);
00058   SimulatedSerialManipulator(ref<const robot::ManipulatorDescription> manipulatorDescription, ref<physics::SolidSystem> solidSystem, bool dynamic=true);
00059 
00060   virtual String className() const { return String("SimulatedSerialManipulator"); }
00061 
00062   virtual void setDynamic(bool enabled) { dynamic = enabled; }
00063   
00064   virtual void setSolidSystem(ref<physics::SolidSystem> solidSystem)
00065     { this->solidSystem = solidSystem; }
00066   
00067   ref<const SimulatedManipulatorDescription> getManipulatorDescription() const { return manipulatorDescr; }
00068 
00069   ref<physics::Solid> getBaseSolid() const  ///< get the Solid for the base link
00070     { return baseSolid; }
00071 
00072   /// Set the force (torque for revolute joints) of joint j (first joint j=1)
00073   void setJointForce(Int j, Real f); 
00074 
00075   /// Set the velocity (ang. velocity for revolute joints) of joint j (first joint j=1)
00076   /** NB: As the simulation is force controlled, this will set the target velocity */
00077   void setJointVel(Int j, Real v, Real maxForce=10.0);
00078   
00079   
00080   /// Set the position (angle for revolute joints) of joint j (first joint j=1)
00081   /** NB: This will instantaneously move the joint to the specified angle - which obviously
00082    *      is not physically realistic.  Consequently, for dynamic simulations, this can
00083    *      cause large forces in the system and possibly numerical instability in the
00084    *      simulation.  It is intended for non-dynamic simulations. 
00085    *  NB: the angle is relative to the theta home position.
00086    */
00087   void setJointPos(Int j, Real p);
00088    
00089    
00090   /// Get the current theta* angle (revolute) or position d (prismatic) of the joint
00091   /** *NB: the angle is relative to the theta home position. */ 
00092   Real getJointPos(Int j) const;     
00093 
00094   /// Get the current joint velocity (ang. velocity for revolute joints)
00095   Real getJointVel(Int j) const;
00096 
00097   base::Point3 getEEPosition() const;    ///< end-effector position in WorldFrame
00098   base::Orient getEEOrientation() const; ///< end-effector orientation in WorldFrame
00099 
00100 
00101   /// test if tool is in position to be grasped by the end-effector.
00102   bool checkProximity(ref<SimulatedTool> tool);
00103 
00104   /// get the last tool passed to checkProximity() that was in proximity to the end-effector (or 0)
00105   ref<SimulatedTool> getToolInProximity() const { return proximityTool; }
00106 
00107   /// returns true if a tool is currently being grasped
00108   bool isToolGrasped() const { return toolGrasped; }
00109 
00110   /// grasp tool (if a suitable one is within grasping proximity of the end-effector)
00111   ///  returns true if a tool was grasped
00112   bool graspTool();
00113 
00114   /// release grasp
00115   void releaseGrasp();
00116 
00117 
00118   // Proximity sensor methods
00119   
00120   /// get distance to closest object detected by proximity sensors on the link
00121   Real    getClosestObjectDistance(Int link) const;
00122   
00123   /// get the direction vector to the closest object detected by proximity sensors on the link
00124   Vector3 getClosestObjectDirection(Int link) const;
00125   
00126   /// get the distance along the link x-axis of the proximity sensor that detected the closest object to the link
00127   Real    getClosestObjectSensorPosition(Int link) const;
00128 
00129   
00130 
00131   // Spatial
00132   virtual void   setPosition(const Point3& pos);
00133   virtual Point3 getPosition() const;
00134   virtual void   setOrientation(const Orient& orient);
00135   virtual Orient getOrientation() const;
00136   virtual void   setConfiguration(const base::Transform& configuration);
00137   virtual base::Transform getConfiguration() const;
00138   
00139   // CollidableProvider
00140   virtual ref<physics::Collidable> createCollidable(CollidableFlags flags = 0);
00141 
00142   // Externalizable
00143   virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const; ///< query if specific format is supported (for input, output or both)
00144   virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0); ///< read or write object state to Externalizer
00145   virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0) const
00146     { Externalizable::externalize(e,format,version); }
00147 
00148 protected:
00149   SimulatedSerialManipulator(const SimulatedSerialManipulator& sm) { Unimplemented; }
00150 
00151   ref<const SimulatedManipulatorDescription> manipulatorDescr;
00152 
00153   /// construct an approximation of the manipulator from the D-H parameters (best we can do) 
00154   void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation);
00155 
00156   /// compute the dimensions of each link's Solid based on the KinematicChain
00157   ///  and fill in linkLengths[]
00158   array<base::Dimension3> computeLinkDimensions(const array<Real>& linkRadii);
00159   
00160   
00161   /// compute transform information for chain
00162   TransformInfo computeLinkTransforms(const Transform& mountTransform, const base::Vector& q) const;
00163 
00164     
00165 
00166   /// create the Solids for each link and assemble them into a Spatial tree (and add them to solidSystem)
00167   virtual void createLinks(const array<base::Dimension3>& linkDims);
00168                  
00169   /// position the links 
00170   virtual void positionLinks(const TransformInfo& transformInfo);
00171                      
00172   virtual void disableCollisions(const array<ref<physics::Collidable> >& collidables,
00173                          const array<ref<physics::Collidable> >& proximityCollidables);
00174                      
00175   virtual void attachJoints(const TransformInfo& transformInfo);
00176 
00177   
00178   void setToolInProximity(ref<SimulatedTool> tool) { proximityTool = tool; }
00179 
00180   virtual void handleCollision(ref<physics::CollisionState> collisionState);  ///< called from ProximityCollisionResponseHandler::handleCollision()
00181 
00182   
00183   mutable Transform mountConfiguration; ///< the mount configuration of the manipulator (WorldFrame)
00184   Transform mountToBaseSolid;  ///< transform from mount frame to base Solid frame
00185   Transform eeToEESolid;       ///< transform from ee frame to ee Solid frame
00186 
00187   ref<physics::Solid> baseSolid; ///< Solid for the base link
00188   ref<physics::Solid> endSolid;  ///< Solid for the end link
00189 
00190   array<ref<physics::SpatialGroup> > linkGroups;   ///< a group for each link (which contains the link Solid and the group for the next link)
00191 
00192 
00193   Real proximityDistance; ///< distance between ee and tool below which is considered within grasping proximity
00194   Real proximityAngle;    ///< anglular distance components between ee and tool below which is considered within grasping range
00195 
00196   ref<SimulatedTool> proximityTool; ///< last tool found to be in proximity of the end-effector (by checkProximity())
00197   bool toolGrasped;
00198 
00199   
00200   friend class SimulatedRobot;
00201   friend class ProximityCollisionResponseHandler;
00202   friend class base::Serializable::SerializableDerivedInstantiator<SimulatedSerialManipulator>;
00203 };
00204 
00205 
00206 
00207 }
00208 } // robot::sim
00209 
00210 #endif

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