ODEPhysics.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 _ODEPHYSICS_HH_
18 #define _ODEPHYSICS_HH_
19 
20 #include <tbb/spin_mutex.h>
21 #include <tbb/concurrent_vector.h>
22 #include <string>
23 #include <utility>
24 
25 #include <boost/thread/thread.hpp>
26 
31 #include "gazebo/physics/Shape.hh"
32 #include "gazebo/gazebo_config.h"
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace physics
38  {
39  class ODEJointFeedback;
40  class ODEPhysicsPrivate;
41 
46 
48  class GZ_PHYSICS_VISIBLE ODEPhysics : public PhysicsEngine
49  {
52  public: enum ODEParam
53  {
56 
59 
62 
65 
68 
70  SOR,
71 
74 
77 
80 
83 
87 
90 
92  WORLD_SOLVER_TYPE
93  };
94 
97  public: explicit ODEPhysics(WorldPtr _world);
98 
100  public: virtual ~ODEPhysics();
101 
102  // Documentation inherited
103  public: virtual void Load(sdf::ElementPtr _sdf);
104 
105  // Documentation inherited
106  public: virtual void Init();
107 
108  // Documentation inherited
109  public: virtual void Reset();
110 
111  // Documentation inherited
112  public: virtual void InitForThread();
113 
114  // Documentation inherited
115  public: virtual void UpdateCollision();
116 
117  // Documentation inherited
118  public: virtual void UpdatePhysics();
119 
120  // Documentation inherited
121  public: virtual void Fini();
122 
123  // Documentation inherited
124  public: virtual std::string GetType() const
125  { return "ode"; }
126 
127  // Documentation inherited
128  public: virtual LinkPtr CreateLink(ModelPtr _parent);
129 
130  // Documentation inherited
131  public: virtual CollisionPtr CreateCollision(
132  const std::string &_shapeType, LinkPtr _parent);
133 
134  // Documentation inherited
135  public: virtual ShapePtr CreateShape(const std::string &_shapeType,
136  CollisionPtr _collision);
137 
138  // Documentation inherited
139  public: virtual JointPtr CreateJoint(const std::string &_type,
140  ModelPtr _parent);
141 
142  // Documentation inherited
143  public: virtual void SetGravity(const ignition::math::Vector3d &_gravity);
144 
145  // Documentation inherited
146  public: virtual void SetWorldCFM(double cfm);
147 
148  // Documentation inherited
149  public: virtual void SetWorldERP(double erp);
150 
151  // Documentation inherited
152  public: virtual void SetSORPGSPreconIters(unsigned int iters);
153 
154  // Documentation inherited
155  public: virtual void SetSORPGSIters(unsigned int iters);
156 
157  // Documentation inherited
158  public: virtual void SetSORPGSW(double w);
159 
160  // Documentation inherited
161  public: virtual void SetContactMaxCorrectingVel(double vel);
162 
163  // Documentation inherited
164  public: virtual void SetContactSurfaceLayer(double layer_depth);
165 
168  public: virtual void SetFrictionModel(const std::string &_fricModel);
169 
172  public: virtual void
173  SetWorldStepSolverType(const std::string &_worldSolverType);
174 
175  // Documentation inherited
176  public: virtual void SetMaxContacts(unsigned int max_contacts);
177 
178  // Documentation inherited
179  public: virtual double GetWorldCFM();
180 
181  // Documentation inherited
182  public: virtual double GetWorldERP();
183 
184  // Documentation inherited
185  public: virtual int GetSORPGSPreconIters();
186 
187  // Documentation inherited
188  public: virtual int GetSORPGSIters();
189 
190  // Documentation inherited
191  public: virtual double GetSORPGSW();
192 
193  // Documentation inherited
194  public: virtual double GetContactMaxCorrectingVel();
195 
198  public: virtual std::string GetFrictionModel() const;
199 
202  public: virtual std::string GetWorldStepSolverType() const;
203 
204  // Documentation inherited
205  public: virtual double GetContactSurfaceLayer();
206 
207  // Documentation inherited
208  public: virtual unsigned int GetMaxContacts();
209 
210  // Documentation inherited
211  public: virtual void DebugPrint() const;
212 
213  // Documentation inherited
214  public: virtual void SetSeed(uint32_t _seed);
215 
217  public: virtual bool SetParam(const std::string &_key,
218  const boost::any &_value);
219 
221  public: virtual boost::any GetParam(const std::string &_key) const;
222 
224  public: virtual bool GetParam(const std::string &_key,
225  boost::any &_value) const;
226 
229  public: dSpaceID GetSpaceId() const;
230 
233  public: dWorldID GetWorldId();
234 
238  public: static void ConvertMass(InertialPtr _interial, void *_odeMass);
239 
244  public: static void ConvertMass(void *_odeMass, InertialPtr _inertial);
245 
250  public: static Friction_Model
251  ConvertFrictionModel(const std::string &_fricModel);
252 
257  public: static std::string
258  ConvertFrictionModel(const Friction_Model _fricModel);
259 
264  public: static std::string
265  ConvertWorldStepSolverType(const World_Solver_Type _solverType);
266 
271  public: static World_Solver_Type
272  ConvertWorldStepSolverType(const std::string &_solverType);
273 
276  public: virtual std::string GetStepType() const;
277 
280  public: virtual void SetStepType(const std::string &_type);
281 
282 
287  public: void Collide(ODECollision *_collision1, ODECollision *_collision2,
288  dContactGeom *_contactCollisions);
289 
292  public: void ProcessJointFeedback(ODEJointFeedback *_feedback);
293 
294  protected: virtual void OnRequest(ConstRequestPtr &_msg);
295 
296  protected: virtual void OnPhysicsMsg(ConstPhysicsPtr &_msg);
297 
302  private: static void CollisionCallback(void *_data, dGeomID _o1,
303  dGeomID _o2);
304 
305 
309  private: void AddTrimeshCollider(ODECollision *_collision1,
310  ODECollision *_collision2);
311 
315  private: void AddCollider(ODECollision *_collision1,
316  ODECollision *_collision2);
317 
320  private: ODEPhysicsPrivate *dataPtr;
321  };
323  }
324 }
325 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Constraint force mixing.
Definition: ODEPhysics.hh:58
Minimum step size.
Definition: ODEPhysics.hh:82
Base class for all ODE collisions.
Definition: ODECollision.hh:40
Base class for a physics engine.
Definition: PhysicsEngine.hh:41
Limit ratios of inertias of adjacent links (note that the corresponding SDF tag is "use_dynamic_moi_r...
Definition: ODEPhysics.hh:86
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
ODE physics engine.
Definition: ODEPhysics.hh:48
ODEParam
ODE Physics parameter types.
Definition: ODEPhysics.hh:52
Surface layer depth.
Definition: ODEPhysics.hh:76
SOR over-relaxation parameter.
Definition: ODEPhysics.hh:70
Error reduction parameter.
Definition: ODEPhysics.hh:61
friction model
Definition: ODEPhysics.hh:89
virtual std::string GetType() const
Return the physics engine type (ode|bullet|dart|simbody).
Definition: ODEPhysics.hh:124
Number of iterations.
Definition: ODEPhysics.hh:64
boost::shared_ptr< Inertial > InertialPtr
Definition: PhysicsTypes.hh:157
Number of iterations.
Definition: ODEPhysics.hh:67
ODE wrapper forward declarations and typedefs.
boost::shared_ptr< Shape > ShapePtr
Definition: PhysicsTypes.hh:141
Max correcting velocity.
Definition: ODEPhysics.hh:73
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Maximum number of contacts.
Definition: ODEPhysics.hh:79
boost::shared_ptr< Collision > CollisionPtr
Definition: PhysicsTypes.hh:113
Solve type.
Definition: ODEPhysics.hh:55