PhysicsEngine.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* Desc: The base class for all physics engines 00018 * Author: Nate Koenig 00019 */ 00020 00021 #ifndef PHYSICSENGINE_HH 00022 #define PHYSICSENGINE_HH 00023 00024 #include "common/Event.hh" 00025 #include "common/CommonTypes.hh" 00026 #include "msgs/msgs.h" 00027 #include "transport/TransportTypes.hh" 00028 #include "physics/PhysicsTypes.hh" 00029 #include <boost/thread/recursive_mutex.hpp> 00030 00031 namespace gazebo 00032 { 00033 namespace physics 00034 { 00037 00039 class PhysicsEngine 00040 { 00043 public: PhysicsEngine(WorldPtr world); 00044 00046 public: virtual ~PhysicsEngine(); 00047 00050 public: virtual void Load( sdf::ElementPtr _sdf ) = 0; 00051 00053 public: virtual void Init() = 0; 00054 00056 public: virtual void Fini(); 00057 00058 public: virtual void Reset() {} 00059 00061 public: virtual void InitForThread() = 0; 00062 00064 public: virtual void UpdateCollision() = 0; 00065 00067 public: virtual void SetUpdateRate(double _value) = 0; 00068 00070 public: virtual double GetUpdateRate() = 0; 00071 public: virtual double GetUpdatePeriod() = 0; 00072 00074 public: virtual void SetStepTime(double _value) = 0; 00075 00077 public: virtual double GetStepTime() = 0; 00078 00080 public: virtual void UpdatePhysics() {} 00081 00083 public: virtual LinkPtr CreateLink(ModelPtr _parent) = 0; 00084 00086 public: virtual CollisionPtr CreateCollision( 00087 const std::string &_shapeType, LinkPtr _body) = 0; 00088 00089 public: virtual ShapePtr CreateShape( 00090 const std::string &_shapeType, 00091 CollisionPtr _collision) = 0; 00092 00094 public: virtual JointPtr CreateJoint(const std::string &type) = 0; 00095 00098 public: math::Vector3 GetGravity() const; 00099 00101 public: virtual void SetGravity(const gazebo::math::Vector3 &gravity) = 0; 00102 00104 public: void ShowContacts(const bool &show); 00105 00107 public: virtual void SetWorldCFM(double /*cfm_*/) {} 00109 public: virtual void SetWorldERP(double /*erp_*/) {} 00111 public: virtual void SetAutoDisableFlag(bool /*autoDisable_*/) {} 00113 public: virtual void SetSORPGSIters(unsigned int /*iters_*/) {} 00115 public: virtual void SetSORPGSW(double /*w_*/) {} 00117 public: virtual void SetContactMaxCorrectingVel(double /*vel_*/) {} 00119 public: virtual void SetContactSurfaceLayer(double /*layerDepth_*/) {} 00121 public: virtual void SetMaxContacts(double /*maxContacts_*/) {} 00122 00124 public: virtual double GetWorldCFM() {return 0;} 00126 public: virtual double GetWorldERP() {return 0;} 00128 public: virtual bool GetAutoDisableFlag() {return 0;} 00130 public: virtual int GetSORPGSIters() {return 0;} 00132 public: virtual double GetSORPGSW() {return 0;} 00134 public: virtual double GetContactMaxCorrectingVel() {return 0;} 00136 public: virtual double GetContactSurfaceLayer() {return 0;} 00138 public: virtual int GetMaxContacts() {return 0;} 00139 00140 public: boost::recursive_mutex* GetRayMutex() const 00141 { return this->rayMutex; } 00142 00143 protected: virtual void OnRequest( 00144 ConstRequestPtr &/*_msg*/ ) 00145 {} 00146 00147 protected: virtual void OnPhysicsMsg( 00148 ConstPhysicsPtr &/*_msg*/ ) 00149 {} 00150 00151 00152 00153 protected: WorldPtr world; 00154 protected: sdf::ElementPtr sdf; 00155 00156 protected: transport::NodePtr node; 00157 protected: transport::PublisherPtr responsePub; 00158 protected: transport::SubscriberPtr physicsSub, requestSub; 00159 protected: boost::recursive_mutex *rayMutex; 00160 00161 public: std::map<LinkPtr,LinkPtr> contactPairs; 00162 public: void AddLinkPair(LinkPtr link1, LinkPtr link2) 00163 { 00164 // keep a map of both directions, easier to search later 00165 if (this->contactPairs.find(link1) == this->contactPairs.end()) 00166 this->contactPairs.insert(std::make_pair(link1,link2)); 00167 if (this->contactPairs.find(link2) == this->contactPairs.end()) 00168 this->contactPairs.insert(std::make_pair(link2,link1)); 00169 }; 00170 public: bool AreTouching(LinkPtr link1, LinkPtr link2) 00171 { 00172 if ((this->contactPairs.find(link1) == this->contactPairs.end() || 00173 this->contactPairs.find(link1)->second != link2) && 00174 (this->contactPairs.find(link2) == this->contactPairs.end() || 00175 this->contactPairs.find(link2)->second != link1)) 00176 return false; 00177 else 00178 return true; 00179 }; 00180 }; 00181 00183 } 00184 00185 } 00186 #endif

1.7.5.1