BulletPhysics.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 /* Desc: The Bullet physics engine wrapper
18  * Author: Nate Koenig
19  * Date: 11 June 2009
20  */
21 
22 #ifndef BULLETPHYSICS_HH
23 #define BULLETPHYSICS_HH
24 #include <string>
25 
26 #include <boost/thread/thread.hpp>
27 #include <boost/thread/mutex.hpp>
28 
32 #include "gazebo/physics/Shape.hh"
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace physics
38  {
39  class Entity;
40  class XMLConfigNode;
41  class Mass;
42 
47 
49  class GZ_PHYSICS_VISIBLE BulletPhysics : public PhysicsEngine
50  {
53  public: enum BulletParam
54  {
57 
60 
63 
66 
68  SOR,
69 
72 
75 
77  MIN_STEP_SIZE
78  };
79 
81  public: explicit BulletPhysics(WorldPtr _world);
82 
84  public: virtual ~BulletPhysics();
85 
86  // Documentation inherited
87  public: virtual void Load(sdf::ElementPtr _sdf);
88 
89  // Documentation inherited
90  public: virtual void Init();
91 
92  // Documentation inherited
93  public: virtual void Reset();
94 
95  // Documentation inherited
96  public: virtual void InitForThread();
97 
98  // Documentation inherited
99  public: virtual void UpdateCollision();
100 
101  // Documentation inherited
102  public: virtual void UpdatePhysics();
103 
104  // Documentation inherited
105  public: virtual void Fini();
106 
107  // Documentation inherited
108  public: virtual std::string GetType() const
109  { return "bullet"; }
110 
111  // Documentation inherited
112  public: virtual LinkPtr CreateLink(ModelPtr _parent);
113 
114  // Documentation inherited
115  public: virtual CollisionPtr CreateCollision(const std::string &_type,
116  LinkPtr _body);
117 
118  // Documentation inherited
119  public: virtual JointPtr CreateJoint(const std::string &_type,
120  ModelPtr _parent);
121 
122  // Documentation inherited
123  public: virtual ShapePtr CreateShape(const std::string &_shapeType,
124  CollisionPtr _collision);
125 
127  // public: virtual PhysicsRaySensor *CreateRaySensor(Link *body);
128 
129  // Documentation inherited
130  protected: virtual void OnRequest(ConstRequestPtr &_msg);
131 
132  // Documentation inherited
133  protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg);
134 
136  public: virtual void ConvertMass(InertialPtr _inertial,
137  void *_engineMass);
138 
140  public: virtual void ConvertMass(void *_engineMass,
141  InertialPtr _inertial);
142 
143  // Documentation inherited
144  public: virtual void SetGravity(const ignition::math::Vector3d &_gravity);
145 
146  // Documentation inherited
147  public: virtual void SetWorldCFM(double _cfm);
148 
149  // Documentation inherited
150  public: virtual double GetWorldCFM();
151 
152  // Documentation inherited
153  public: virtual void SetSeed(uint32_t _seed);
154 
156  public: btDynamicsWorld *GetDynamicsWorld() const
157  {return this->dynamicsWorld;}
158 
159  public: virtual void DebugPrint() const;
160 
162  public: virtual bool SetParam(const std::string &_key,
163  const boost::any &_value);
164 
166  public: virtual boost::any GetParam(const std::string &_key) const;
167 
169  public: virtual bool GetParam(const std::string &_key,
170  boost::any &_value) const;
171 
172  // Documentation inherited
173  public: virtual void SetSORPGSIters(unsigned int iters);
174 
175  private: btBroadphaseInterface *broadPhase;
176  private: btDefaultCollisionConfiguration *collisionConfig;
177  private: btCollisionDispatcher *dispatcher;
178  private: btSequentialImpulseConstraintSolver *solver;
179  private: btDiscreteDynamicsWorld *dynamicsWorld;
180 
181  private: common::Time lastUpdateTime;
182 
184  private: std::string solverType;
185  };
186 
188  }
189 }
190 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
BulletParam
Bullet physics parameter types.
Definition: BulletPhysics.hh:53
Base class for a physics engine.
Definition: PhysicsEngine.hh:41
Bullet physics engine.
Definition: BulletPhysics.hh:49
Surface layer depth.
Definition: BulletPhysics.hh:71
SOR over-relaxation parameter.
Definition: BulletPhysics.hh:68
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
virtual std::string GetType() const
Return the physics engine type (ode|bullet|dart|simbody).
Definition: BulletPhysics.hh:108
Number of iterations.
Definition: BulletPhysics.hh:65
Solve type.
Definition: BulletPhysics.hh:56
boost::shared_ptr< Inertial > InertialPtr
Definition: PhysicsTypes.hh:157
Maximum number of contacts.
Definition: BulletPhysics.hh:74
btDynamicsWorld * GetDynamicsWorld() const
Register a joint with the dynamics world.
Definition: BulletPhysics.hh:156
Constraint force mixing.
Definition: BulletPhysics.hh:59
boost::shared_ptr< Shape > ShapePtr
Definition: PhysicsTypes.hh:141
Error reduction parameter.
Definition: BulletPhysics.hh:62
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::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44