SimbodyPhysics Class Reference

Simbody physics engine. More...

#include <SimbodyPhysics.hh>

Inherits PhysicsEngine.

Public Member Functions

 SimbodyPhysics (WorldPtr _world)
 Constructor. More...
 
virtual ~SimbodyPhysics ()
 Destructor. More...
 
virtual CollisionPtr CreateCollision (const std::string &_type, LinkPtr _body)
 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)
 Create a new joint. More...
 
virtual LinkPtr CreateLink (ModelPtr _parent)
 Create a new body. More...
 
virtual ModelPtr CreateModel (BasePtr _parent)
 Create a new model. More...
 
virtual ShapePtr CreateShape (const std::string &_shapeType, CollisionPtr _collision)
 Create a physics::Shape object. More...
 
virtual void DebugPrint () const
 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...
 
ContactManagerGetContactManager () const
 Get a pointer to the contact manger. More...
 
SimTK::MultibodySystem * GetDynamicsWorld () const
 Register a joint with the dynamics world. 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
 Return the physics engine type (ode|bullet|dart|simbody). More...
 
double GetUpdatePeriod ()
 Get the simulation update period. More...
 
virtual void Init ()
 Initialize the physics engine. More...
 
virtual void InitForThread ()
 Init the engine for threads. More...
 
void InitModel (const physics::ModelPtr _model)
 Add a Model to the Simbody system. 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)
 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)
 Set the random number seed for the physics engine. More...
 
void SetTargetRealTimeFactor (double _factor)
 Set target real time factor. More...
 
virtual void UpdateCollision ()
 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...
 
static SimTK::Transform GetPose (sdf::ElementPtr _element)
 If the given element contains a <pose> element, return it as a Transform. More...
 
static std::string GetTypeString (unsigned int _type)
 Convert Base::GetType() to string, this is needed by the MultibodyGraphMaker. More...
 
static std::string GetTypeString (physics::Base::EntityType _type)
 Convert Base::GetType() to string, this is needed by the MultibodyGraphMaker. More...
 
static SimTK::Transform Pose2Transform (const ignition::math::Pose3d &_pose)
 Convert the given pose in x,y,z,thetax,thetay,thetaz format to a Simbody Transform. More...
 
static SimTK::Quaternion QuadToQuad (const ignition::math::Quaterniond &_q)
 Convert ignition::math::Quaterniond to SimTK::Quaternion. More...
 
static ignition::math::Quaterniond QuadToQuadIgn (const SimTK::Quaternion &_q)
 Convert SimTK::Quaternion to ignition::math::Quaterniond. More...
 
static ignition::math::Pose3d Transform2PoseIgn (const SimTK::Transform &_xAB)
 Convert a Simbody transform to a pose in x,y,z, thetax,thetay,thetaz format. More...
 
static ignition::math::Vector3d Vec3ToVector3Ign (const SimTK::Vec3 &_v)
 Convert SimTK::Vec3 to ignition::math::Vector3d. More...
 
static SimTK::Vec3 Vector3ToVec3 (const ignition::math::Vector3d &_v)
 Convert ignition::math::Vector3d to SimTK::Vec3. More...
 

Public Attributes

SimTK::CompliantContactSubsystem contact
 
SimTK::Force::DiscreteForces discreteForces
 
SimTK::GeneralForceSubsystem forces
 
SimTK::Force::Gravity gravity
 
SimTK::Integrator * integ
 
SimTK::SimbodyMatterSubsystem matter
 
bool simbodyPhysicsInitialized
 true if initialized More...
 
bool simbodyPhysicsStepped
 
SimTK::MultibodySystem system
 
SimTK::ContactTrackerSubsystem tracker
 

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

ContactManagercontactManager
 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...
 

Detailed Description

Simbody physics engine.

Constructor & Destructor Documentation

◆ SimbodyPhysics()

SimbodyPhysics ( WorldPtr  _world)
explicit

Constructor.

◆ ~SimbodyPhysics()

virtual ~SimbodyPhysics ( )
virtual

Destructor.

Member Function Documentation

◆ any_cast()

static T any_cast ( const boost::any &  _value)
inlinestaticinherited

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>.

Parameters
[in]_valueValue to cast to type T.
Returns
Value cast to type T.

References PhysicsEngine::OnPhysicsMsg(), and PhysicsEngine::OnRequest().

◆ CreateCollision() [1/2]

virtual CollisionPtr CreateCollision ( const std::string &  _shapeType,
LinkPtr  _link 
)
virtual

Create a collision.

Parameters
[in]_shapeTypeType of collision to create.
[in]_linkParent link.

Implements PhysicsEngine.

◆ CreateCollision() [2/2]

CollisionPtr CreateCollision ( const std::string &  _shapeType,
const std::string &  _linkName 
)
inherited

Create a collision.

Parameters
[in]_shapeTypeType of collision to create.
[in]_linkNameName of the parent link.

◆ CreateJoint()

virtual JointPtr CreateJoint ( const std::string &  _type,
ModelPtr  _parent 
)
virtual

Create a new joint.

Parameters
[in]_typeType of joint to create.
[in]_parentModel parent.

Implements PhysicsEngine.

◆ CreateLink()

virtual LinkPtr CreateLink ( ModelPtr  _parent)
virtual

Create a new body.

Parameters
[in]_parentParent model for the link.

Implements PhysicsEngine.

◆ CreateModel()

virtual ModelPtr CreateModel ( BasePtr  _base)
virtual

Create a new model.

Parameters
[in]_baseBoost shared pointer to a new model.

Reimplemented from PhysicsEngine.

◆ CreateShape()

virtual ShapePtr CreateShape ( const std::string &  _shapeType,
CollisionPtr  _collision 
)
virtual

Create a physics::Shape object.

Parameters
[in]_shapeTypeType of shape to create.
[in]_collisionCollision parent.

Implements PhysicsEngine.

◆ DebugPrint()

virtual void DebugPrint ( ) const
virtual

Debug print out of the physic engine state.

Implements PhysicsEngine.

◆ Fini()

virtual void Fini ( )
virtual

Finilize the physics engine.

Reimplemented from PhysicsEngine.

◆ GetAutoDisableFlag()

virtual bool GetAutoDisableFlag ( )
inlinevirtualinherited

: Remove this function, and replace it with a more generic property map

access functions to set ODE parameters..

Returns
Auto disable flag.

References PhysicsEngine::DebugPrint(), PhysicsEngine::GetContactManager(), PhysicsEngine::GetParam(), PhysicsEngine::SetParam(), and PhysicsEngine::World().

◆ GetContactManager()

ContactManager* GetContactManager ( ) const
inherited

Get a pointer to the contact manger.

Returns
Pointer to the contact manager.

Referenced by PhysicsEngine::GetAutoDisableFlag().

◆ GetDynamicsWorld()

SimTK::MultibodySystem* GetDynamicsWorld ( ) const

Register a joint with the dynamics world.

◆ GetMaxStepSize()

double GetMaxStepSize ( ) const
inherited

Get max step size.

Returns
Max step size.

Referenced by PhysicsEngine::Reset().

◆ GetParam() [1/2]

virtual boost::any GetParam ( const std::string &  _key) const
virtual

Get an parameter of the physics engine.

Parameters
[in]_attrString key
See also
SetParam
Returns
The value of the parameter

Reimplemented from PhysicsEngine.

◆ GetParam() [2/2]

virtual bool GetParam ( const std::string &  _key,
boost::any &  _value 
) const
virtual

Get a parameter from the physics engine with a boolean to indicate success or failure.

Parameters
[in]_keyKey of the accessed param
[out]_valueValue of the accessed param
Returns
True if the parameter was successfully retrieved

Reimplemented from PhysicsEngine.

◆ GetPhysicsUpdateMutex()

boost::recursive_mutex* GetPhysicsUpdateMutex ( ) const
inlineinherited

returns a pointer to the PhysicsEngine::physicsUpdateMutex.

Returns
Pointer to the physics mutex.

References PhysicsEngine::GetSDF(), and PhysicsEngine::physicsUpdateMutex.

◆ GetPose()

static SimTK::Transform GetPose ( sdf::ElementPtr  _element)
static

If the given element contains a <pose> element, return it as a Transform.

Otherwise return the identity Transform. If there is more than one <pose> element, only the first one is processed.

◆ GetRealTimeUpdateRate()

double GetRealTimeUpdateRate ( ) const
inherited

Get real time update rate.

Returns
Update rate

Referenced by PhysicsEngine::Reset().

◆ GetSDF()

sdf::ElementPtr GetSDF ( ) const
inherited

Get a pointer to the SDF element for this physics engine.

Returns
Pointer to the physics SDF element.

Referenced by PhysicsEngine::GetPhysicsUpdateMutex().

◆ GetTargetRealTimeFactor()

double GetTargetRealTimeFactor ( ) const
inherited

Get target real time factor.

Returns
Target real time factor

Referenced by PhysicsEngine::Reset().

◆ GetType()

virtual std::string GetType ( ) const
virtual

Return the physics engine type (ode|bullet|dart|simbody).

Returns
Type of the physics engine.

Implements PhysicsEngine.

◆ GetTypeString() [1/2]

static std::string GetTypeString ( unsigned int  _type)
static

Convert Base::GetType() to string, this is needed by the MultibodyGraphMaker.

Parameters
[in]_typeJoint type returned by Joint::GetType().
Returns
a hard-coded string needed by the MultibodyGraphMaker.

◆ GetTypeString() [2/2]

static std::string GetTypeString ( physics::Base::EntityType  _type)
static

Convert Base::GetType() to string, this is needed by the MultibodyGraphMaker.

Parameters
[in]_typeJoint type returned by Joint::GetType().
Returns
a hard-coded string needed by the MultibodyGraphMaker.

◆ GetUpdatePeriod()

double GetUpdatePeriod ( )
inherited

Get the simulation update period.

Returns
Simulation update period.

Referenced by PhysicsEngine::Reset().

◆ Init()

virtual void Init ( )
virtual

Initialize the physics engine.

Implements PhysicsEngine.

◆ InitForThread()

virtual void InitForThread ( )
virtual

Init the engine for threads.

Implements PhysicsEngine.

◆ InitModel()

void InitModel ( const physics::ModelPtr  _model)

Add a Model to the Simbody system.

Parameters
[in]_modelPointer to the model to add into Simbody.

◆ Load()

virtual void Load ( sdf::ElementPtr  _sdf)
virtual

Load the physics engine.

Parameters
[in]_sdfPointer to the SDF parameters.

Reimplemented from PhysicsEngine.

◆ OnPhysicsMsg()

virtual void OnPhysicsMsg ( ConstPhysicsPtr &  _msg)
protectedvirtual

virtual callback for gztopic "~/physics".

Parameters
[in]_msgPhysics message.

Reimplemented from PhysicsEngine.

◆ OnRequest()

virtual void OnRequest ( ConstRequestPtr &  _msg)
protectedvirtual

virtual callback for gztopic "~/request".

Parameters
[in]_msgRequest message.

Reimplemented from PhysicsEngine.

◆ Pose2Transform()

static SimTK::Transform Pose2Transform ( const ignition::math::Pose3d &  _pose)
static

Convert the given pose in x,y,z,thetax,thetay,thetaz format to a Simbody Transform.

The rotation angles are interpreted as a body-fixed sequence, meaning we rotation about x, then about the new y, then about the now twice-rotated z.

Parameters
[in]_poseIgnition math Pose3d object
Returns
Simbody's SimTK::Transform object

◆ QuadToQuad()

static SimTK::Quaternion QuadToQuad ( const ignition::math::Quaterniond &  _q)
static

Convert ignition::math::Quaterniond to SimTK::Quaternion.

Parameters
[in]_qIgnition::math::Quaterniond object
Returns
Simbody's SimTK::Quaternion object

◆ QuadToQuadIgn()

static ignition::math::Quaterniond QuadToQuadIgn ( const SimTK::Quaternion &  _q)
static

Convert SimTK::Quaternion to ignition::math::Quaterniond.

Parameters
[in]_qSimbody's SimTK::Quaternion object
Returns
Ignition::math::Quaterniond object

◆ Reset()

virtual void Reset ( )
virtual

Rest the physics engine.

Reimplemented from PhysicsEngine.

◆ SetAutoDisableFlag()

virtual void SetAutoDisableFlag ( bool  _autoDisable)
virtualinherited

: Remove this function, and replace it with a more generic property map

Access functions to set ODE parameters.

Parameters
[in]_autoDisableTrue to enable auto disabling of bodies.

Referenced by PhysicsEngine::UpdatePhysics().

◆ SetGravity()

virtual void SetGravity ( const ignition::math::Vector3d &  _gravity)
virtual

Set the gravity vector.

Parameters
[in]_gravityNew gravity vector.

Implements PhysicsEngine.

◆ SetMaxContacts()

virtual void SetMaxContacts ( unsigned int  _maxContacts)
virtualinherited

: Remove this function, and replace it with a more generic property map

access functions to set ODE parameters

Parameters
[in]_maxContactsMaximum number of contacts.

Reimplemented in ODEPhysics.

Referenced by PhysicsEngine::UpdatePhysics().

◆ SetMaxStepSize()

void SetMaxStepSize ( double  _stepSize)
inherited

Set max step size.

Parameters
[in]_stepSizeMax step size.

Referenced by PhysicsEngine::Reset().

◆ SetParam()

virtual bool SetParam ( const std::string &  _key,
const boost::any &  _value 
)
virtual

Set a parameter of the physics engine.

See SetParam documentation for descriptions of duplicate parameters.

Parameters
[in]_keyString key Below is a list of _key parameter definitions:
  1. "solver_type" (string) - returns solver used by engine, e.g. "sequential_impulse' for Bullet, "quick" for ODE "Featherstone and Lemkes" for DART and "Spatial Algebra and Elastic Foundation" for Simbody. -# "cfm" (double) - global CFM (ODE/Bullet) -# "erp" (double) - global ERP (ODE/Bullet) -# "precon_iters" (bool) - precondition iterations (experimental). (ODE)
  2. "iters" (int) - number of LCP PGS iterations. If sor_lcp_tolerance is negative, full iteration count is executed. Otherwise, PGS may stop iteration early if sor_lcp_tolerance is satisfied by the total RMS residual.
  3. "sor" (double) - relaxation parameter for Projected Gauss-Seidel (PGS) updates. (ODE/Bullet)
  4. "contact_max_correcting_vel" (double) - truncates correction impulses from ERP by this value. (ODE)
  5. "contact_surface_layer" (double) - ERP is 0 for interpenetration depths below this value. (ODE/Bullet)
  6. "max_contacts" (int) - max number of contact constraints between any pair of collision bodies.
  7. "min_step_size" (double) - minimum internal step size. (defined but not used in ode).
  8. "max_step_size" (double) - maximum physics step size when physics update step must return.
[in]_valueThe value to set to
Returns
true if SetParam is successful, false if operation fails.

Reimplemented from PhysicsEngine.

◆ SetRealTimeUpdateRate()

void SetRealTimeUpdateRate ( double  _rate)
inherited

Set real time update rate.

Parameters
[in]_rateUpdate rate

Referenced by PhysicsEngine::Reset().

◆ SetSeed()

virtual void SetSeed ( uint32_t  _seed)
virtual

Set the random number seed for the physics engine.

Parameters
[in]_seedThe random number seed.

Implements PhysicsEngine.

◆ SetTargetRealTimeFactor()

void SetTargetRealTimeFactor ( double  _factor)
inherited

Set target real time factor.

Parameters
[in]_factorTarget real time factor

Referenced by PhysicsEngine::Reset().

◆ Transform2PoseIgn()

static ignition::math::Pose3d Transform2PoseIgn ( const SimTK::Transform &  _xAB)
static

Convert a Simbody transform to a pose in x,y,z, thetax,thetay,thetaz format.

Parameters
[in]_xABSimbody's SimTK::Transform object
Returns
ignition::math::Pose3d object

◆ UpdateCollision()

virtual void UpdateCollision ( )
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.

Implements PhysicsEngine.

◆ UpdatePhysics()

virtual void UpdatePhysics ( )
virtual

Update the physics engine.

Will only be called if the physics are enabled, which is the case when World::PhysicsEnabled() returns true.

See also
PhysicsEngine::UpdateCollision()

Reimplemented from PhysicsEngine.

◆ Vec3ToVector3Ign()

static ignition::math::Vector3d Vec3ToVector3Ign ( const SimTK::Vec3 &  _v)
static

Convert SimTK::Vec3 to ignition::math::Vector3d.

Parameters
[in]_vSimbody's SimTK::Vec3 object
Returns
ignition::math::Vector3d object

◆ Vector3ToVec3()

static SimTK::Vec3 Vector3ToVec3 ( const ignition::math::Vector3d &  _v)
static

Convert ignition::math::Vector3d to SimTK::Vec3.

Parameters
[in]_vIgnition math Vector3d object
Returns
Simbody's SimTK::Vec3 object

◆ World()

WorldPtr World ( ) const
inherited

Get a pointer to the world.

Returns
Pointer to the world.

Referenced by PhysicsEngine::GetAutoDisableFlag().

Member Data Documentation

◆ contact

SimTK::CompliantContactSubsystem contact

◆ contactManager

ContactManager* contactManager
protectedinherited

Class that handles all contacts generated by the physics engine.

◆ discreteForces

SimTK::Force::DiscreteForces discreteForces

◆ forces

SimTK::GeneralForceSubsystem forces

◆ gravity

SimTK::Force::Gravity gravity

◆ integ

SimTK:: Integrator* integ

◆ matter

SimTK::SimbodyMatterSubsystem matter

◆ maxStepSize

double maxStepSize
protectedinherited

Real time update rate.

◆ node

transport::NodePtr node
protectedinherited

Node for communication.

◆ nodeIgn

ignition::transport::Node nodeIgn
protectedinherited

Ignition node for communication.

◆ physicsSub

transport::SubscriberPtr physicsSub
protectedinherited

Subscribe to the physics topic.

◆ physicsUpdateMutex

boost::recursive_mutex* physicsUpdateMutex
protectedinherited

Mutex to protect the update cycle.

Referenced by PhysicsEngine::GetPhysicsUpdateMutex().

◆ realTimeUpdateRate

double realTimeUpdateRate
protectedinherited

Real time update rate.

◆ requestSub

transport::SubscriberPtr requestSub
protectedinherited

Subscribe to the request topic.

◆ responsePub

transport::PublisherPtr responsePub
protectedinherited

Response publisher.

◆ responsePubIgn

ignition::transport::Node::Publisher responsePubIgn
protectedinherited

Response publisher.

◆ sdf

sdf::ElementPtr sdf
protectedinherited

Our SDF values.

◆ simbodyPhysicsInitialized

bool simbodyPhysicsInitialized

true if initialized

◆ simbodyPhysicsStepped

bool simbodyPhysicsStepped

◆ system

SimTK::MultibodySystem system

◆ targetRealTimeFactor

double targetRealTimeFactor
protectedinherited

Target real time factor.

◆ tracker

SimTK::ContactTrackerSubsystem tracker

◆ world

WorldPtr world
protectedinherited

Pointer to the world.


The documentation for this class was generated from the following file: