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

robot/sim/SimulatedTool

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: SimulatedTool 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.7 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_SIMULATEDTOOL_
00026 #define _ROBOT_SIM_SIMULATEDTOOL_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <robot/Robot>
00031 
00032 #include <robot/sim/SimulatedKinematicChain>
00033 
00034 #include <physics/SolidSystem>
00035 #include <physics/Solid>
00036 #include <physics/Spatial>
00037 #include <physics/SpatialGroup>
00038 #include <physics/SpatialTransform>
00039 #include <physics/Motor>
00040 
00041 #include <robot/ToolDescription>
00042 #include <robot/KinematicChain>
00043 
00044 
00045 namespace robot {
00046 namespace sim {
00047 
00048 
00049 /**
00050  * Represents a simulated manipulator tool according to a supplied 
00051  * D-H parameter specification.
00052  *  Simulated using gfx/physics.
00053  */
00054 class SimulatedTool : public SimulatedKinematicChain
00055 {
00056 public:
00057 /*
00058   SimulatedTool(ref<base::VFile> toolSpecification,
00059                     const base::Point3& initialPosition, const base::Orient& initialOrientation,
00060                       ref<physics::SolidSystem> solidSystem, bool dynamic=true);
00061 */                
00062    SimulatedTool(ref<const robot::ToolDescription> toolDescription,
00063                              const base::Point3& initialPosition, const base::Orient& initialOrientation,
00064                              ref<physics::SolidSystem> solidSystem, bool dynamic=true);
00065               
00066   virtual String className() const { return String("SimulatedTool"); }
00067 
00068   virtual void setDynamic(bool enabled) { dynamic = enabled; }
00069 
00070   virtual void setSolidSystem(ref<physics::SolidSystem> solidSystem)
00071     { this->solidSystem = solidSystem; }
00072 
00073   ref<const robot::ToolDescription> getToolDescription() const { return toolDescr; }
00074 
00075   ref<physics::Solid> getFirstLinkSolid() const  ///< get the Solid for first link
00076     { return firstSolid; }
00077     
00078   ref<physics::Collidable> getFirstLinkCollidable() const ///< get the Collidable associated with the first link
00079     { Assert(collidables.size() > 1); return collidables[1]; }
00080 
00081   ref<physics::Collidable> getFirstLinkProximitySensorCollidable() const ///< get the Collidable associated with the first link's proximity sensor
00082     { Assert(proximityCollidables.size() > 1); return proximityCollidables[1]; }
00083 
00084   /// Set the force (torque for revolute joints) of joint j (first joint j=1)
00085   void setJointForce(Int j, Real f); 
00086 
00087   /// Set the velocity (ang. velocity for revolute joints) of joint j (first joint j=1)
00088   /** NB: As the simulation is force controlled, this will set the target velocity */
00089   void setJointVel(Int j, Real v, Real maxForce=10.0);
00090 
00091   /// Set the position (angle for revolute joints) of joint j (first joint j=1)
00092   /** NB: This will instantaneously move the joint to the specified angle - which obviously
00093    *      is not physically realistic.  Consequently, for dynamic simulations, this can
00094    *      cause large forces in the system and possibly numerical instability in the
00095    *      simulation.  It is intended for non-dynamic simulations. 
00096    *  NB: the angle is relative to the theta home position.
00097    */
00098   void setJointPos(Int j, Real p);
00099 
00100 
00101   /// Get the current theta* angle (revolute) or position d (prismatic) of the joint
00102   /** *NB: the angle is relative to the theta home position. */ 
00103   Real getJointPos(Int j) const;     
00104 
00105   /// Get the current joint velocity (ang. velocity for revolute joints)
00106   Real getJointVel(Int j) const;
00107 
00108 
00109   /// attach the base Solid to the specified solid - this is the first joint
00110   void attachTo(ref<physics::Solid> manipEESolid);
00111 
00112   /// detatch base Solid
00113   void detatch();
00114 
00115   
00116   // Proximity sensor methods
00117 
00118   /// get distance to closest object detected by proximity sensors on the link
00119   Real    getClosestObjectDistance(Int link) const;
00120   
00121   /// get the direction vector to the closest object detected by proximity sensors on the link
00122   Vector3 getClosestObjectDirection(Int link) const;
00123   
00124   /// get the distance along the link x-axis of the proximity sensor that detected the closest object to the link
00125   Real    getClosestObjectSensorPosition(Int link) const;
00126   
00127   
00128   // Spatial
00129   virtual void   setPosition(const Point3& pos);
00130   virtual Point3 getPosition() const;
00131   virtual void   setOrientation(const Orient& orient);
00132   virtual Orient getOrientation() const;
00133   virtual void   setConfiguration(const base::Transform& configuration);
00134   virtual base::Transform getConfiguration() const;
00135   
00136   // CollidableProvider
00137   virtual ref<physics::Collidable> createCollidable(CollidableFlags flags = 0);
00138 
00139   // Externalizable
00140   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)
00141   virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0); ///< read or write object state to Externalizer
00142   void externalize(base::Externalizer& e, const String format = "", Real version = 1.0) const
00143     { Externalizable::externalize(e,format,version); }
00144 
00145 protected:
00146   SimulatedTool(const SimulatedTool& st) { Unimplemented; }
00147 
00148   ref<const robot::ToolDescription> toolDescr;
00149 
00150   /// construct an approximation of the tool from the D-H parameters (best we can do) 
00151   void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation);
00152   
00153   
00154   /// compute transform information for chain
00155   TransformInfo computeLinkTransforms(const Transform& mountTransform, const base::Vector& q) const;
00156 
00157 
00158   /// create the Solids for each link and assemble them into a Spatial tree (and add them to solidSystem)
00159   virtual void createLinks(const array<base::Dimension3>& linkDims);
00160                  
00161   /// position the links 
00162   virtual void positionLinks(const TransformInfo& transformInfo);
00163                      
00164   virtual void disableCollisions(const array<ref<physics::Collidable> >& collidables,
00165                                  const array<ref<physics::Collidable> >& proximityCollidables);
00166                      
00167   virtual void attachJoints(const TransformInfo& transformInfo);
00168   
00169   virtual void handleCollision(ref<physics::CollisionState> collisionState);  ///< called from ProximityCollisionResponseHandler::handleCollision()
00170   
00171 
00172   ref<physics::Solid> firstSolid; ///< Solid for the first link
00173   ref<physics::Solid> endSolid;   ///< Solid for the tool end-effector
00174   base::Transform firstLinkSolidToMount;       ///< transform from origin of first link Solid to mount origin
00175   ref<physics::SpatialTransform> mountSpatial; ///< Spatial who's configuration is that of the tool's mount point
00176   ref<physics::SpatialGroup> spatialGroup;     ///< a group containing the Solids
00177   bool attached;                                       ///< is this tool attached to the end-effector of a manipulator?
00178   ref<physics::ConstraintGroup> mountConstraintGroup;  ///< group that holds the joint attaching the tool to the manipulator end-effector (valid if attached is true)
00179 
00180 
00181   friend class SimulatedRobot;
00182   friend class base::Serializable::SerializableDerivedInstantiator<SimulatedTool>;
00183 
00184 };
00185 
00186 
00187 
00188 }
00189 } // robot::sim
00190 
00191 #endif

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