PhysicsEngine.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 #include <ignition/transport/Node.hh>
23 
25 #include "gazebo/math/Vector3.hh"
26 #include "gazebo/msgs/msgs.hh"
27 
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
33  namespace physics
34  {
35  class ContactManager;
36 
39 
42  class GZ_PHYSICS_VISIBLE PhysicsEngine
43  {
46  public: explicit PhysicsEngine(WorldPtr _world);
47 
49  public: virtual ~PhysicsEngine();
50 
53  public: virtual void Load(sdf::ElementPtr _sdf);
54 
56  public: virtual void Init() = 0;
57 
59  public: virtual void Fini();
60 
62  public: virtual void Reset() {}
63 
65  public: virtual void InitForThread() = 0;
66 
68  public: virtual void UpdateCollision() = 0;
69 
72  public: virtual std::string GetType() const = 0;
73 
76  public: virtual void SetSeed(uint32_t _seed) = 0;
77 
80  public: double GetUpdatePeriod();
81 
84  public: double GetTargetRealTimeFactor() const;
85 
88  public: double GetRealTimeUpdateRate() const;
89 
92  public: double GetMaxStepSize() const;
93 
96  public: void SetTargetRealTimeFactor(double _factor);
97 
100  public: void SetRealTimeUpdateRate(double _rate);
101 
104  public: void SetMaxStepSize(double _stepSize);
105 
107  public: virtual void UpdatePhysics() {}
108 
111  public: virtual ModelPtr CreateModel(BasePtr _base);
112 
115  public: virtual LinkPtr CreateLink(ModelPtr _parent) = 0;
116 
120  public: virtual CollisionPtr CreateCollision(
121  const std::string &_shapeType, LinkPtr _link) = 0;
122 
126  public: CollisionPtr CreateCollision(const std::string &_shapeType,
127  const std::string &_linkName);
128 
132  public: virtual ShapePtr CreateShape(const std::string &_shapeType,
133  CollisionPtr _collision) = 0;
134 
138  public: virtual JointPtr CreateJoint(const std::string &_type,
139  ModelPtr _parent = ModelPtr()) = 0;
140 
144  public: virtual math::Vector3 GetGravity() const GAZEBO_DEPRECATED(8.0);
145 
149  public: virtual void SetGravity(
150  const gazebo::math::Vector3 &_gravity) GAZEBO_DEPRECATED(8.0);
151 
154  public: virtual void SetGravity(
155  const ignition::math::Vector3d &_gravity) = 0;
156 
160  public: virtual ignition::math::Vector3d MagneticField() const
161  GAZEBO_DEPRECATED(8.0);
162 
167  public: virtual void SetAutoDisableFlag(bool _autoDisable);
168 
173  public: virtual void SetMaxContacts(unsigned int _maxContacts);
174 
179  public: virtual bool GetAutoDisableFlag() {return 0;}
180 
212  public: virtual bool SetParam(const std::string &_key,
213  const boost::any &_value);
214 
219  public: virtual boost::any GetParam(const std::string &_key) const;
220 
226  public: virtual bool GetParam(const std::string &_key,
227  boost::any &_value) const;
228 
230  public: virtual void DebugPrint() const = 0;
231 
234  public: WorldPtr World() const;
235 
238  public: ContactManager *GetContactManager() const;
239 
242  public: boost::recursive_mutex *GetPhysicsUpdateMutex() const
243  {return this->physicsUpdateMutex;}
244 
247  public: sdf::ElementPtr GetSDF() const;
248 
251  protected: virtual void OnRequest(ConstRequestPtr &_msg);
252 
255  protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg);
256 
258  protected: WorldPtr world;
259 
261  protected: sdf::ElementPtr sdf;
262 
265 
268 
271 
274 
276  protected: boost::recursive_mutex *physicsUpdateMutex;
277 
281 
283  protected: double realTimeUpdateRate;
284 
286  protected: double targetRealTimeFactor;
287 
289  protected: double maxStepSize;
290 
291  // Place ignition::transport objects at the end of this file to
292  // guarantee they are destructed first.
293 
295  protected: ignition::transport::Node nodeIgn;
296 
298  protected: ignition::transport::Node::Publisher responsePubIgn;
299  };
301  }
302 }
303 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
sdf::ElementPtr sdf
Our SDF values.
Definition: PhysicsEngine.hh:261
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
ignition::transport::Node::Publisher responsePubIgn
Response publisher.
Definition: PhysicsEngine.hh:298
Forward declarations for the common classes.
Definition: Animation.hh:33
boost::recursive_mutex * GetPhysicsUpdateMutex() const
returns a pointer to the PhysicsEngine::physicsUpdateMutex.
Definition: PhysicsEngine.hh:242
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
ContactManager * contactManager
Class that handles all contacts generated by the physics engine.
Definition: PhysicsEngine.hh:280
Base class for a physics engine.
Definition: PhysicsEngine.hh:42
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
transport::SubscriberPtr physicsSub
Subscribe to the physics topic.
Definition: PhysicsEngine.hh:270
virtual bool GetAutoDisableFlag()
: Remove this function, and replace it with a more generic property map
Definition: PhysicsEngine.hh:179
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
transport::SubscriberPtr requestSub
Subscribe to the request topic.
Definition: PhysicsEngine.hh:273
default namespace for gazebo
virtual void Reset()
Rest the physics engine.
Definition: PhysicsEngine.hh:62
The world provides access to all other object within a simulated environment.
Definition: World.hh:81
double realTimeUpdateRate
Real time update rate.
Definition: PhysicsEngine.hh:283
WorldPtr world
Pointer to the world.
Definition: PhysicsEngine.hh:258
ignition::transport::Node nodeIgn
Ignition node for communication.
Definition: PhysicsEngine.hh:295
double targetRealTimeFactor
Target real time factor.
Definition: PhysicsEngine.hh:286
virtual void UpdatePhysics()
Update the physics engine.
Definition: PhysicsEngine.hh:107
transport::PublisherPtr responsePub
Response publisher.
Definition: PhysicsEngine.hh:267
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
boost::shared_ptr< Shape > ShapePtr
Definition: PhysicsTypes.hh:141
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::recursive_mutex * physicsUpdateMutex
Mutex to protect the update cycle.
Definition: PhysicsEngine.hh:276
double maxStepSize
Real time update rate.
Definition: PhysicsEngine.hh:289
transport::NodePtr node
Node for communication.
Definition: PhysicsEngine.hh:264
Aggregates all the contact information generated by the collision detection engine.
Definition: ContactManager.hh:72
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77