AGX Dynamics  2.37.2.0
agx::GenericConstraint Class Reference

Generic constraint which by default is empty of elementary constraints. More...

#include <GenericConstraint.h>

+ Inheritance diagram for agx::GenericConstraint:

Public Member Functions

 GenericConstraint (agx::RigidBody *rb1)
 Construct given one rigid body (second is null). More...
 
 GenericConstraint (agx::RigidBody *rb1, agx::RigidBody *rb2)
 Construct given two rigid bodies (first has to be != null). More...
 
 GenericConstraint (agx::RigidBody *rb1, agx::Frame *f1, agx::RigidBody *rb2, agx::Frame *f2)
 Construct given two bodies and frames. More...
 
GenericConstraintComplianceMatrix * getComplianceMatrix () const
 If this constraint active rows doesn't vary and isStaticSize = true has been flagged when enabling support for compliance matrix, this method will return the matrix at any time. More...
 
int getNumDOF () const override
 
virtual void onAddNotification ()
 Callback when the constraint has been added to a simulation. More...
 
virtual void onPostSolve ()
 Callback from after the solve and the solutions been pushed to the elementary constraints. More...
 
virtual agx::Bool onPreSolve ()
 Callback before this constraint reaches the solver (actually preSystemCallback). More...
 
virtual void onRemoveNotification ()
 Callback when the constraint has been removed from a simulation. More...
 
void render (class agxRender::RenderManager *manager, float scale) const override
 Inherited method of how to render this constraint into DebugRenderer. More...
 
agx::Bool setRigidBodies (agx::RigidBody *rb1, agx::RigidBody *rb2)
 Assign/update rigid bodies of this constraint. More...
 
void setSupportComplianceMatrix (agx::Bool enable, agx::Bool isStaticSize=false)
 Enable/disable updateComplianceMatrix callback with write access to the elements in the compliance matrix of this constraint. More...
 
virtual void updateComplianceMatrix (GenericConstraintComplianceMatrix *matrix)
 Callback to write data. More...
 
- Public Member Functions inherited from agx::Constraint
agx::Bool addElementaryConstraint (const agx::Name &name, agx::ElementaryConstraint *elementaryConstraint)
 Add elementary constraint (like Spherical, Dot1, Dot2 etc) given name. More...
 
agx::Bool addSecondaryConstraint (const agx::Name &name, agx::ElementaryConstraint *secondaryConstraint)
 Add secondary constraint (like motor, range and/or lock etc) given name. More...
 
 AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE (agx::Constraint)
 
template<typename T >
T * as ()
 Try to do dynamic_cast on the constraint and return a pointer to the casted constraint. More...
 
template<typename T >
const T * as () const
 Try to do dynamic_cast on the constraint and return a pointer to the casted constraint. More...
 
agx::UInt calculateNumActiveRows () const
 Calculates the current number of active rows, including both elementary and secondary constraints. More...
 
template<typename T >
ref_ptr< T > createFromBody (Vec3 bodyPoint, Vec3 bodyAxis, RigidBody *rb1, RigidBody *rb2)
 
template<typename T >
ref_ptr< T > createFromWorld (Vec3 worldPoint, Vec3 worldAxis, RigidBody *rb1, RigidBody *rb2)
 
agx::RigidBodyAttachment * getAttachment (const agx::RigidBody *rb) const
 
agx::Attachment * getAttachment (agx::UInt i) const
 
agx::AttachmentPair * getAttachmentPair () const
 
agx::RigidBody * getBodyAt (agx::UInt i)
 
const agx::RigidBody * getBodyAt (agx::UInt i) const
 
virtual agx::Real getCompliance (agx::UInt dof) const
 Get the compliance for DOF i. More...
 
agx::Real getCurrentForce (agx::UInt dof) const
 Consider using getLastForce instead. More...
 
virtual Real getDamping (agx::UInt dof) const
 Get the damping for DOF dof. More...
 
virtual agx::Real getElasticity (agx::UInt dof) const
 Get the elasticity for DOF i. More...
 
agx::ElementaryConstraint * getElementaryConstraint (const agx::UInt index) const
 
agx::ElementaryConstraint * getElementaryConstraintGivenName (const agx::Name &name) const
 Find elementary constraint given name. More...
 
agx::Bool getEnable () const
 
agx::Bool getEnableComputeForces () const
 
bool getEnableDebugRendering () const
 
bool getEnableLinearization () const
 
agx::UInt32 getEntityId () const
 
agx::RangeReal getForceRange (agx::UInt dof=0) const
 Get the force range for DOF dof. More...
 
agx::Bool getLastForce (agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
 If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the body with bodyIndex. More...
 
agx::Bool getLastForce (const agx::RigidBody *rb, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
 If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the body rb. More...
 
agx::Bool getLastLocalForce (agx::UInt bodyIndex, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
 If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the body with bodyIndex. More...
 
agx::Bool getLastLocalForce (const agx::RigidBody *rb, agx::Vec3 &retForce, agx::Vec3 &retTorque, agx::Bool giveForceAtCm=false) const
 If 'compute forces' is enabled, returns the last force and torque applied by this constraint on the body rb. More...
 
agx::UInt getNumBodies () const
 returns the number of bodies involved More...
 
agx::UInt getNumElementaryConstraints () const
 
agx::UInt getNumSecondaryConstraints () const
 
virtual agx::RegularizationParameters * getRegularizationParameters (agx::UInt i)
 
virtual const agx::RegularizationParameters * getRegularizationParameters (agx::UInt i) const
 
agx::ConstraintImplementation * getRep ()
 
const agx::ConstraintImplementation * getRep () const
 
agx::ElementaryConstraint * getSecondaryConstraint (const agx::UInt index) const
 
agx::ElementaryConstraint * getSecondaryConstraintGivenName (const agx::Name &name) const
 Find secondary constraint given name. More...
 
agx::Constraint::SolveType getSolveType () const
 
agx::Bool getValid () const
 
agx::Bool isEnabled () const
 
virtual agx::Bool rebind ()
 Rebind this constraint, i.e., use current state as the initial configuration. More...
 
agx::Bool removeElementaryConstraint (agx::ElementaryConstraint *elementaryConstraint)
 Remove elementary constraint. More...
 
agx::Bool removeElementaryConstraint (const agx::Name &name)
 Remove elementary constraint. More...
 
agx::Bool removeSecondaryConstraint (agx::ElementaryConstraint *secondaryConstraint)
 Remove secondary constraint. More...
 
agx::Bool removeSecondaryConstraint (const agx::Name &name)
 Remove secondary constraint. More...
 
void restore (agxStream::InputArchive &in) override
 
virtual void restoreLightData (agxStream::StorageStream &str) override
 
virtual void setCompliance (agx::Real compliance, agx::Int dof)
 Set the compliance of this constraint for the i:th DOF. More...
 
void setCompliance (agx::Real compliance)
 Set the compliance of this constraint for all DOFs. More...
 
virtual void setDamping (agx::Real damping, agx::Int dof)
 Set the damping of this constraint for the i:th DOF. More...
 
void setDamping (agx::Real damping)
 Set the damping of this constraint for all DOFs. More...
 
virtual void setElasticity (agx::Real elasticity, agx::Int dof)
 Set the elasticity of this constraint for the i:th DOF. More...
 
virtual void setElasticity (agx::Real elasticity)
 Set the elasticity of this constraint for all DOFs. More...
 
virtual void setEnable (agx::Bool enable)
 Enable/disable a constraint. More...
 
void setEnableComputeForces (agx::Bool enable)
 Enable (or disable) computation of the forces applied to the dynamic bodies in this constraint. More...
 
void setEnableDebugRendering (agx::Bool enable)
 Enable/disable debug rendering of this constraint. More...
 
void setEnableLinearization (bool enable)
 Pass true to enable linearization of constraint compliance. More...
 
void setForceRange (agx::RangeReal forceRange)
 Assign force range for all DOF of the elementary constraints. More...
 
void setForceRange (agx::RangeReal forceRange, agx::Int dof)
 Assign force range, of an elementary constraint, for a given DOF. More...
 
void setForceRange (agx::Real lower, agx::Real upper, agx::Int dof)
 Assign force range, of an elementary constraint, for a given DOF. More...
 
void setSolveType (agx::Constraint::SolveType solveType)
 Specify the solve type for this constraint. More...
 
void store (agxStream::OutputArchive &out) const override
 
virtual void storeLightData (agxStream::StorageStream &str) const override
 
- Public Member Functions inherited from agx::Interaction
 Interaction ()
 Default constructor. More...
 
const char * getClassName () const override
 
const agx::Name & getName () const
 
agx::PropertyContainer * getPropertyContainer ()
 
const agx::PropertyContainer * getPropertyContainer () const
 
agxSDK::SimulationProxy * getSimulationProxy () const
 
agxStream::StorageAgent * getStorageAgent () const override
 
agx::Bool hasPropertyContainer () const
 
void setName (const agx::Name &name)
 Name this interaction. More...
 
void setPropertyContainer (agx::PropertyContainer *propertyContainer)
 Assign a new property container. More...
 
virtual void updateForce (agx::DynamicsSystem *dynamicsSystem)
 This virtual method is implemented so that it computes the interaction forces on all the physical bodies implicated. More...
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor. More...
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting. More...
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match. More...
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test. More...
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object. More...
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
- Public Member Functions inherited from agxStream::Serializable
virtual ~Serializable ()
 Destructor for normal C++ use but hidden from SWIG bindings. More...
 
bool getEnableSerialization () const
 
bool getEnableUuidGeneration ()
 
agx::UInt32 getIndex () const
 This index is given at creation of this object. More...
 
agx::Uuid getUuid () const
 
bool isFinished () const
 
void setEnableSerialization (bool flag)
 Set to false to disable serialization of this object. More...
 
void setFinished ()
 Tells this class that it is restored correctly and should not be deleted during destruction of an Archive. More...
 
void setUuid (const agx::Uuid &uuid)
 Explicitly set a Uuid on a serializable object. More...
 

Static Public Member Functions

static void onCleanup (const agxSDK::Simulation *simulation)
 
static void onPostSolveCallback (const agxSDK::Simulation *simulation)
 
static void onPreSolveCallback (const agxSDK::Simulation *simulation)
 
- Static Public Member Functions inherited from agx::Constraint
static agx::Bool calculateFramesFromBody (agx::Vec3 bodyPoint, agx::Vec3 bodyAxis, const agx::RigidBody *body, agx::Frame *bodyFrame, const agx::RigidBody *otherBody, agx::Frame *otherFrame)
 Calculates the constraint attachment frames given point and axis in body coordinates of body. More...
 
static agx::Bool calculateFramesFromBody (agx::Vec3 bodyPoint, agx::Vec3 bodyAxis, agx::Vec3 secondBodyAxis, const agx::RigidBody *body, agx::Frame *bodyFrame, const agx::RigidBody *otherBody, agx::Frame *otherFrame)
 Calculates the constraint attachment frames given point and axes in body coordinates of body. More...
 
static agx::Bool calculateFramesFromWorld (agx::Vec3 worldPoint, agx::Vec3 worldAxis, const agx::RigidBody *rb1, agx::Frame *rb1Frame, const agx::RigidBody *rb2, agx::Frame *rb2Frame)
 Given a point and an axis in world, this function calculates each local attachment frame for one or two bodies. More...
 
static agx::Bool calculateFramesFromWorld (agx::Vec3 worldPoint, agx::Vec3 worldAxis, agx::Vec3 secondWorldAxis, const agx::RigidBody *rb1, agx::Frame *rb1Frame, const agx::RigidBody *rb2, agx::Frame *rb2Frame)
 Given a point and two axes in world, this function calculates each local attachment frame for one or two bodies. More...
 
template<typename T >
static agx::ref_ptr< T > createFromBody (agx::Vec3 bodyPoint, agx::Vec3 bodyAxis, agx::RigidBody *rb1, agx::RigidBody *rb2=nullptr)
 Creates a constraint given a point and an axis in rb1 model frame. More...
 
template<typename T >
static agx::ref_ptr< T > createFromWorld (agx::Vec3 worldPoint, agx::Vec3 worldAxis, agx::RigidBody *rb1, agx::RigidBody *rb2=nullptr)
 Creates a constraint given a point and an axis in world frame. More...
 
- Static Public Member Functions inherited from agx::Interaction
static agxStream::Serializable * create ()
 
static agxStream::Serializable * create (agxStream::InputArchive &)
 
static const char * getConstructClassId ()
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- Static Public Member Functions inherited from agxStream::Serializable
static void setEnableUuidGeneration (bool flag)
 Specify if there should be UUID:s generated for each new Serializable object. By default it is enabled. More...
 

Protected Member Functions

virtual ~GenericConstraint ()
 
virtual void addNotification () override
 Called when added to a simulation. More...
 
virtual void removeNotification () override
 Called when removed from a simulation. More...
 
- Protected Member Functions inherited from agx::Constraint
 Constraint ()
 
virtual ~Constraint ()
 
virtual void postSystemCallback (agx::DynamicsSystem *dynamicsSystem) override
 Called after all post step events, after solve. More...
 
virtual void preSystemCallback (agx::DynamicsSystem *dynamicsSystem) override
 Called after all pre step events, before solve. More...
 
void setRep (agx::ConstraintImplementation *_rep)
 
virtual void setSimulation (agxSDK::Simulation *simulation) override
 Assign simulation. More...
 
virtual void setSystem (agx::DynamicsSystem *)
 
- Protected Member Functions inherited from agx::Interaction
virtual ~Interaction ()
 Reference counted object, protected destructor. More...
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor. More...
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 
- Protected Member Functions inherited from agxStream::Serializable
 Serializable ()
 Default constructor. More...
 
 Serializable (const Serializable &other)
 Copy constructor. More...
 
void generateUuid ()
 

Additional Inherited Members

- Public Types inherited from agx::Constraint
enum  SolveType { DIRECT = 1, ITERATIVE = (1<<2), DIRECT_AND_ITERATIVE = (DIRECT | ITERATIVE) }
 Specifies in what solvers the constraint will be solved. More...
 
- Static Protected Member Functions inherited from agx::Referenced
static DeleteHandler * getDeleteHandler ()
 
static void setDeleteHandler (DeleteHandler *handler)
 Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More...
 
- Protected Attributes inherited from agx::Constraint
agx::ConstraintImplementation * m_implementation
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

Generic constraint which by default is empty of elementary constraints.

This enables the possibility to build custom/generic constraints with additional GenericElementaryConstraint instances or to use the already implemented in the toolkit.

This constraint receives; onAddNotification, onRemoveNotification, onPreSolve and onPostSolve.

Python example: class MyHinge(agx.GenericConstraint): def init(self, rb1: agx.RigidBody, rb1Frame: agx.Frame, rb2: agx.RigidBody, rb2Frame: agx.Frame): super().__init__( rb1, rb1Frame, rb2, rb2Frame )

self.addElementaryConstraint( "SP", agx.SphericalRel( agx.ElementaryConstraintData( self.getAttachmentPair() ) ) ) self.addElementaryConstraint( "D1VN", MyDot1( agx.Attachment.V, agx.Attachment.N ) ) self.addElementaryConstraint( "D1UN", MyDot1( agx.Attachment.U, agx.Attachment.N ) )

def onAddNotification(self): print( 'add notification!' )

def onRemoveNotification(self): print( 'remove notification!' )

def onPreSolve(self): return True

Definition at line 53 of file GenericConstraint.h.

Constructor & Destructor Documentation

◆ GenericConstraint() [1/3]

agx::GenericConstraint::GenericConstraint ( agx::RigidBody *  rb1)

Construct given one rigid body (second is null).

Note
Two frames will be created and added to the AttachmentPair of this constraint. The transform of the constraint frames is identity.
Parameters
rb1- first rigid body

◆ GenericConstraint() [2/3]

agx::GenericConstraint::GenericConstraint ( agx::RigidBody *  rb1,
agx::RigidBody *  rb2 
)

Construct given two rigid bodies (first has to be != null).

Note
Two frames will be created and added to the AttachmentPair of this constraint. The transform of the constraint frames is identity.
Parameters
rb1- first rigid body
rb2- second rigid body

◆ GenericConstraint() [3/3]

agx::GenericConstraint::GenericConstraint ( agx::RigidBody *  rb1,
agx::Frame *  f1,
agx::RigidBody *  rb2,
agx::Frame *  f2 
)

Construct given two bodies and frames.

Parameters
rb1- first rigid body
f1- constraint frame relative to rb1
rb2- second rigid body
f2- constraint frame relative to rb2

◆ ~GenericConstraint()

virtual agx::GenericConstraint::~GenericConstraint ( )
protectedvirtual

Member Function Documentation

◆ addNotification()

virtual void agx::GenericConstraint::addNotification ( )
overrideprotectedvirtual

Called when added to a simulation.

Reimplemented from agx::Constraint.

◆ getComplianceMatrix()

GenericConstraintComplianceMatrix* agx::GenericConstraint::getComplianceMatrix ( ) const

If this constraint active rows doesn't vary and isStaticSize = true has been flagged when enabling support for compliance matrix, this method will return the matrix at any time.

Otherwise nullptr is returned.

Returns
compliance matrix if accessible, otherwise nullptr

◆ getNumDOF()

int agx::GenericConstraint::getNumDOF ( ) const
overridevirtual
Returns
the number of DOF for this constraint, not including secondary constraints. -1 if num DOF is undefined for the constraint.

Implements agx::Constraint.

◆ onAddNotification()

virtual void agx::GenericConstraint::onAddNotification ( )
virtual

Callback when the constraint has been added to a simulation.

◆ onCleanup()

static void agx::GenericConstraint::onCleanup ( const agxSDK::Simulation *  simulation)
static

◆ onPostSolve()

virtual void agx::GenericConstraint::onPostSolve ( )
virtual

Callback from after the solve and the solutions been pushed to the elementary constraints.

◆ onPostSolveCallback()

static void agx::GenericConstraint::onPostSolveCallback ( const agxSDK::Simulation *  simulation)
static

◆ onPreSolve()

virtual agx::Bool agx::GenericConstraint::onPreSolve ( )
virtual

Callback before this constraint reaches the solver (actually preSystemCallback).

If the return value is true and this constraint is valid, this constraint will continue into the solver.

Returns
true if this constraint is active, false if inactive

◆ onPreSolveCallback()

static void agx::GenericConstraint::onPreSolveCallback ( const agxSDK::Simulation *  simulation)
static

◆ onRemoveNotification()

virtual void agx::GenericConstraint::onRemoveNotification ( )
virtual

Callback when the constraint has been removed from a simulation.

◆ removeNotification()

virtual void agx::GenericConstraint::removeNotification ( )
overrideprotectedvirtual

Called when removed from a simulation.

Reimplemented from agx::Constraint.

◆ render()

void agx::GenericConstraint::render ( class agxRender::RenderManager *  mgr,
float  scale 
) const
overridevirtual

Inherited method of how to render this constraint into DebugRenderer.

Implements agx::Constraint.

◆ setRigidBodies()

agx::Bool agx::GenericConstraint::setRigidBodies ( agx::RigidBody *  rb1,
agx::RigidBody *  rb2 
)

Assign/update rigid bodies of this constraint.

Note that rb1 must be valid for this constraint to be valid.

Parameters
rb1- first rigid body
rb2- second rigid body
Returns
true if this constraint is valid after the bodies has been assigned, otherwise false

◆ setSupportComplianceMatrix()

void agx::GenericConstraint::setSupportComplianceMatrix ( agx::Bool  enable,
agx::Bool  isStaticSize = false 
)

Enable/disable updateComplianceMatrix callback with write access to the elements in the compliance matrix of this constraint.

If isStaticSize is true, meaning the number of active rows in this constraint is constant, the matrix is accessible and wont reset to zero each time step.

Note
This is only supported by the direct solver.
Parameters
enable- true to enable, false to disable
isStaticSize- true if this constraints active rows is constant, e.g., LockJoint, enabling access to the compliance matrix in runtime and the matrix isn't reset to zero each time step.

◆ updateComplianceMatrix()

virtual void agx::GenericConstraint::updateComplianceMatrix ( GenericConstraintComplianceMatrix *  matrix)
virtual

Callback to write data.

All values must be greater than or equal to zero. Data is only stored for the lower triangle since the matrix must be symmetric and positive definite.


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