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
33#include "gazebo/util/system.hh"
34
35namespace 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 {
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
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
Bullet physics engine.
Definition BulletPhysics.hh:50
virtual bool GetParam(const std::string &_key, boost::any &_value) const
Documentation inherited.
virtual LinkPtr CreateLink(ModelPtr _parent)
Create a new body.
virtual void ConvertMass(void *_engineMass, InertialPtr _inertial)
Convert a gazebo Mass to a bullet Mass.
virtual void Fini()
Finilize the physics engine.
BulletParam
Bullet physics parameter types.
Definition BulletPhysics.hh:54
@ GLOBAL_CFM
Constraint force mixing.
Definition BulletPhysics.hh:59
@ GLOBAL_ERP
Error reduction parameter.
Definition BulletPhysics.hh:62
@ CONTACT_SURFACE_LAYER
Surface layer depth.
Definition BulletPhysics.hh:71
@ PGS_ITERS
Number of iterations.
Definition BulletPhysics.hh:65
@ SOLVER_TYPE
Solve type.
Definition BulletPhysics.hh:56
@ MIN_STEP_SIZE
Minimum step size.
Definition BulletPhysics.hh:77
@ MAX_CONTACTS
Maximum number of contacts.
Definition BulletPhysics.hh:74
@ SOR
SOR over-relaxation parameter.
Definition BulletPhysics.hh:68
virtual void Init()
Initialize the physics engine.
virtual void Reset()
Rest the physics engine.
virtual ~BulletPhysics()
Destructor.
btDynamicsWorld * GetDynamicsWorld() const
Register a joint with the dynamics world.
Definition BulletPhysics.hh:156
virtual void UpdateCollision()
Update the physics engine collision.
virtual void UpdatePhysics()
Update the physics engine.
virtual void OnRequest(ConstRequestPtr &_msg)
Create a physics based ray sensor.
virtual void ConvertMass(InertialPtr _inertial, void *_engineMass)
Convert a bullet mass to a gazebo Mass.
BulletPhysics(WorldPtr _world)
Constructor.
virtual ShapePtr CreateShape(const std::string &_shapeType, CollisionPtr _collision)
Create a physics::Shape object.
virtual void InitForThread()
Init the engine for threads.
virtual std::string GetType() const
Return the physics engine type (ode|bullet|dart|simbody).
Definition BulletPhysics.hh:108
virtual void SetSORPGSIters(unsigned int iters)
virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg)
virtual callback for gztopic "~/physics".
virtual boost::any GetParam(const std::string &_key) const
Documentation inherited.
virtual void SetGravity(const ignition::math::Vector3d &_gravity)
Set the gravity vector.
virtual CollisionPtr CreateCollision(const std::string &_type, LinkPtr _body)
Create a collision.
virtual void DebugPrint() const
Debug print out of the physic engine state.
virtual void Load(sdf::ElementPtr _sdf)
Load the physics engine.
virtual void SetWorldCFM(double _cfm)
virtual bool SetParam(const std::string &_key, const boost::any &_value)
Documentation inherited.
virtual void SetSeed(uint32_t _seed)
Set the random number seed for the physics engine.
virtual JointPtr CreateJoint(const std::string &_type, ModelPtr _parent)
Create a new joint.
Base class for a physics engine.
Definition PhysicsEngine.hh:42
boost::shared_ptr< Link > LinkPtr
Definition PhysicsTypes.hh:109
boost::shared_ptr< Inertial > InertialPtr
Definition PhysicsTypes.hh:157
boost::shared_ptr< Collision > CollisionPtr
Definition PhysicsTypes.hh:113
boost::shared_ptr< Shape > ShapePtr
Definition PhysicsTypes.hh:141
boost::shared_ptr< World > WorldPtr
Definition PhysicsTypes.hh:89
boost::shared_ptr< Model > ModelPtr
Definition PhysicsTypes.hh:93
boost::shared_ptr< Joint > JointPtr
Definition PhysicsTypes.hh:117
Forward declarations for the common classes.
Definition Animation.hh:27