AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
agxModel::SerialKinematicChain Class Reference

A Serial Kinematic Chain is a KinematicChain where there are no loops or branches. More...

#include <KinematicChain.h>

+ Inheritance diagram for agxModel::SerialKinematicChain:

Public Member Functions

 SerialKinematicChain (agxSDK::Simulation &simulation, const agx::RigidBody &base, const agx::RigidBody &end, const agx::AffineMatrix4x4 *endLocalTransform=nullptr)
 Create a serial chain from "base" to "end" by traversing the bodies and constraints in the simulation.
 
 SerialKinematicChain (const agx::RigidBodyPtrVector &bodies, const agx::ConstraintPtrVector &constraints, const agx::AffineMatrix4x4 *endLocalTransform=nullptr)
 Create a serial chain from the input bodies and constraints which are provided in the correct order.
 
KinematicChainStatus computeForwardKinematics (const agx::RealVector &jointPositions, agx::AffineMatrix4x4 &outputTransform, bool clampToJointLimits=false)
 Compute the transform for the end of the chain relative the base given the provided joint values.
 
KinematicChainStatus computeForwardKinematicsAll (const agx::RealVector &jointPositions, agx::AffineMatrix4x4Vector &outputTransforms, bool clampToJointLimits=false)
 Compute the transform for all links in the chain relative the base given provided joint values.
 
KinematicChainStatus computeForwardKinematicsAll (const agx::RealVector &jointPositions, const agx::RealVector &jointVelocities, agx::AffineMatrix4x4Vector &outputTransforms, agx::Vec3Vector &outputLinearVelocities, agx::Vec3Vector &outputAngularVelocities, bool clampToJointLimits=false)
 Compute the transforms and velocities for all links in the chain relative the base given provided joint values.
 
KinematicChainStatus computeInverseDynamics (const agx::RealVector &jointAcceleration, agx::RealVector &tau)
 Compute the torque/forces needed to get the specified jointAccelerations.
 
KinematicChainStatus computeInverseDynamics (const agx::RealVector &jointAcceleration, const agx::RealVector &externalForces, agx::RealVector &tau)
 Compute the torque/forces needed to get the specified jointAccelerations.
 
KinematicChainStatus computeInverseKinematics (const agx::AffineMatrix4x4 &transform, const agx::RealVector &currentJointPositions, agx::RealVector &outputJointPositions, agx::Real solverEpsilon=1e-5)
 Compute joint positions needed for the end body in the chain to get the specified transform relative the base.
 
KinematicChainStatus computeManipulatorJacobian (const agx::RealVector &jointPositions, agx::RealVector &jacobian)
 Compute the manipulator jacobian relative the base.
 
const agx::ConstraintRefVector & getJoints () const
 Get the joints that are in the chain.
 
const agx::RigidBodyRefVector & getLinks () const
 Get the links that are in the chain.
 
agx::UInt getNumJoints () const
 Returns number of joints in the chain where motion can occur.
 
agx::UInt getNumLinks () const
 Returns number of links in the chain.
 
bool isValid () const
 Check if the chain was valid at time of creation.
 
void setSimulation (agxSDK::Simulation *sim)
 Set the Simulation that is used to read certain values needed for inverse dynamics computations.
 
- Public Member Functions inherited from agx::Referenced
 Referenced ()
 Default constructor.
 
 Referenced (const Referenced &)
 
template<typename T >
T * as ()
 Subclass casting.
 
template<typename T >
const T * as () const
 
template<typename T >
T * asSafe ()
 Safe subclass casting, return nullptr if template type does not match.
 
template<typename T >
const T * asSafe () const
 
int getReferenceCount () const
 
template<typename T >
bool is () const
 Subclass test.
 
Referenced & operator= (const Referenced &)
 Assignment operator. Will increment the number of references to the referenced object.
 
void reference (void *ptr=nullptr) const
 Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
 
void unreference (void *ptr=nullptr) const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 
void unreference_nodelete () const
 Decrement the reference count by one, indicating that a pointer to this object is referencing it.
 

Protected Member Functions

 SerialKinematicChain ()
 
 ~SerialKinematicChain ()
 
- Protected Member Functions inherited from agx::Referenced
virtual ~Referenced ()
 Destructor.
 
void allocateObserverVector () const
 
void deleteUsingDeleteHandler () const
 

Additional Inherited Members

- Public Types inherited from agxModel::KinematicChain
enum  KinematicChainStatus {
  SUCCESS , INVALID_CHAIN , BAD_INPUT_ARGUMENTS , SOLVER_FAILURE ,
  NO_SIMULATION
}
 
- Static Public Member Functions inherited from agx::Referenced
template<typename T >
static bool ValidateCast (const Referenced *object)
 
- 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.
 
- Protected Attributes inherited from agx::Referenced
Mutex m_mutex
 
ObserverContainer m_observers
 
AtomicValue m_refCount
 

Detailed Description

A Serial Kinematic Chain is a KinematicChain where there are no loops or branches.

When a chain is specified, it is via a series of agx::RigidBody and agx::Constraint objects where the number of rigid bodies is one more than number of constraints.

Bodies are expected to be handled as 6-dof bodies and having setHandleAsParticle enabled is not supported.

The constraint types that are supported are:

  • Rotational / Hinge
  • Sliding / Prismatic
  • Fixed / LockJoint

The first two constraint types remove 5 degrees of freedom (dof) each where as the lock removes 6 dofs.

After the chain representation is created, querying the number of joints in the chain will give the number of constraints that leave 1 degree of freedom (rotation or sliding) for the connected body. This is the same number of joint values which should be provided to the computeForwardKinematics function or are outputted from computeInverseKinematics or computeInverseDynamics.

If the coordinate frame of interest does not align with the model coordinate system for the final body/link/segment in the chain, then there is a possibility to append a local transform in the end links coordinate system. The appended transform will be the final transform from the chain. This optional appended transform is fixed relative the last body and does not increase the number of joint values that are expected as input or produced as output. It does increase the number of link outputs with one.

Note
Kinematic computations can be performed if the chain is valid. Performing inverse dynamics computations has one additional requirement: being able to access data in the simulation that contains the bodies and constraints. If a constructor is used that does not take a Simulation as parameter, then calling setSimulation must be performed before computeInverseDynamics can be used.

Definition at line 98 of file KinematicChain.h.

Constructor & Destructor Documentation

◆ SerialKinematicChain() [1/3]

agxModel::SerialKinematicChain::SerialKinematicChain ( agxSDK::Simulation &  simulation,
const agx::RigidBody &  base,
const agx::RigidBody &  end,
const agx::AffineMatrix4x4 *  endLocalTransform = nullptr 
)

Create a serial chain from "base" to "end" by traversing the bodies and constraints in the simulation.

The chain will contain relative transforms from when it was created. Any changes to e.g. a constraint attachment frame will not be seen. If the kinematic structure is changed, then the chain must be recreated.

Parameters
simulationThe simulation in which to traverse bodies and constraints to find a chain between "base" and "end".
baseThe first body in the chain
endThe last body in the chain
endLocalTransformAn optional transform expressed in the last bodies frame which extends the chain with one additional link.

◆ SerialKinematicChain() [2/3]

agxModel::SerialKinematicChain::SerialKinematicChain ( const agx::RigidBodyPtrVector &  bodies,
const agx::ConstraintPtrVector &  constraints,
const agx::AffineMatrix4x4 *  endLocalTransform = nullptr 
)

Create a serial chain from the input bodies and constraints which are provided in the correct order.

The chain will contain relative transforms from when it was created. Any changes to e.g. a constraint attachment frame will not be seen. If the kinematic structure is changed, then the chain must be recreated.

Note
Number of bodies should be equal to number of constraints + 1. The first body in the bodies vector is "base" and the last one is "end". For well formed input, bodies[i] and bodies[i+1] are connected via constraints[i].
Parameters
bodiesA vector with the bodies in the chain
constraintsA vector with constraints that connect the bodies
endLocalTransformAn optional transform expressed in the last bodies frame which extends the chain with one additional link.

◆ SerialKinematicChain() [3/3]

agxModel::SerialKinematicChain::SerialKinematicChain ( )
protected

◆ ~SerialKinematicChain()

agxModel::SerialKinematicChain::~SerialKinematicChain ( )
protected

Member Function Documentation

◆ computeForwardKinematics()

KinematicChainStatus agxModel::SerialKinematicChain::computeForwardKinematics ( const agx::RealVector &  jointPositions,
agx::AffineMatrix4x4 &  outputTransform,
bool  clampToJointLimits = false 
)

Compute the transform for the end of the chain relative the base given the provided joint values.

By default, the pose is computed given the provided values as is regardless if the joints have limits or not.

Parameters
jointPositionsVector with the same number of joint values as there are joints in the chain.
outputTransformThe transform for the end body relative the base. Only written if method returns success.
clampToJointLimitsIf true, then each value in jointPositions will be clamped to corresponding joints range before computing the pose.
Returns
Status code indicating if function succeeded.

◆ computeForwardKinematicsAll() [1/2]

KinematicChainStatus agxModel::SerialKinematicChain::computeForwardKinematicsAll ( const agx::RealVector &  jointPositions,
agx::AffineMatrix4x4Vector &  outputTransforms,
bool  clampToJointLimits = false 
)

Compute the transform for all links in the chain relative the base given provided joint values.

For a chain with N links, there will be N AffineMatrix4x4 in the output vector. The first item for "base" will be an identity matrix.

By default, the poses are computed given the provided values as is regardless if the joints have limits or not.

Parameters
jointPositionsVector with the same number of joint positions as there are joints in the chain.
outputTransformsVector with transforms. Only written if method returns success.
clampToJointLimitsIf true, then each value in jointPositions will be clamped to corresponding joints range before computing the pose.
Returns
Status code indicating if function succeeded.

◆ computeForwardKinematicsAll() [2/2]

KinematicChainStatus agxModel::SerialKinematicChain::computeForwardKinematicsAll ( const agx::RealVector &  jointPositions,
const agx::RealVector &  jointVelocities,
agx::AffineMatrix4x4Vector &  outputTransforms,
agx::Vec3Vector &  outputLinearVelocities,
agx::Vec3Vector &  outputAngularVelocities,
bool  clampToJointLimits = false 
)

Compute the transforms and velocities for all links in the chain relative the base given provided joint values.

By default, the poses are computed given the provided values as is regardless if the joints have limits or not.

Parameters
jointPositionsVector with the same number of joint positions as there are joints in the chain.
jointVelocitiesVector with the same number of joint velocities as there are joints in the chain.
outputTransformsVector with transforms. Only written if method returns success.
outputLinearVelocitiesVector with computed linear velocity for each link.
outputAngularVelocitiesVector with computed angular velocity for each link.
clampToJointLimitsIf true, then each value in jointPositions will be clamped to corresponding joints range before computing the pose.
Returns
Status code indicating if function succeeded.

◆ computeInverseDynamics() [1/2]

KinematicChainStatus agxModel::SerialKinematicChain::computeInverseDynamics ( const agx::RealVector &  jointAcceleration,
agx::RealVector &  tau 
)

Compute the torque/forces needed to get the specified jointAccelerations.

Current joint positions and velocities are read from bodies and constraints forming the chain.

Parameters
jointAccelerationDesired joint acceleration.
tauOutput torques/forces.
Returns
Status code indicating if function succeeded.

◆ computeInverseDynamics() [2/2]

KinematicChainStatus agxModel::SerialKinematicChain::computeInverseDynamics ( const agx::RealVector &  jointAcceleration,
const agx::RealVector &  externalForces,
agx::RealVector &  tau 
)

Compute the torque/forces needed to get the specified jointAccelerations.

Current joint positions and velocities are read from bodies and constraints forming the chain.

Parameters
jointAccelerationDesired joint acceleration.
tauOutput torques/forces.
Returns
Status code indicating if function succeeded.
Parameters
externalForcesExtra external forces acting on the bodies. This vector should have 6 elements (3 force, 3 torque) for each body in the chain.
Returns
Status code indicating if function succeeded.

◆ computeInverseKinematics()

KinematicChainStatus agxModel::SerialKinematicChain::computeInverseKinematics ( const agx::AffineMatrix4x4 &  transform,
const agx::RealVector &  currentJointPositions,
agx::RealVector &  outputJointPositions,
agx::Real  solverEpsilon = 1e-5 
)

Compute joint positions needed for the end body in the chain to get the specified transform relative the base.

Parameters
transformDesired transform for the end body relative the base.
currentJointPositionsVector with current positions for each joint which has a degree of freedom.
outputJointPositionsVector to which joint values will be stored.
solverEpsilonprecision for IK solution
Returns
Status code indicating if function succeeded.

◆ computeManipulatorJacobian()

KinematicChainStatus agxModel::SerialKinematicChain::computeManipulatorJacobian ( const agx::RealVector &  jointPositions,
agx::RealVector &  jacobian 
)

Compute the manipulator jacobian relative the base.

This jacobian gives a relationship between end effector velocities and joint velocities.

Parameters
jointPositionsJoint positions for which the jacobian should be evaluated
jacobianA vector where the output 6xN jacobian is stored by row.
Returns
Status code indicating if function succeeded.

◆ getJoints()

const agx::ConstraintRefVector & agxModel::SerialKinematicChain::getJoints ( ) const

Get the joints that are in the chain.

◆ getLinks()

const agx::RigidBodyRefVector & agxModel::SerialKinematicChain::getLinks ( ) const

Get the links that are in the chain.

◆ getNumJoints()

agx::UInt agxModel::SerialKinematicChain::getNumJoints ( ) const

Returns number of joints in the chain where motion can occur.

This number does not have to match the input number of constraints since it only includes joints which have 1 degree of freedom (rotation or sliding).

Inputs and outputs in joint space should have this number of elements.

◆ getNumLinks()

agx::UInt agxModel::SerialKinematicChain::getNumLinks ( ) const

Returns number of links in the chain.

This number often corresponds to the number of bodies that were used when creating the chain representation. If a final "end transform" was specified, then the link count is increased by 1.

◆ isValid()

bool agxModel::SerialKinematicChain::isValid ( ) const

Check if the chain was valid at time of creation.

Modifying bodies (e.g. enabling treat as particle) or constraints (e.g. adding additional elementary constraints) will in many cases cause compute methods to return INVALID_CHAIN regardless of if this method returns true or not.

Returns
True if a valid was constructed.

◆ setSimulation()

void agxModel::SerialKinematicChain::setSimulation ( agxSDK::Simulation *  sim)

Set the Simulation that is used to read certain values needed for inverse dynamics computations.

Calling this method is needed if a constructor was used that did not take a Simulation as argument.


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