AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
Constraint.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20#include <agx/Frame.h>
21#include <agx/Interaction.h>
22#include <agx/SetVector.h>
23
24#if defined(_MSC_VER)
25#pragma warning( push )
26#pragma warning( disable : 4589 ) // Disable: 4589: Constructor of abstract class 'agx::FrictionModel' ignores initializer for virtual base class 'agxStream::Serializable'
27#endif
28
29
30namespace agxSDK
31{
32 class Simulation;
33}
34
35namespace agxRender
36{
37 class RenderManager;
38}
39
40namespace agx
41{
42 // forward declaration
43 class Constraint;
44 class DynamicsSystem;
45 class ConstraintImplementation;
46 class DebugRendererCache;
47 class Attachment;
48 class AttachmentPair;
49 class RigidBodyAttachment;
50 class RigidBody;
51 class RegularizationParameters;
52
56
57
89 {
90 public:
93 {
94 DIRECT = 1,
95 ITERATIVE = (1<<2),
96 DIRECT_AND_ITERATIVE = (DIRECT | ITERATIVE)
97 };
98
99 public:
104 virtual agx::Bool rebind();
105
108
113
118
124 virtual void setCompliance( agx::Real compliance, agx::Int dof );
125
130 void setCompliance( agx::Real compliance );
131
138 virtual void setElasticity(agx::Real elasticity, agx::Int dof);
139
144 virtual void setElasticity(agx::Real elasticity);
145
146
153 virtual agx::Real getCompliance( agx::UInt dof ) const;
154
162
168 virtual void setDamping( agx::Real damping, agx::Int dof );
169
174 void setDamping( agx::Real damping );
175
182 virtual Real getDamping( agx::UInt dof ) const;
183
190 void setForceRange( agx::RangeReal forceRange );
191
198 void setForceRange( agx::RangeReal forceRange, agx::Int dof );
199
207 void setForceRange( agx::Real lower, agx::Real upper, agx::Int dof );
208
216
225
230
235
243
245 virtual void render( class agxRender::RenderManager* mgr, float scale ) const = 0;
246
249
250 #ifndef SWIG
252 const agx::ConstraintImplementation* getRep() const;
253 #endif
254
257
262 virtual void setEnable( agx::Bool enable );
263
268
273
277 virtual int getNumDOF() const = 0;
278
286
292
297
302
307
312
317
325
330
350 agx::Bool getLastForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
351
370 agx::Bool getLastForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
371
390 agx::Bool getLastLocalForce( agx::UInt bodyIndex, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
391
409 agx::Bool getLastLocalForce( const agx::RigidBody* rb, agx::Vec3& retForce, agx::Vec3& retTorque, agx::Bool giveForceAtCm = false ) const;
410
418
434 void setEnableLinearization(bool enable);
435
441
449
457
464
471
478
485
491
498
504
511
516
521
529
542 agx::Vec3 worldAxis,
543 const agx::RigidBody* rb1,
544 agx::Frame* rb1Frame,
545 const agx::RigidBody* rb2,
546 agx::Frame* rb2Frame );
547
562 agx::Vec3 worldAxis,
563 agx::Vec3 secondWorldAxis,
564 const agx::RigidBody* rb1,
565 agx::Frame* rb1Frame,
566 const agx::RigidBody* rb2,
567 agx::Frame* rb2Frame );
568
580 agx::Vec3 bodyAxis,
581 const agx::RigidBody* body,
582 agx::Frame* bodyFrame,
583 const agx::RigidBody* otherBody,
584 agx::Frame* otherFrame );
585
599 agx::Vec3 bodyAxis,
600 agx::Vec3 secondBodyAxis,
601 const agx::RigidBody* body,
602 agx::Frame* bodyFrame,
603 const agx::RigidBody* otherBody,
604 agx::Frame* otherFrame );
605
616 template<typename T>
618 agx::Vec3 worldAxis,
619 agx::RigidBody* rb1,
620 agx::RigidBody* rb2 = nullptr );
621
631 template<typename T>
633 agx::Vec3 bodyAxis,
634 agx::RigidBody* rb1,
635 agx::RigidBody* rb2 = nullptr );
636
638 template<typename T>
639 T *as();
640
642 template<typename T>
643 const T *as() const;
644
646
647 void store( agxStream::OutputArchive& out ) const override;
648 void restore( agxStream::InputArchive& in ) override;
649
650 virtual void storeLightData( agxStream::StorageStream& str ) const override;
651 virtual void restoreLightData( agxStream::StorageStream& str ) override;
652
653 protected:
655 virtual ~Constraint();
656
657 friend class DynamicsSystem;
658 virtual void setSystem( agx::DynamicsSystem* ) {}
659
660 friend class agxSDK::Simulation;
661 virtual void setSimulation( agxSDK::Simulation* simulation ) override;
662 /*
663 Called when this Constraint is added to a simulation
664 (given that it not already is in the simulation).
665 */
666 virtual void addNotification() override;
667 virtual void removeNotification() override;
668
669#ifndef SWIG
670 virtual void preSystemCallback( agx::DynamicsSystem* dynamicsSystem ) override;
671 virtual void postSystemCallback( agx::DynamicsSystem* dynamicsSystem ) override;
672#endif
673
675
676 protected:
678
679 private:
681 friend class InternalData;
685 agx::Referenced* getInternalData() const;
686
690 void setInternalData( agx::Referenced* data );
692
693 private:
694 agx::Bool m_debugRenderingEnable;
695 };
696
701
704
710 {
711 public:
715 static agx::Constraint1DOF* safeCast( const agx::Constraint* constraint );
716
717 public:
722
726 const agx::Lock1D* getLock1D() const;
727
732
736 const agx::Motor1D* getMotor1D() const;
737
742
747
752
756 const agx::Range1D* getRange1D() const;
757
762
767
775
783
784 protected:
787 };
788
789
790
792
798 {
799 public:
803 static agx::Constraint2DOF* safeCast( const agx::Constraint* constraint );
804
805 public:
807 enum DOF
808 {
809 FIRST = 0,
810 SECOND
811 };
812
817
822
827
832
837
842
847
852
857
862
868
873 const agx::Screw1D* getScrew1D() const;
874
879
884
885 protected:
888 };
889
891 class AGXPHYSICS_EXPORT ConstraintFrame
892 {
893 public:
894 ConstraintFrame();
895 virtual ~ConstraintFrame();
896
897 Vec3& operator [] ( const unsigned int& i );
898 const Vec3& operator [] ( const unsigned int& i ) const;
899
900 void setTranslate( const Vec3& translate );
901 const Vec3& getTranslate() const;
902
903 protected:
904 Vec3 m_data[ 4 ];
905 };
907
909 {
910 return m_implementation;
911 }
912
913 inline const ConstraintImplementation* Constraint::getRep() const
914 {
915 return m_implementation;
916 }
917
918 template<typename T>
919 ref_ptr<T> Constraint::createFromWorld( Vec3 worldPoint, Vec3 worldAxis, RigidBody* rb1, RigidBody* rb2 /* = nullptr */ )
920 {
921 FrameRef f1 = new Frame();
922 FrameRef f2 = new Frame();
923 Constraint::calculateFramesFromWorld( worldPoint, worldAxis, rb1, f1, rb2, f2 );
924 ref_ptr<T> constraint = new T( rb1, f1, rb2, f2 );
925 return constraint;
926 }
927
928 template<typename T>
929 ref_ptr<T> Constraint::createFromBody( Vec3 bodyPoint, Vec3 bodyAxis, RigidBody* rb1, RigidBody* rb2 /* = nullptr */ )
930 {
931 FrameRef f1 = new Frame();
932 FrameRef f2 = new Frame();
933 Constraint::calculateFramesFromBody( bodyPoint, bodyAxis, rb1, f1, rb2, f2 );
934 ref_ptr<T> constraint = new T( rb1, f1, rb2, f2 );
935 return constraint;
936 }
937
939 template<typename T>
940 T *Constraint::as()
941 {
942 return dynamic_cast<T*>(this);
943 }
944
946 template<typename T>
947 const T *Constraint::as() const
948 {
949 return dynamic_cast<const T*>(this);
950 }
951
952} //namespace agx
953
954#if defined(_MSC_VER)
955#pragma warning( pop )
956#endif
957
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:57
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
Constraint attachment pair class.
Constraint attachment base class for any type of frame.
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:710
const agx::Motor1D * getMotor1D() const
const agx::Lock1D * getLock1D() const
agx::Real getAngle() const
This method return the current angle for the 1D constraint.
const agx::ElectricMotorController * getElectricMotorController() const
agx::Lock1D * getLock1D()
agx::Range1D * getRange1D()
agx::ElectricMotorController * getElectricMotorController()
agx::Motor1D * getMotor1D()
virtual ~Constraint1DOF()
const agx::Range1D * getRange1D() const
static agx::Constraint1DOF * safeCast(const agx::Constraint *constraint)
Utility method for not so type safe languages.
agx::Real getCurrentSpeed() const
This methods return the current speed for the 1D constraint.
const agx::FrictionController * getFrictionController() const
agx::FrictionController * getFrictionController()
Specialization for constraints that have two degree of freedom such as Cylindrical.
Definition: Constraint.h:798
const agx::Motor1D * getMotor1D(agx::Constraint2DOF::DOF dof) const
agx::Real getCurrentSpeed(agx::Constraint2DOF::DOF dof) const
const agx::Range1D * getRange1D(agx::Constraint2DOF::DOF dof) const
const agx::Lock1D * getLock1D(agx::Constraint2DOF::DOF dof) const
DOF
Specifies a selected degree of freedom.
Definition: Constraint.h:808
agx::Motor1D * getMotor1D(agx::Constraint2DOF::DOF dof)
agx::Range1D * getRange1D(agx::Constraint2DOF::DOF dof)
const agx::ElectricMotorController * getElectricMotorController(agx::Constraint2DOF::DOF dof) const
const agx::Screw1D * getScrew1D() const
Screw controller connects rotation and translation.
const agx::FrictionController * getFrictionController(agx::Constraint2DOF::DOF dof) const
static agx::Constraint2DOF * safeCast(const agx::Constraint *constraint)
Utility method for not so type safe languages.
agx::Real getAngle(agx::Constraint2DOF::DOF dof) const
virtual ~Constraint2DOF()
agx::ElectricMotorController * getElectricMotorController(agx::Constraint2DOF::DOF dof)
agx::Lock1D * getLock1D(agx::Constraint2DOF::DOF dof)
agx::Screw1D * getScrew1D()
Screw controller connects rotation and translation.
agx::FrictionController * getFrictionController(agx::Constraint2DOF::DOF dof)
The base class for a constraint.
Definition: Constraint.h:89
void setRep(agx::ConstraintImplementation *_rep)
void restore(agxStream::InputArchive &in) override
agx::Bool removeElementaryConstraint(agx::ElementaryConstraint *elementaryConstraint)
Remove elementary constraint.
agx::UInt getNumElementaryConstraints() const
virtual Real getDamping(agx::UInt dof) const
Get the damping for DOF dof.
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 b...
agx::ElementaryConstraint * getElementaryConstraint(const agx::UInt index) const
virtual void setElasticity(agx::Real elasticity, agx::Int dof)
Set the elasticity of this constraint for the i:th DOF.
virtual ~Constraint()
bool getEnableLinearization() const
agx::Constraint::SolveType getSolveType() const
void setForceRange(agx::RangeReal forceRange, agx::Int dof)
Assign force range, of an elementary constraint, for a given DOF.
agx::UInt calculateNumActiveRows() const
Calculates the current number of active rows, including both elementary and secondary constraints.
agx::Attachment * getAttachment(agx::UInt i) const
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 b...
virtual void postSystemCallback(agx::DynamicsSystem *dynamicsSystem) override
Called after all post step events, after solve.
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(agx::Constraint)
agx::ConstraintImplementation * m_implementation
Definition: Constraint.h:677
agx::Bool removeSecondaryConstraint(agx::ElementaryConstraint *secondaryConstraint)
Remove secondary constraint.
agx::ElementaryConstraint * getSecondaryConstraintGivenName(const agx::Name &name) const
Find secondary constraint given name.
agx::RigidBodyAttachment * getAttachment(const agx::RigidBody *rb) const
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.
agx::Bool isEnabled() const
void setDamping(agx::Real damping)
Set the damping of this constraint for all DOFs.
agx::Bool addSecondaryConstraint(const agx::Name &name, agx::ElementaryConstraint *secondaryConstraint)
Add secondary constraint (like motor, range and/or lock etc) given name.
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.
agx::Bool getEnableComputeForces() const
virtual void setEnable(agx::Bool enable)
Enable/disable a constraint.
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 b...
virtual void render(class agxRender::RenderManager *mgr, float scale) const =0
Inherited method of how to render this constraint into DebugRenderer.
void store(agxStream::OutputArchive &out) const override
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 b...
virtual void storeLightData(agxStream::StorageStream &str) const override
agx::UInt32 getEntityId() const
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.
virtual void removeNotification() override
Called when removed from a simulation.
const agx::RigidBody * getBodyAt(agx::UInt i) const
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.
void setForceRange(agx::Real lower, agx::Real upper, agx::Int dof)
Assign force range, of an elementary constraint, for a given DOF.
RealVector calculateCurrentViolation() const
Calculates the current violation of the ordinary degrees of freedom of this constraint,...
agx::Bool removeSecondaryConstraint(const agx::Name &name)
Remove secondary constraint.
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 t...
void setEnableComputeForces(agx::Bool enable)
Enable (or disable) computation of the forces applied to the dynamic bodies in this constraint.
void setForceRange(agx::RangeReal forceRange)
Assign force range for all DOF of the elementary constraints.
virtual const agx::RegularizationParameters * getRegularizationParameters(agx::UInt i) const
agx::UInt getNumSecondaryConstraints() const
void setCompliance(agx::Real compliance)
Set the compliance of this constraint for all DOFs.
virtual agx::Bool rebind()
Rebind this constraint, i.e., use current state as the initial configuration.
agx::AttachmentPair * getAttachmentPair() const
bool getEnableDebugRendering() const
void setEnableDebugRendering(agx::Bool enable)
Enable/disable debug rendering of this constraint.
virtual void setCompliance(agx::Real compliance, agx::Int dof)
Set the compliance of this constraint for the i:th DOF.
virtual void setElasticity(agx::Real elasticity)
Set the elasticity of this constraint for all DOFs.
virtual void addNotification() override
Called when added to a simulation.
agx::RigidBody * getBodyAt(agx::UInt i)
virtual int getNumDOF() const =0
virtual agx::Real getCompliance(agx::UInt dof) const
Get the compliance for DOF i.
agx::Bool getEnable() const
virtual agx::RegularizationParameters * getRegularizationParameters(agx::UInt i)
virtual void setDamping(agx::Real damping, agx::Int dof)
Set the damping of this constraint for the i:th DOF.
virtual void restoreLightData(agxStream::StorageStream &str) override
virtual void setSystem(agx::DynamicsSystem *)
Definition: Constraint.h:658
agx::Bool removeElementaryConstraint(const agx::Name &name)
Remove elementary constraint.
agx::Bool addElementaryConstraint(const agx::Name &name, agx::ElementaryConstraint *elementaryConstraint)
Add elementary constraint (like Spherical, Dot1, Dot2 etc) given name.
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 ...
agx::RangeReal getForceRange(agx::UInt dof=0) const
Get the force range for DOF dof.
agx::Bool getValid() const
virtual void preSystemCallback(agx::DynamicsSystem *dynamicsSystem) override
Called after all pre step events, before solve.
void setEnableLinearization(bool enable)
Pass true to enable linearization of constraint compliance.
agx::ElementaryConstraint * getSecondaryConstraint(const agx::UInt index) const
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:93
void setSolveType(agx::Constraint::SolveType solveType)
Specify the solve type for this constraint.
agx::UInt getNumBodies() const
returns the number of bodies involved
virtual agx::Real getElasticity(agx::UInt dof) const
Get the elasticity for DOF i.
virtual void setSimulation(agxSDK::Simulation *simulation) override
Assign simulation.
agx::ElementaryConstraint * getElementaryConstraintGivenName(const agx::Name &name) const
Find elementary constraint given name.
agx::Real getCurrentForce(agx::UInt dof) const
Consider using getLastForce instead.
The complete physical system with bodies, interactions, data layout, time stepper,...
Implementation of a electric motor controller.
Elementary constraint base class with interface and global constraint functionality.
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
Translational or rotational friction controller for Hinge, Prismatic and CylindricalJoint.
The base class for interactions.
Definition: Interaction.h:33
Internal data for any object, ObjT, with methods: agx::Referenced* ObjT::getInternalData() const; voi...
Definition: InternalData.h:33
Elementary secondary constraint to keep constraint angle at a given target position.
Representation of a name string.
Definition: Name.h:33
Elementary secondary constraint to keep constraint angle within two given values.
Base class providing referencing counted objects.
Definition: Referenced.h:120
All ghost variables have compliance and damping attributes.
Constraint attachment class for agx::RigidBody.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
Elementary secondary constraint to drive something given target speed (translational or rotational).
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define CALLABLE
Definition: macros.h:72
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:36
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
bool Bool
Definition: Integer.h:40
uint64_t UInt
Definition: Integer.h:27
agx::SetVector< ref_ptr< Constraint > > ConstraintRefSetVector
Definition: Constraint.h:55
double Real
Definition: Real.h:42
int64_t Int
Definition: Integer.h:28