PhysicsEngine.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _PHYSICSENGINE_HH_
18 #define _PHYSICSENGINE_HH_
19 
20 #include <boost/thread/recursive_mutex.hpp>
21 #include <string>
22 
24 #include "gazebo/msgs/msgs.hh"
25 
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace physics
32  {
33  class ContactManager;
34 
37 
41  {
44  public: explicit PhysicsEngine(WorldPtr _world);
45 
47  public: virtual ~PhysicsEngine();
48 
51  public: virtual void Load(sdf::ElementPtr _sdf);
52 
54  public: virtual void Init() = 0;
55 
57  public: virtual void Fini();
58 
60  public: virtual void Reset() {}
61 
63  public: virtual void InitForThread() = 0;
64 
66  public: virtual void UpdateCollision() = 0;
67 
70  public: virtual std::string GetType() const = 0;
71 
74  public: virtual void SetSeed(uint32_t _seed) = 0;
75 
78  public: double GetUpdatePeriod();
79 
82  public: double GetTargetRealTimeFactor() const;
83 
86  public: double GetRealTimeUpdateRate() const;
87 
90  public: double GetMaxStepSize() const;
91 
94  public: void SetTargetRealTimeFactor(double _factor);
95 
98  public: void SetRealTimeUpdateRate(double _rate);
99 
102  public: void SetMaxStepSize(double _stepSize);
103 
105  public: virtual void UpdatePhysics() {}
106 
109  public: virtual ModelPtr CreateModel(BasePtr _base);
110 
113  public: virtual LinkPtr CreateLink(ModelPtr _parent) = 0;
114 
118  public: virtual CollisionPtr CreateCollision(
119  const std::string &_shapeType, LinkPtr _link) = 0;
120 
124  public: CollisionPtr CreateCollision(const std::string &_shapeType,
125  const std::string &_linkName);
126 
130  public: virtual ShapePtr CreateShape(const std::string &_shapeType,
131  CollisionPtr _collision) = 0;
132 
136  public: virtual JointPtr CreateJoint(const std::string &_type,
137  ModelPtr _parent = ModelPtr()) = 0;
138 
141  public: virtual math::Vector3 GetGravity() const;
142 
145  public: virtual void SetGravity(
146  const gazebo::math::Vector3 &_gravity) = 0;
147 
150  public: virtual ignition::math::Vector3d MagneticField() const;
151 
156  public: virtual void SetWorldCFM(double /*_cfm*/)
157  GAZEBO_DEPRECATED(6.0) {}
158 
163  public: virtual void SetWorldERP(double /*_erp*/)
164  GAZEBO_DEPRECATED(6.0) {}
165 
170  public: virtual void SetAutoDisableFlag(bool _autoDisable);
171 
176  public: virtual void SetContactMaxCorrectingVel(double /*_vel*/)
177  GAZEBO_DEPRECATED(6.0) {}
178 
183  public: virtual void SetContactSurfaceLayer(double /*_layerDepth*/)
184  GAZEBO_DEPRECATED(6.0) {}
185 
190  public: virtual void SetMaxContacts(unsigned int _maxContacts);
191 
196  public: virtual double GetWorldCFM() GAZEBO_DEPRECATED(6.0) {return 0;}
197 
202  public: virtual double GetWorldERP() GAZEBO_DEPRECATED(6.0) {return 0;}
203 
208  public: virtual bool GetAutoDisableFlag() {return 0;}
209 
214  public: virtual double GetContactMaxCorrectingVel()
215  GAZEBO_DEPRECATED(6.0) {return 0;}
216 
221  public: virtual double GetContactSurfaceLayer()
222  GAZEBO_DEPRECATED(6.0) {return 0;}
223 
228  public: virtual unsigned int GetMaxContacts() {return 0;}
229 
261  public: virtual bool SetParam(const std::string &_key,
262  const boost::any &_value);
263 
268  public: virtual boost::any GetParam(const std::string &_key) const;
269 
275  public: virtual bool GetParam(const std::string &_key,
276  boost::any &_value) const;
277 
279  public: virtual void DebugPrint() const = 0;
280 
283  public: ContactManager *GetContactManager() const;
284 
287  public: boost::recursive_mutex *GetPhysicsUpdateMutex() const
288  {return this->physicsUpdateMutex;}
289 
292  public: sdf::ElementPtr GetSDF() const;
293 
296  protected: virtual void OnRequest(ConstRequestPtr &_msg);
297 
300  protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg);
301 
303  protected: WorldPtr world;
304 
306  protected: sdf::ElementPtr sdf;
307 
310 
313 
316 
319 
321  protected: boost::recursive_mutex *physicsUpdateMutex;
322 
326 
328  protected: double realTimeUpdateRate;
329 
331  protected: double targetRealTimeFactor;
332 
334  protected: double maxStepSize;
335  };
337  }
338 }
339 #endif
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:68
double realTimeUpdateRate
Real time update rate.
Definition: PhysicsEngine.hh:328
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:84
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
double targetRealTimeFactor
Target real time factor.
Definition: PhysicsEngine.hh:331
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
virtual void UpdatePhysics()
Update the physics engine.
Definition: PhysicsEngine.hh:105
boost::shared_ptr< Shape > ShapePtr
Definition: PhysicsTypes.hh:116
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Base class for a physics engine.
Definition: PhysicsEngine.hh:40
virtual bool GetAutoDisableFlag()
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:208
Forward declarations for transport.
virtual double GetWorldERP() GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:202
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:47
WorldPtr world
Pointer to the world.
Definition: PhysicsEngine.hh:303
virtual double GetWorldCFM() GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:196
sdf::ElementPtr sdf
Our SDF values.
Definition: PhysicsEngine.hh:306
boost::recursive_mutex * physicsUpdateMutex
Mutex to protect the update cycle.
Definition: PhysicsEngine.hh:321
default namespace for gazebo
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:96
transport::SubscriberPtr physicsSub
Subscribe to the physics topic.
Definition: PhysicsEngine.hh:315
virtual void SetContactMaxCorrectingVel(double) GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:176
virtual void SetContactSurfaceLayer(double) GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:183
virtual double GetContactMaxCorrectingVel() GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map.
Definition: PhysicsEngine.hh:214
virtual void Reset()
Rest the physics engine.
Definition: PhysicsEngine.hh:60
transport::SubscriberPtr requestSub
Subscribe to the request topic.
Definition: PhysicsEngine.hh:318
virtual void SetWorldCFM(double) GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:156
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:80
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:100
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::recursive_mutex * GetPhysicsUpdateMutex() const
returns a pointer to the PhysicsEngine::physicsUpdateMutex.
Definition: PhysicsEngine.hh:287
virtual double GetContactSurfaceLayer() GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map.
Definition: PhysicsEngine.hh:221
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
virtual unsigned int GetMaxContacts()
: Remove this function, and replace it with a more generic property map.
Definition: PhysicsEngine.hh:228
virtual void SetWorldERP(double) GAZEBO_DEPRECATED(6.0)
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:163
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
transport::PublisherPtr responsePub
Response publisher.
Definition: PhysicsEngine.hh:312
Aggregates all the contact information generated by the collision detection engine.
Definition: ContactManager.hh:65
double maxStepSize
Real time update rate.
Definition: PhysicsEngine.hh:334
transport::NodePtr node
Node for communication.
Definition: PhysicsEngine.hh:309
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:92
ContactManager * contactManager
Class that handles all contacts generated by the physics engine.
Definition: PhysicsEngine.hh:325