Base class for a physics engine. More...
#include <physics/physics.hh>
Inherited by BulletPhysics, DARTPhysics, ODEPhysics, and SimbodyPhysics.
Public Member Functions | |
PhysicsEngine (WorldPtr _world) | |
Default constructor. More... | |
virtual | ~PhysicsEngine () |
Destructor. More... | |
virtual CollisionPtr | CreateCollision (const std::string &_shapeType, LinkPtr _link)=0 |
Create a collision. More... | |
CollisionPtr | CreateCollision (const std::string &_shapeType, const std::string &_linkName) |
Create a collision. More... | |
virtual JointPtr | CreateJoint (const std::string &_type, ModelPtr _parent=ModelPtr())=0 |
Create a new joint. More... | |
virtual LinkPtr | CreateLink (ModelPtr _parent)=0 |
Create a new body. More... | |
virtual ModelPtr | CreateModel (BasePtr _base) |
Create a new model. More... | |
virtual ShapePtr | CreateShape (const std::string &_shapeType, CollisionPtr _collision)=0 |
Create a physics::Shape object. More... | |
virtual void | DebugPrint () const =0 |
Debug print out of the physic engine state. More... | |
virtual void | Fini () |
Finilize the physics engine. More... | |
virtual bool | GetAutoDisableFlag () |
: Remove this function, and replace it with a more generic property map More... | |
ContactManager * | GetContactManager () const |
Get a pointer to the contact manger. More... | |
double | GetMaxStepSize () const |
Get max step size. More... | |
virtual boost::any | GetParam (const std::string &_key) const |
Get an parameter of the physics engine. More... | |
virtual bool | GetParam (const std::string &_key, boost::any &_value) const |
Get a parameter from the physics engine with a boolean to indicate success or failure. More... | |
boost::recursive_mutex * | GetPhysicsUpdateMutex () const |
returns a pointer to the PhysicsEngine::physicsUpdateMutex. More... | |
double | GetRealTimeUpdateRate () const |
Get real time update rate. More... | |
sdf::ElementPtr | GetSDF () const |
Get a pointer to the SDF element for this physics engine. More... | |
double | GetTargetRealTimeFactor () const |
Get target real time factor. More... | |
virtual std::string | GetType () const =0 |
Return the physics engine type (ode|bullet|dart|simbody). More... | |
double | GetUpdatePeriod () |
Get the simulation update period. More... | |
virtual void | Init ()=0 |
Initialize the physics engine. More... | |
virtual void | InitForThread ()=0 |
Init the engine for threads. More... | |
virtual void | Load (sdf::ElementPtr _sdf) |
Load the physics engine. More... | |
virtual void | Reset () |
Rest the physics engine. More... | |
virtual void | SetAutoDisableFlag (bool _autoDisable) |
: Remove this function, and replace it with a more generic property map More... | |
virtual void | SetGravity (const ignition::math::Vector3d &_gravity)=0 |
Set the gravity vector. More... | |
virtual void | SetMaxContacts (unsigned int _maxContacts) |
: Remove this function, and replace it with a more generic property map More... | |
void | SetMaxStepSize (double _stepSize) |
Set max step size. More... | |
virtual bool | SetParam (const std::string &_key, const boost::any &_value) |
Set a parameter of the physics engine. More... | |
void | SetRealTimeUpdateRate (double _rate) |
Set real time update rate. More... | |
virtual void | SetSeed (uint32_t _seed)=0 |
Set the random number seed for the physics engine. More... | |
void | SetTargetRealTimeFactor (double _factor) |
Set target real time factor. More... | |
virtual void | UpdateCollision ()=0 |
Update the physics engine collision. More... | |
virtual void | UpdatePhysics () |
Update the physics engine. More... | |
WorldPtr | World () const |
Get a pointer to the world. More... | |
Static Public Member Functions | |
template<typename T > | |
static T | any_cast (const boost::any &_value) |
Helper function for performing any_cast operations in SetParam. More... | |
Protected Member Functions | |
virtual void | OnPhysicsMsg (ConstPhysicsPtr &_msg) |
virtual callback for gztopic "~/physics". More... | |
virtual void | OnRequest (ConstRequestPtr &_msg) |
virtual callback for gztopic "~/request". More... | |
Protected Attributes | |
ContactManager * | contactManager |
Class that handles all contacts generated by the physics engine. More... | |
double | maxStepSize |
Real time update rate. More... | |
transport::NodePtr | node |
Node for communication. More... | |
ignition::transport::Node | nodeIgn |
Ignition node for communication. More... | |
transport::SubscriberPtr | physicsSub |
Subscribe to the physics topic. More... | |
boost::recursive_mutex * | physicsUpdateMutex |
Mutex to protect the update cycle. More... | |
double | realTimeUpdateRate |
Real time update rate. More... | |
transport::SubscriberPtr | requestSub |
Subscribe to the request topic. More... | |
transport::PublisherPtr | responsePub |
Response publisher. More... | |
ignition::transport::Node::Publisher | responsePubIgn |
Response publisher. More... | |
sdf::ElementPtr | sdf |
Our SDF values. More... | |
double | targetRealTimeFactor |
Target real time factor. More... | |
WorldPtr | world |
Pointer to the world. More... | |
Base class for a physics engine.
|
explicit |
Default constructor.
[in] | _world | Pointer to the world. |
|
virtual |
Destructor.
|
inlinestatic |
Helper function for performing any_cast operations in SetParam.
This is useful because the PresetManager stores the output of sdf::Element::GetAny as boost::any values in its parameterMap and calls SetParam with these values. Prior to libsdformat8, the GetAny function returned boost::any, but it now returns std::any. This helper is used in SetParam to first check if a boost::any value contains a std::any, and if so, perform a std::any_cast<T>. Otherwise, it returns boost::any_cast<T>.
[in] | _value | Value to cast to type T. |
References PhysicsEngine::OnPhysicsMsg(), and PhysicsEngine::OnRequest().
|
pure virtual |
Create a collision.
[in] | _shapeType | Type of collision to create. |
[in] | _link | Parent link. |
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
CollisionPtr CreateCollision | ( | const std::string & | _shapeType, |
const std::string & | _linkName | ||
) |
Create a collision.
[in] | _shapeType | Type of collision to create. |
[in] | _linkName | Name of the parent link. |
|
pure virtual |
Create a new joint.
[in] | _type | Type of joint to create. |
[in] | _parent | Model parent. |
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
Create a new body.
[in] | _parent | Parent model for the link. |
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
Create a new model.
[in] | _base | Boost shared pointer to a new model. |
Reimplemented in DARTPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
|
pure virtual |
Create a physics::Shape object.
[in] | _shapeType | Type of shape to create. |
[in] | _collision | Collision parent. |
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
|
pure virtual |
Debug print out of the physic engine state.
Implemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::GetAutoDisableFlag().
|
virtual |
Finilize the physics engine.
Reimplemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
|
inlinevirtual |
: Remove this function, and replace it with a more generic property map
access functions to set ODE parameters..
References PhysicsEngine::DebugPrint(), PhysicsEngine::GetContactManager(), PhysicsEngine::GetParam(), PhysicsEngine::SetParam(), and PhysicsEngine::World().
ContactManager* GetContactManager | ( | ) | const |
Get a pointer to the contact manger.
Referenced by PhysicsEngine::GetAutoDisableFlag().
double GetMaxStepSize | ( | ) | const |
|
virtual |
Get an parameter of the physics engine.
[in] | _attr | String key |
Reimplemented in SimbodyPhysics, ODEPhysics, BulletPhysics, and DARTPhysics.
Referenced by PhysicsEngine::GetAutoDisableFlag().
|
virtual |
Get a parameter from the physics engine with a boolean to indicate success or failure.
[in] | _key | Key of the accessed param |
[out] | _value | Value of the accessed param |
Reimplemented in SimbodyPhysics, ODEPhysics, BulletPhysics, and DARTPhysics.
|
inline |
returns a pointer to the PhysicsEngine::physicsUpdateMutex.
References PhysicsEngine::GetSDF(), and PhysicsEngine::physicsUpdateMutex.
double GetRealTimeUpdateRate | ( | ) | const |
sdf::ElementPtr GetSDF | ( | ) | const |
Get a pointer to the SDF element for this physics engine.
Referenced by PhysicsEngine::GetPhysicsUpdateMutex().
double GetTargetRealTimeFactor | ( | ) | const |
|
pure virtual |
Return the physics engine type (ode|bullet|dart|simbody).
Implemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::Reset().
double GetUpdatePeriod | ( | ) |
Get the simulation update period.
Referenced by PhysicsEngine::Reset().
|
pure virtual |
Initialize the physics engine.
Implemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
|
pure virtual |
Init the engine for threads.
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::Reset().
|
virtual |
Load the physics engine.
[in] | _sdf | Pointer to the SDF parameters. |
Reimplemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
|
protectedvirtual |
virtual callback for gztopic "~/physics".
[in] | _msg | Physics message. |
Reimplemented in ODEPhysics, SimbodyPhysics, DARTPhysics, and BulletPhysics.
Referenced by PhysicsEngine::any_cast().
|
protectedvirtual |
virtual callback for gztopic "~/request".
[in] | _msg | Request message. |
Reimplemented in ODEPhysics, SimbodyPhysics, DARTPhysics, and BulletPhysics.
Referenced by PhysicsEngine::any_cast().
|
inlinevirtual |
Rest the physics engine.
Reimplemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
References PhysicsEngine::GetMaxStepSize(), PhysicsEngine::GetRealTimeUpdateRate(), PhysicsEngine::GetTargetRealTimeFactor(), PhysicsEngine::GetType(), PhysicsEngine::GetUpdatePeriod(), PhysicsEngine::InitForThread(), PhysicsEngine::SetMaxStepSize(), PhysicsEngine::SetRealTimeUpdateRate(), PhysicsEngine::SetSeed(), PhysicsEngine::SetTargetRealTimeFactor(), and PhysicsEngine::UpdateCollision().
|
virtual |
: Remove this function, and replace it with a more generic property map
Access functions to set ODE parameters.
[in] | _autoDisable | True to enable auto disabling of bodies. |
Referenced by PhysicsEngine::UpdatePhysics().
|
pure virtual |
Set the gravity vector.
[in] | _gravity | New gravity vector. |
Implemented in BulletPhysics, ODEPhysics, DARTPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
|
virtual |
: Remove this function, and replace it with a more generic property map
access functions to set ODE parameters
[in] | _maxContacts | Maximum number of contacts. |
Reimplemented in ODEPhysics.
Referenced by PhysicsEngine::UpdatePhysics().
void SetMaxStepSize | ( | double | _stepSize | ) |
|
virtual |
Set a parameter of the physics engine.
See SetParam documentation for descriptions of duplicate parameters.
[in] | _key | String key Below is a list of _key parameter definitions:
|
[in] | _value | The value to set to |
Reimplemented in SimbodyPhysics, ODEPhysics, BulletPhysics, and DARTPhysics.
Referenced by PhysicsEngine::GetAutoDisableFlag().
void SetRealTimeUpdateRate | ( | double | _rate | ) |
|
pure virtual |
Set the random number seed for the physics engine.
[in] | _seed | The random number seed. |
Implemented in ODEPhysics, BulletPhysics, DARTPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::Reset().
void SetTargetRealTimeFactor | ( | double | _factor | ) |
Set target real time factor.
[in] | _factor | Target real time factor |
Referenced by PhysicsEngine::Reset().
|
pure virtual |
Update the physics engine collision.
This function works in tandem with PhysicsEngine::UpdatePhysics() to update the world. This function will be called even if the physics is disabled (when World::PhysicsEnabled()) returns false). Which updates are done in which of the two functions PhysicsEngine::UpdateCollision() and PhysicsEngine::UpdatePhysics() is to some extent left to the implementing physics engine. The intention is that PhysicsEngine::UpdateCollision() will update the collision states of the world, including contact information, and PhysicsEngine::UpdatePhysics() will update the dynamics of the world, i.e. advance the world and react to the collision state. However for some physics engines, both is done in one step, or providing the contact information separately in UpdateCollision() would mean double work, as it can't be avoided to be done again in PhysicsEngine::UpdatePhysics() - in this case it is better that PhysicsEngine::UpdateCollision does not actually update collision and contact information, and instead leaves it to UpdatePhysics(). There should be one exception however when it still does make this update: If World::PhysicsEnabled() returns false, and therefore PhysicsEngine::UpdatePhysics() will not be called in the update step, then PhysicsEngine::UpdateCollision will need to ensure that collision and contact information will still be updated.
Implemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
Referenced by PhysicsEngine::Reset().
|
inlinevirtual |
Update the physics engine.
Will only be called if the physics are enabled, which is the case when World::PhysicsEnabled() returns true.
Reimplemented in ODEPhysics, DARTPhysics, BulletPhysics, and SimbodyPhysics.
References PhysicsEngine::CreateCollision(), PhysicsEngine::CreateJoint(), PhysicsEngine::CreateLink(), PhysicsEngine::CreateModel(), PhysicsEngine::CreateShape(), PhysicsEngine::SetAutoDisableFlag(), PhysicsEngine::SetGravity(), and PhysicsEngine::SetMaxContacts().
Get a pointer to the world.
Referenced by PhysicsEngine::GetAutoDisableFlag().
|
protected |
Class that handles all contacts generated by the physics engine.
|
protected |
Real time update rate.
|
protected |
Node for communication.
|
protected |
Ignition node for communication.
|
protected |
Subscribe to the physics topic.
|
protected |
Mutex to protect the update cycle.
Referenced by PhysicsEngine::GetPhysicsUpdateMutex().
|
protected |
Real time update rate.
|
protected |
Subscribe to the request topic.
|
protected |
Response publisher.
|
protected |
Response publisher.
|
protected |
Our SDF values.
|
protected |
Target real time factor.
|
protected |
Pointer to the world.