DART
6.7.3
|
The InverseKinematics class provides a convenient way of setting up an IK optimization problem. More...
#include <InverseKinematics.hpp>
Classes | |
class | Analytical |
Analytical is a base class that should be inherited by methods that are made to solve the IK analytically instead of iteratively. More... | |
class | Constraint |
The InverseKinematics::Constraint Function is simply meant to be used to merge the ErrorMethod and GradientMethod that are being held by an InverseKinematics module. More... | |
class | ErrorMethod |
ErrorMethod is a base class for different ways of computing the error of an InverseKinematics module. More... | |
class | Function |
This class should be inherited by optimizer::Function classes that have a dependency on the InverseKinematics module that they belong to. More... | |
class | GradientMethod |
GradientMethod is a base class for different ways of computing the gradient of an InverseKinematics module. More... | |
class | JacobianDLS |
JacobianDLS refers to the Damped Least Squares Jacobian Pseudoinverse (specifically, Moore-Penrose Pseudoinverse). More... | |
class | JacobianTranspose |
JacobianTranspose will simply apply the transpose of the Jacobian to the error vector in order to compute the gradient. More... | |
class | Objective |
The InverseKinematics::Objective Function is simply used to merge the objective and null space objective functions that are being held by an InverseKinematics module. More... | |
class | TaskSpaceRegion |
The TaskSpaceRegion is a nicely generalized method for computing the error of an IK Problem. More... | |
Public Member Functions | |
InverseKinematics (const InverseKinematics &)=delete | |
Copying is not allowed. More... | |
InverseKinematics & | operator= (const InverseKinematics &)=delete |
Assignment is not allowed. More... | |
virtual | ~InverseKinematics () |
Virtual destructor. More... | |
bool | solve (bool _applySolution=true) |
Solve the IK Problem. More... | |
bool | solve (Eigen::VectorXd &positions, bool _applySolution=true) |
Same as solve(bool), but the positions vector will be filled with the solved positions. More... | |
InverseKinematicsPtr | clone (JacobianNode *_newNode) const |
Clone this IK module, but targeted at a new Node. More... | |
void | setActive (bool _active=true) |
If this IK module is set to active, then it will be utilized by any HierarchicalIK that has it in its list. More... | |
void | setInactive () |
Equivalent to setActive(false) More... | |
bool | isActive () const |
Returns true if this IK module is allowed to be active in a HierarchicalIK. More... | |
void | setHierarchyLevel (std::size_t _level) |
Set the hierarchy level of this module. More... | |
std::size_t | getHierarchyLevel () const |
Get the hierarchy level of this modle. More... | |
void | useChain () |
When solving the IK for this module's Node, use the longest available dynamics::Chain that goes from this module's Node towards the root of the Skeleton. More... | |
void | useWholeBody () |
Use all relevant joints on the Skeleton to solve the IK. More... | |
template<class DegreeOfFreedomT > | |
void | setDofs (const std::vector< DegreeOfFreedomT * > &_dofs) |
Explicitly set which degrees of freedom should be used to solve the IK for this module. More... | |
void | setDofs (const std::vector< std::size_t > &_dofs) |
Explicitly set which degrees of freedom should be used to solve the IK for this module. More... | |
const std::vector< std::size_t > & | getDofs () const |
Get the indices of the DOFs that this IK module will use when solving. More... | |
const std::vector< int > & | getDofMap () const |
When a Jacobian is computed for a JacobianNode, it will include a column for every DegreeOfFreedom that the node depends on. More... | |
void | setObjective (const std::shared_ptr< optimizer::Function > &_objective) |
Set an objective function that should be minimized while satisfying the inverse kinematics constraint. More... | |
const std::shared_ptr< optimizer::Function > & | getObjective () |
Get the objective function for this IK module. More... | |
std::shared_ptr< const optimizer::Function > | getObjective () const |
Get the objective function for this IK module. More... | |
void | setNullSpaceObjective (const std::shared_ptr< optimizer::Function > &_nsObjective) |
Set an objective function that should be minimized within the null space of the inverse kinematics constraint. More... | |
const std::shared_ptr< optimizer::Function > & | getNullSpaceObjective () |
Get the null space objective for this IK module. More... | |
std::shared_ptr< const optimizer::Function > | getNullSpaceObjective () const |
Get the null space objective for this IK module. More... | |
bool | hasNullSpaceObjective () const |
Returns false if the null space objective does nothing. More... | |
template<class IKErrorMethod , typename... Args> | |
IKErrorMethod & | setErrorMethod (Args &&... args) |
Set the ErrorMethod for this IK module. More... | |
ErrorMethod & | getErrorMethod () |
Get the ErrorMethod for this IK module. More... | |
const ErrorMethod & | getErrorMethod () const |
Get the ErrorMethod for this IK module. More... | |
template<class IKGradientMethod , typename... Args> | |
IKGradientMethod & | setGradientMethod (Args &&... args) |
Set the GradientMethod for this IK module. More... | |
GradientMethod & | getGradientMethod () |
Get the GradientMethod for this IK module. More... | |
const GradientMethod & | getGradientMethod () const |
Get the GradientMethod for this IK module. More... | |
Analytical * | getAnalytical () |
Get the Analytical IK method for this module, if one is available. More... | |
const Analytical * | getAnalytical () const |
Get the Analytical IK method for this module, if one is available. More... | |
const std::shared_ptr< optimizer::Problem > & | getProblem () |
Get the Problem that is being maintained by this IK module. More... | |
std::shared_ptr< const optimizer::Problem > | getProblem () const |
Get the Problem that is being maintained by this IK module. More... | |
void | resetProblem (bool _clearSeeds=false) |
Reset the Problem that is being maintained by this IK module. More... | |
void | setSolver (const std::shared_ptr< optimizer::Solver > &_newSolver) |
Set the Solver that should be used by this IK module, and set it up with the Problem that is configured by this IK module. More... | |
const std::shared_ptr< optimizer::Solver > & | getSolver () |
Get the Solver that is being used by this IK module. More... | |
std::shared_ptr< const optimizer::Solver > | getSolver () const |
Get the Solver that is being used by this IK module. More... | |
void | setOffset (const Eigen::Vector3d &_offset=Eigen::Vector3d::Zero()) |
Inverse kinematics can be performed on any point within the body frame. More... | |
const Eigen::Vector3d & | getOffset () const |
Get the offset from the origin of the body frame that will be used when performing inverse kinematics. More... | |
bool | hasOffset () const |
This returns false if the offset for the inverse kinematics is a zero vector. More... | |
void | setTarget (std::shared_ptr< SimpleFrame > _newTarget) |
Set the target for this IK module. More... | |
std::shared_ptr< SimpleFrame > | getTarget () |
Get the target that is being used by this IK module. More... | |
std::shared_ptr< const SimpleFrame > | getTarget () const |
Get the target that is being used by this IK module. More... | |
JacobianNode * | getNode () |
Get the JacobianNode that this IK module operates on. More... | |
const JacobianNode * | getNode () const |
Get the JacobianNode that this IK module operates on. More... | |
JacobianNode * | getAffiliation () |
This is the same as getNode(). More... | |
const JacobianNode * | getAffiliation () const |
This is the same as getNode(). More... | |
const math::Jacobian & | computeJacobian () const |
Compute the Jacobian for this IK module's node, using the Skeleton's current joint positions and the DOFs that have been assigned to the module. More... | |
Eigen::VectorXd | getPositions () const |
Get the current joint positions of the Skeleton. More... | |
void | setPositions (const Eigen::VectorXd &_q) |
Set the current joint positions of the Skeleton. More... | |
void | clearCaches () |
Clear the caches of this IK module. More... | |
Static Public Member Functions | |
static InverseKinematicsPtr | create (JacobianNode *_node) |
Create an InverseKinematics module for a specified node. More... | |
Protected Member Functions | |
InverseKinematics (JacobianNode *_node) | |
Constructor that accepts a JacobianNode. More... | |
void | initialize () |
Gets called during construction. More... | |
void | resetTargetConnection () |
Reset the signal connection for this IK module's target. More... | |
void | resetNodeConnection () |
Reset the signal connection for this IK module's Node. More... | |
void | sendDestructionNotification () const |
Send a destruction notification to all Observers. More... | |
void | addObserver (Observer *_observer) const |
Add an Observer to the list of Observers. More... | |
void | removeObserver (Observer *_observer) const |
Remove an Observer from the list of Observers. More... | |
Protected Attributes | |
common::Connection | mTargetConnection |
Connection to the target update. More... | |
common::Connection | mNodeConnection |
Connection to the node update. More... | |
bool | mActive |
True if this IK module should be active in its IK hierarcy. More... | |
std::size_t | mHierarchyLevel |
Hierarchy level for this IK module. More... | |
std::vector< std::size_t > | mDofs |
A list of the DegreeOfFreedom Skeleton indices that will be used by this IK module. More... | |
std::vector< int > | mDofMap |
Map for the DOFs that are to be used by this IK module. More... | |
std::shared_ptr< optimizer::Function > | mObjective |
Objective for the IK module. More... | |
std::shared_ptr< optimizer::Function > | mNullSpaceObjective |
Null space objective for the IK module. More... | |
std::unique_ptr< ErrorMethod > | mErrorMethod |
The method that this IK module will use to compute errors. More... | |
std::unique_ptr< GradientMethod > | mGradientMethod |
The method that this IK module will use to compute gradients. More... | |
Analytical * | mAnalytical |
If mGradientMethod is an Analytical extension, then this will have the same value is mGradientMethod. More... | |
std::shared_ptr< optimizer::Problem > | mProblem |
The Problem that will be maintained by this IK module. More... | |
std::shared_ptr< optimizer::Solver > | mSolver |
The solver that this IK module will use for iterative methods. More... | |
Eigen::Vector3d | mOffset |
The offset that this IK module should use when computing IK. More... | |
bool | mHasOffset |
True if the offset is non-zero. More... | |
std::shared_ptr< SimpleFrame > | mTarget |
Target that this IK module should use. More... | |
sub_ptr< JacobianNode > | mNode |
JacobianNode that this IK module is associated with. More... | |
math::Jacobian | mJacobian |
Jacobian cache for the IK module. More... | |
std::set< Observer * > | mObservers |
List of current Observers. More... | |
Friends | |
class | Objective |
class | Constraint |
The InverseKinematics class provides a convenient way of setting up an IK optimization problem.
It generates constraint functions based on the specified InverseKinematics::ErrorMethod and InverseKinematics::GradientMethod. The optimization problem is then solved by any classes derived from optimizer::Solver class. The default solver is optimizer::GradientDescentSolver.
It also provides a convenient way of specifying a configuration space objective and a null space objective. It is also possible to fully customize the optimizer::Problem that the module creates, and the IK module can be safely cloned over to another JacobianNode, as long as every optimizer::Function that depends on the JacobianNode inherits the InverseKinematics::Function class and correctly overloads the clone function
|
delete |
Copying is not allowed.
|
virtual |
Virtual destructor.
|
protected |
Constructor that accepts a JacobianNode.
|
protectedinherited |
Add an Observer to the list of Observers.
void dart::dynamics::InverseKinematics::clearCaches | ( | ) |
Clear the caches of this IK module.
It should generally not be necessary to call this function. However, if you have some non-standard external dependency for your error and/or gradient method computations, then you will need to tie this function to something that tracks changes in that dependency.
InverseKinematicsPtr dart::dynamics::InverseKinematics::clone | ( | JacobianNode * | _newNode | ) | const |
Clone this IK module, but targeted at a new Node.
Any Functions in the Problem that inherit InverseKinematics::Function will be adapted to the new IK module. Any generic optimizer::Function will just be copied over by pointer instead of being cloned.
const math::Jacobian & dart::dynamics::InverseKinematics::computeJacobian | ( | ) | const |
Compute the Jacobian for this IK module's node, using the Skeleton's current joint positions and the DOFs that have been assigned to the module.
|
static |
Create an InverseKinematics module for a specified node.
JacobianNode * dart::dynamics::InverseKinematics::getAffiliation | ( | ) |
This is the same as getNode().
It is used by the InverseKinematicsPtr to provide a common interface for the various IK smart pointer types.
const JacobianNode * dart::dynamics::InverseKinematics::getAffiliation | ( | ) | const |
This is the same as getNode().
It is used by the InverseKinematicsPtr to provide a common interface for the various IK smart pointer types.
InverseKinematics::Analytical * dart::dynamics::InverseKinematics::getAnalytical | ( | ) |
Get the Analytical IK method for this module, if one is available.
Analytical methods are not provided by default. If this IK module does not have an analytical method, then this will return a nullptr.
const InverseKinematics::Analytical * dart::dynamics::InverseKinematics::getAnalytical | ( | ) | const |
Get the Analytical IK method for this module, if one is available.
Analytical methods are not provided by default. If this IK module does not have an analytical method, then this will return a nullptr.
const std::vector< int > & dart::dynamics::InverseKinematics::getDofMap | ( | ) | const |
When a Jacobian is computed for a JacobianNode, it will include a column for every DegreeOfFreedom that the node depends on.
Given the column index of one of those dependent coordinates, this map will return its location in the mDofs vector. A value of -1 means that it is not present in the mDofs vector and therefore should not be used when performing inverse kinematics.
const std::vector< std::size_t > & dart::dynamics::InverseKinematics::getDofs | ( | ) | const |
Get the indices of the DOFs that this IK module will use when solving.
InverseKinematics::ErrorMethod & dart::dynamics::InverseKinematics::getErrorMethod | ( | ) |
Get the ErrorMethod for this IK module.
Every IK module always has an ErrorMethod available, so this is passed by reference.
const InverseKinematics::ErrorMethod & dart::dynamics::InverseKinematics::getErrorMethod | ( | ) | const |
Get the ErrorMethod for this IK module.
Every IK module always has an ErrorMethod available, so this is passed by reference.
InverseKinematics::GradientMethod & dart::dynamics::InverseKinematics::getGradientMethod | ( | ) |
Get the GradientMethod for this IK module.
Every IK module always has a GradientMethod available, so this is passed by reference.
const InverseKinematics::GradientMethod & dart::dynamics::InverseKinematics::getGradientMethod | ( | ) | const |
Get the GradientMethod for this IK module.
Every IK module always has a GradientMethod available, so this is passed by reference.
std::size_t dart::dynamics::InverseKinematics::getHierarchyLevel | ( | ) | const |
Get the hierarchy level of this modle.
JacobianNode * dart::dynamics::InverseKinematics::getNode | ( | ) |
Get the JacobianNode that this IK module operates on.
const JacobianNode * dart::dynamics::InverseKinematics::getNode | ( | ) | const |
Get the JacobianNode that this IK module operates on.
const std::shared_ptr< optimizer::Function > & dart::dynamics::InverseKinematics::getNullSpaceObjective | ( | ) |
Get the null space objective for this IK module.
std::shared_ptr< const optimizer::Function > dart::dynamics::InverseKinematics::getNullSpaceObjective | ( | ) | const |
Get the null space objective for this IK module.
const std::shared_ptr< optimizer::Function > & dart::dynamics::InverseKinematics::getObjective | ( | ) |
Get the objective function for this IK module.
std::shared_ptr< const optimizer::Function > dart::dynamics::InverseKinematics::getObjective | ( | ) | const |
Get the objective function for this IK module.
const Eigen::Vector3d & dart::dynamics::InverseKinematics::getOffset | ( | ) | const |
Get the offset from the origin of the body frame that will be used when performing inverse kinematics.
The offset will be expressed in the coordinates of the body frame.
Eigen::VectorXd dart::dynamics::InverseKinematics::getPositions | ( | ) | const |
const std::shared_ptr< optimizer::Problem > & dart::dynamics::InverseKinematics::getProblem | ( | ) |
Get the Problem that is being maintained by this IK module.
std::shared_ptr< const optimizer::Problem > dart::dynamics::InverseKinematics::getProblem | ( | ) | const |
Get the Problem that is being maintained by this IK module.
const std::shared_ptr< optimizer::Solver > & dart::dynamics::InverseKinematics::getSolver | ( | ) |
Get the Solver that is being used by this IK module.
std::shared_ptr< const optimizer::Solver > dart::dynamics::InverseKinematics::getSolver | ( | ) | const |
Get the Solver that is being used by this IK module.
std::shared_ptr< SimpleFrame > dart::dynamics::InverseKinematics::getTarget | ( | ) |
Get the target that is being used by this IK module.
You never have to check whether this is a nullptr, because it cannot ever be set to nullptr.
std::shared_ptr< const SimpleFrame > dart::dynamics::InverseKinematics::getTarget | ( | ) | const |
Get the target that is being used by this IK module.
You never have to check whether this is a nullptr, because it cannot ever be set to nullptr.
bool dart::dynamics::InverseKinematics::hasNullSpaceObjective | ( | ) | const |
Returns false if the null space objective does nothing.
bool dart::dynamics::InverseKinematics::hasOffset | ( | ) | const |
This returns false if the offset for the inverse kinematics is a zero vector.
Otherwise, it returns true. Use setOffset() to set the offset and getOffset() to get the offset.
|
protected |
Gets called during construction.
bool dart::dynamics::InverseKinematics::isActive | ( | ) | const |
Returns true if this IK module is allowed to be active in a HierarchicalIK.
|
delete |
Assignment is not allowed.
|
protectedinherited |
Remove an Observer from the list of Observers.
|
protected |
Reset the signal connection for this IK module's Node.
void dart::dynamics::InverseKinematics::resetProblem | ( | bool | _clearSeeds = false | ) |
Reset the Problem that is being maintained by this IK module.
This will clear out all Functions from the Problem and then configure the Problem to use this IK module's Objective and Constraint functions.
Setting _clearSeeds to true will clear out any seeds that have been loaded into the Problem.
|
protected |
Reset the signal connection for this IK module's target.
|
protectedinherited |
Send a destruction notification to all Observers.
This will cause all Observers to behave as if this Subject has been permanently deleted, so it should only be called when that behavior is desired.
void dart::dynamics::InverseKinematics::setActive | ( | bool | _active = true | ) |
If this IK module is set to active, then it will be utilized by any HierarchicalIK that has it in its list.
If it is set to inactive, then it will be ignored by any HierarchicalIK holding onto it, but you can still use the solve() function with this.
void dart::dynamics::InverseKinematics::setDofs | ( | const std::vector< DegreeOfFreedomT * > & | _dofs | ) |
Explicitly set which degrees of freedom should be used to solve the IK for this module.
void dart::dynamics::InverseKinematics::setDofs | ( | const std::vector< std::size_t > & | _dofs | ) |
Explicitly set which degrees of freedom should be used to solve the IK for this module.
The values in the vector should correspond to the Skeleton indices of each DOF.
IKErrorMethod & dart::dynamics::InverseKinematics::setErrorMethod | ( | Args &&... | args | ) |
Set the ErrorMethod for this IK module.
You can pass in arguments for the constructor, but you should ignore the constructor's first argument. The first argument of the ErrorMethod's constructor must be a pointer to this IK module, which will be automatically passed by this function.
IKGradientMethod & dart::dynamics::InverseKinematics::setGradientMethod | ( | Args &&... | args | ) |
Set the GradientMethod for this IK module.
You can pass in arguments for the constructor, but you should ignore the constructor's first argument. The first argument of the GradientMethod's constructor must be a pointer to this IK module, which will be automatically passed by this function.
void dart::dynamics::InverseKinematics::setHierarchyLevel | ( | std::size_t | _level | ) |
Set the hierarchy level of this module.
Modules with a larger hierarchy value will be projected through the null spaces of all modules with a smaller hierarchy value. In other words, IK modules with a hierarchy level closer to 0 are given higher priority.
void dart::dynamics::InverseKinematics::setInactive | ( | ) |
Equivalent to setActive(false)
void dart::dynamics::InverseKinematics::setNullSpaceObjective | ( | const std::shared_ptr< optimizer::Function > & | _nsObjective | ) |
Set an objective function that should be minimized within the null space of the inverse kinematics constraint.
The gradient of this function will always be projected through the null space of this IK module's Jacobian. Pass in a nullptr to remove the null space objective.
Note: The objectives given to setObjective() and setNullSpaceObjective() will always be superimposed (added together) via the evalObjective() function.
void dart::dynamics::InverseKinematics::setObjective | ( | const std::shared_ptr< optimizer::Function > & | _objective | ) |
Set an objective function that should be minimized while satisfying the inverse kinematics constraint.
Pass in a nullptr to remove the objective and make it a constant-zero function.
void dart::dynamics::InverseKinematics::setOffset | ( | const Eigen::Vector3d & | _offset = Eigen::Vector3d::Zero() | ) |
Inverse kinematics can be performed on any point within the body frame.
The default point is the origin of the body frame. Use this function to change the point that will be used. _offset must represent the offset of the desired point from the body origin, expressed in coordinates of the body frame.
void dart::dynamics::InverseKinematics::setPositions | ( | const Eigen::VectorXd & | _q | ) |
void dart::dynamics::InverseKinematics::setSolver | ( | const std::shared_ptr< optimizer::Solver > & | _newSolver | ) |
Set the Solver that should be used by this IK module, and set it up with the Problem that is configured by this IK module.
void dart::dynamics::InverseKinematics::setTarget | ( | std::shared_ptr< SimpleFrame > | _newTarget | ) |
Set the target for this IK module.
Note that a target will automatically be created for the IK module upon instantiation, so you typically do not need to use this function. If you want to attach the target to an arbitrary (non-SimpleFrame) reference frame, you can do getTarget()->setParentFrame(arbitraryFrame)
bool dart::dynamics::InverseKinematics::solve | ( | bool | _applySolution = true | ) |
Solve the IK Problem.
The initial guess for the IK optimization problem is the current joint positions of the target system. If the iterative solver fails to find a successive solution, it attempts more to solve the problem with other seed configurations or random configurations if enough seed is not provided.
Here is the pseudocode as described above:
By default, the max_attempts is 1, but this can be changed by calling InverseKinematics::getSolver() and casting the SolverPtr to an optimizer::GradientDescentSolver (unless you have changed the Solver type) and then calling GradientDescentSolver::setMaxAttempts(std::size_t).
By default, the list of seeds is empty, but they can be added by calling InverseKinematics::getProblem() and then using Problem::addSeed(Eigen::VectorXd).
By default, the Skeleton itself will retain the solved joint positions. If you pass in false for _applySolution, then the joint positions will be returned to their original positions after the problem is solved.
Calling this function will automatically call Position::setLowerBounds(~) and Position::setUpperBounds(~) with the lower/upper position bounds of the corresponding Degrees Of Freedom. Problem::setDimension(~) will be taken care of automatically, and Problem::setInitialGuess(~) will be called with the current positions of the Degrees Of Freedom.
bool dart::dynamics::InverseKinematics::solve | ( | Eigen::VectorXd & | positions, |
bool | _applySolution = true |
||
) |
Same as solve(bool), but the positions vector will be filled with the solved positions.
void dart::dynamics::InverseKinematics::useChain | ( | ) |
When solving the IK for this module's Node, use the longest available dynamics::Chain that goes from this module's Node towards the root of the Skeleton.
Using this will prevent any other branches in the Skeleton from being affected by this IK module.
void dart::dynamics::InverseKinematics::useWholeBody | ( | ) |
Use all relevant joints on the Skeleton to solve the IK.
|
friend |
|
friend |
|
protected |
True if this IK module should be active in its IK hierarcy.
|
protected |
If mGradientMethod is an Analytical extension, then this will have the same value is mGradientMethod.
Otherwise, this will be a nullptr.
Note that this pointer's memory does not need to be managed, because it is always either nullptr or a reference to mGradientMethod.
|
protected |
Map for the DOFs that are to be used by this IK module.
|
protected |
A list of the DegreeOfFreedom Skeleton indices that will be used by this IK module.
|
protected |
The method that this IK module will use to compute errors.
|
protected |
The method that this IK module will use to compute gradients.
|
protected |
True if the offset is non-zero.
|
protected |
Hierarchy level for this IK module.
|
mutableprotected |
Jacobian cache for the IK module.
|
protected |
JacobianNode that this IK module is associated with.
|
protected |
Connection to the node update.
|
protected |
Null space objective for the IK module.
|
protected |
Objective for the IK module.
|
mutableprotectedinherited |
List of current Observers.
|
protected |
The offset that this IK module should use when computing IK.
|
protected |
The Problem that will be maintained by this IK module.
|
protected |
The solver that this IK module will use for iterative methods.
|
protected |
Target that this IK module should use.
|
protected |
Connection to the target update.