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

robot/sim/SimulatedPlatform

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: SimulatedPlatform 1033 2004-02-11 20:47:52Z jungd $
00019   $Revision: 1.11 $
00020   $Date: 2004-02-11 15:47:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SIM_SIMULATEDPLATFORM_
00026 #define _ROBOT_SIM_SIMULATEDPLATFORM_
00027 
00028 #include <robot/sim/sim>
00029 
00030 #include <base/ReferencedObject>
00031 #include <base/Externalizable>
00032 
00033 #include <physics/PositionableOrientable>
00034 #include <physics/Spatial>
00035 #include <physics/SpatialGroup>
00036 #include <physics/SolidSystem>
00037 
00038 #include <robot/PlatformDescription>
00039 
00040 
00041 namespace robot {
00042 namespace sim {
00043 
00044 /**
00045  * A simulated robot platform created
00046  *  according to a supplied specification.
00047  *  Simulated using gfx/physics.
00048  */
00049 class SimulatedPlatform : public physics::Spatial, public physics::CollidableProvider, public base::Externalizable
00050 {
00051 public:
00052   SimulatedPlatform();
00053   SimulatedPlatform(ref<const robot::PlatformDescription> platformDescription, ref<physics::SolidSystem> solidSystem = ref<physics::SolidSystem>(0), bool dynamic=true);
00054   virtual ~SimulatedPlatform();
00055 
00056   virtual String className() const { return String("SimulatedPlatform"); }
00057 
00058   virtual void setDynamic(bool enabled) { dynamic = enabled; }
00059 
00060   void setSolidSystem(ref<physics::SolidSystem> solidSystem) { this->solidSystem = solidSystem; }
00061   
00062   ref<const robot::PlatformDescription> getPlatformDescription() const { return platformDescr; }
00063 
00064   void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation);
00065 
00066   ref<physics::Solid> getPlatformSolid() const { return platformSolids[Platform]; }
00067 
00068   /// Nonholonomic platform - set the torque applied to the left back drive wheel
00069   void setLeftBackWheelTorque(Real t);
00070   /// Nonholonomic platform - set the velocity of the left back drive wheel
00071   void setLeftBackWheelVel(Real v, Real maxTorque=10.0);
00072   /// Nonholonomic platform - get angular velocity of the left back drive wheel
00073   Real getLeftBackWheelVel() const;
00074 
00075   /// Nonholonomic platform - set the torque applied to the right back drive wheel
00076   void setRightBackWheelTorque(Real t);
00077   /// Nonholonomic platform - set the angular velocity of the right back drive wheel
00078   void setRightBackWheelVel(Real v, Real maxTorque=10.0);
00079   /// Nonholonomic platform - get angular velocity of the right back drive wheel
00080   Real getRightBackWheelVel() const;
00081 
00082   /// Nonholonomic platform -  set the torque applied by the front steering motor
00083   void setSteeringTorque(Real t);
00084   /// Nonholonomic platform -  set the angular velocity of the front steering motor
00085   void setSteeringVel(Real v, Real maxTorque=10.0);
00086   /// Nonholonomic platform - get angle of the steering wheels
00087   Real getSteeringAngle() const;
00088 
00089   
00090   // Spatial
00091   virtual void   setPosition(const Point3& pos);
00092   virtual Point3 getPosition() const;
00093   virtual void   setOrientation(const Orient& orient);
00094   virtual Orient getOrientation() const;
00095   virtual void   setConfiguration(const base::Transform& configuration);
00096   virtual base::Transform getConfiguration() const;
00097   
00098   // CollidableProvider
00099   virtual ref<physics::Collidable> createCollidable(CollidableFlags flags = 0);
00100 
00101   // Externalizable
00102   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)
00103   virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0); ///< read or write object state to Externalizer
00104 
00105 protected:
00106   
00107   ref<physics::SolidSystem> solidSystem;
00108   ref<const robot::PlatformDescription> platformDescr;
00109   
00110   /// if true, full physics is simulated; if false, the Solids that comprise the Platform aren't connected together (& only their pos/orient is significant)
00111   bool dynamic;
00112 
00113   enum PlatformSolids { Platform, 
00114                         LeftFrontWheel, RightFrontWheel, 
00115                         LeftBackWheel,  RightBackWheel,
00116                         LeftFrontWheelMount, RightFrontWheelMount,
00117                         Crossbar, 
00118                         MaxPlatformSolids };
00119                        
00120   array<ref<physics::Solid> > platformSolids;  ///< Solids that comprise the platform, indexed by PlatformSolids enum
00121   
00122   ref<physics::SpatialGroup> spatialGroup;   ///< all the Spatials that comprise the platform (e.g. the Solids)
00123   void updateGroupConfigurationFromPlatformSolid() const;
00124   
00125   void disableCollisions(const array<ref<physics::Collidable> >& collidables);
00126   
00127   // only relevant if dynamic==true
00128   ref<physics::ConstraintGroup> wheelConstraintGroup;
00129   ref<physics::HingeJoint> leftDriveHingeJoint;
00130   ref<physics::HingeJoint> rightDriveHingeJoint;
00131   ref<physics::HingeJoint> steeringHingeJoint;
00132   ref<physics::Motor> leftDriveMotor;  ///< drive motor for left back wheel of non-holonomic mobile base
00133   ref<physics::Motor> rightDriveMotor; ///< drive motor for right back wheel of non-holonomic mobile base
00134   ref<physics::Motor> steeringMotor;   ///< steering motor for front wheels of non-holonomic mobile base
00135 };
00136 
00137 
00138 }
00139 } // robot::sim
00140 
00141 #endif

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