33 #ifndef DART_DYNAMICS_HIERARCHICALIK_HPP_
34 #define DART_DYNAMICS_HIERARCHICALIK_HPP_
36 #include <unordered_set>
48 typedef std::vector< std::vector< std::shared_ptr<InverseKinematics> > >
IKHierarchy;
73 bool solve(
bool _applySolution =
true);
77 bool solve(Eigen::VectorXd& positions,
bool _applySolution =
true);
80 virtual std::shared_ptr<HierarchicalIK>
clone(
96 const std::shared_ptr<HierarchicalIK>& _newIK)
const = 0;
103 void setObjective(
const std::shared_ptr<optimizer::Function>& _objective);
106 const std::shared_ptr<optimizer::Function>&
getObjective();
109 std::shared_ptr<const optimizer::Function>
getObjective()
const;
113 const std::shared_ptr<optimizer::Function>& _nsObjective);
125 const std::shared_ptr<optimizer::Problem>&
getProblem();
128 std::shared_ptr<const optimizer::Problem>
getProblem()
const;
140 void setSolver(
const std::shared_ptr<optimizer::Solver>& _newSolver);
143 const std::shared_ptr<optimizer::Solver>&
getSolver();
146 std::shared_ptr<const optimizer::Solver>
getSolver()
const;
195 Objective(
const std::shared_ptr<HierarchicalIK>& _ik);
202 const std::shared_ptr<HierarchicalIK>& _newIK)
const override;
205 double eval(
const Eigen::VectorXd &_x)
override;
209 Eigen::Map<Eigen::VectorXd> _grad)
override;
214 std::weak_ptr<HierarchicalIK>
mIK;
230 Constraint(
const std::shared_ptr<HierarchicalIK>& _ik);
237 const std::shared_ptr<HierarchicalIK>& _newIK)
const override;
240 double eval(
const Eigen::VectorXd& _x)
override;
244 Eigen::Map<Eigen::VectorXd> _grad)
override;
249 std::weak_ptr<HierarchicalIK>
mIK;
262 void initialize(
const std::shared_ptr<HierarchicalIK>& my_ptr);
266 void copyOverSetup(
const std::shared_ptr<HierarchicalIK>& _otherIK)
const;
287 std::weak_ptr<HierarchicalIK>
mPtr;
306 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
316 typedef std::unordered_set< std::shared_ptr<InverseKinematics> >
ModuleSet;
317 typedef std::unordered_set< std::shared_ptr<const InverseKinematics> >
ConstModuleSet;
323 std::shared_ptr<HierarchicalIK>
clone(
333 bool addModule(
const std::shared_ptr<InverseKinematics>& _ik);
350 std::unordered_set< std::shared_ptr<InverseKinematics> >
mModuleSet;
364 std::shared_ptr<HierarchicalIK>
clone(
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition: Subject.hpp:58
The CompositeIK class allows you to specify an arbitrary hierarchy of InverseKinematics modules for a...
Definition: HierarchicalIK.hpp:313
void refreshIKHierarchy() override
Refresh the IK hierarchy of this IK module.
Definition: HierarchicalIK.cpp:681
std::unordered_set< std::shared_ptr< const InverseKinematics > > ConstModuleSet
Definition: HierarchicalIK.hpp:317
static std::shared_ptr< CompositeIK > create(const SkeletonPtr &_skel)
Create a CompositeIK module.
Definition: HierarchicalIK.cpp:602
CompositeIK(const SkeletonPtr &_skel)
Constructor.
Definition: HierarchicalIK.cpp:707
std::unordered_set< std::shared_ptr< InverseKinematics > > mModuleSet
The set of modules being used by this CompositeIK.
Definition: HierarchicalIK.hpp:350
std::shared_ptr< HierarchicalIK > clone(const SkeletonPtr &_newSkel) const override
Clone this HierarchicalIK module.
Definition: HierarchicalIK.cpp:610
bool addModule(const std::shared_ptr< InverseKinematics > &_ik)
Add an IK module to this CompositeIK.
Definition: HierarchicalIK.cpp:647
std::unordered_set< std::shared_ptr< InverseKinematics > > ModuleSet
Definition: HierarchicalIK.hpp:316
virtual std::shared_ptr< CompositeIK > cloneCompositeIK(const SkeletonPtr &_newSkel) const
Same as clone(), but passes back a more complete type.
Definition: HierarchicalIK.cpp:617
const ModuleSet & getModuleSet()
Get the set of modules being used by this CompositeIK.
Definition: HierarchicalIK.cpp:665
The HierarchicalIK::Constraint Function is simply used to merge the constraints of the InverseKinemat...
Definition: HierarchicalIK.hpp:226
Eigen::VectorXd mTempGradCache
Cache for temporary gradients.
Definition: HierarchicalIK.hpp:255
std::weak_ptr< HierarchicalIK > mIK
Pointer to this Constraint's HierarchicalIK module.
Definition: HierarchicalIK.hpp:249
virtual ~Constraint()=default
Virtual destructor.
void evalGradient(const Eigen::VectorXd &_x, Eigen::Map< Eigen::VectorXd > _grad) override
Evaluates and returns the objective function at the point x.
Definition: HierarchicalIK.cpp:487
optimizer::FunctionPtr clone(const std::shared_ptr< HierarchicalIK > &_newIK) const override
Enable this function to be cloned to a new IK module.
Definition: HierarchicalIK.cpp:439
Constraint(const std::shared_ptr< HierarchicalIK > &_ik)
Constructor.
Definition: HierarchicalIK.cpp:432
Eigen::VectorXd mLevelGradCache
Cache for the gradient of a level.
Definition: HierarchicalIK.hpp:252
double eval(const Eigen::VectorXd &_x) override
Evaluates and returns the objective function at the point x.
Definition: HierarchicalIK.cpp:445
This class should be inherited by optimizer::Function classes that have a dependency on the Hierarchi...
Definition: HierarchicalIK.hpp:91
virtual optimizer::FunctionPtr clone(const std::shared_ptr< HierarchicalIK > &_newIK) const =0
Enable this function to be cloned to a new IK module.
virtual ~Function()=default
Virtual destructor.
The HierarchicalIK::Objective Function is simply used to merge the objective and null space objective...
Definition: HierarchicalIK.hpp:191
Objective(const std::shared_ptr< HierarchicalIK > &_ik)
Constructor.
Definition: HierarchicalIK.cpp:356
optimizer::FunctionPtr clone(const std::shared_ptr< HierarchicalIK > &_newIK) const override
Enable this function to be cloned to a new IK module.
Definition: HierarchicalIK.cpp:363
double eval(const Eigen::VectorXd &_x) override
Evaluates and returns the objective function at the point x.
Definition: HierarchicalIK.cpp:370
virtual ~Objective()=default
Virtual destructor.
std::weak_ptr< HierarchicalIK > mIK
Pointer to this Objective's HierarchicalIK module.
Definition: HierarchicalIK.hpp:214
Eigen::VectorXd mGradCache
Cache for the gradient computation.
Definition: HierarchicalIK.hpp:217
void evalGradient(const Eigen::VectorXd &_x, Eigen::Map< Eigen::VectorXd > _grad) override
Evaluates and returns the objective function at the point x.
Definition: HierarchicalIK.cpp:394
The HierarchicalIK class provides a convenient way of setting up a hierarchical inverse kinematics op...
Definition: HierarchicalIK.hpp:63
virtual std::shared_ptr< HierarchicalIK > clone(const SkeletonPtr &_newSkel) const =0
Clone this HierarchicalIK module.
void clearCaches()
Clear the caches of this IK module.
Definition: HierarchicalIK.cpp:350
IKHierarchy mHierarchy
Cache for the IK hierarcy.
Definition: HierarchicalIK.hpp:272
std::shared_ptr< optimizer::Solver > mSolver
The Solver that this IK module will use.
Definition: HierarchicalIK.hpp:278
void resetProblem(bool _clearSeeds=false)
Reset the Problem that is being maintained by this HierarchicalIK module.
Definition: HierarchicalIK.cpp:169
optimizer::FunctionPtr mNullSpaceObjective
The null space Objective of this IK module.
Definition: HierarchicalIK.hpp:284
WeakSkeletonPtr mSkeleton
Pointer to the Skeleton that this IK is tied to.
Definition: HierarchicalIK.hpp:269
bool hasNullSpaceObjective() const
Returns true if this HierarchicalIK has a null space objective.
Definition: HierarchicalIK.cpp:151
optimizer::FunctionPtr mObjective
The Objective of this IK module.
Definition: HierarchicalIK.hpp:281
void setNullSpaceObjective(const std::shared_ptr< optimizer::Function > &_nsObjective)
Set the null space objective for this HierarchicalIK.
Definition: HierarchicalIK.cpp:130
const std::shared_ptr< optimizer::Solver > & getSolver()
Get the Solver that is being used by this IK module.
Definition: HierarchicalIK.cpp:195
void setPositions(const Eigen::VectorXd &_q)
Set the current joint positions of the Skeleton associated with this IK module.
Definition: HierarchicalIK.cpp:318
const IKHierarchy & getIKHierarchy() const
Get the IK hierarchy of this IK module.
Definition: HierarchicalIK.cpp:207
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 configur...
Definition: HierarchicalIK.cpp:184
const std::shared_ptr< optimizer::Function > & getObjective()
Get the objective function for this HierarchicalIK.
Definition: HierarchicalIK.cpp:118
virtual ~HierarchicalIK()=default
Virtual destructor.
virtual void refreshIKHierarchy()=0
Refresh the IK hierarchy of this IK module.
SkeletonPtr getAffiliation()
This is the same as getSkeleton().
Definition: HierarchicalIK.cpp:338
void initialize(const std::shared_ptr< HierarchicalIK > &my_ptr)
Setup the module.
Definition: HierarchicalIK.cpp:548
const std::shared_ptr< optimizer::Problem > & getProblem()
Get the Problem that is being maintained by this HierarchicalIK module.
Definition: HierarchicalIK.cpp:157
std::weak_ptr< HierarchicalIK > mPtr
Weak pointer to self.
Definition: HierarchicalIK.hpp:287
void copyOverSetup(const std::shared_ptr< HierarchicalIK > &_otherIK) const
Copy the setup of this HierarchicalIK module into another HierarchicalIK module.
Definition: HierarchicalIK.cpp:579
Eigen::VectorXd mLastPositions
Cache for the last positions.
Definition: HierarchicalIK.hpp:290
std::vector< Eigen::MatrixXd > mNullSpaceCache
Cache for null space computations.
Definition: HierarchicalIK.hpp:293
bool solve(bool _applySolution=true)
Solve the IK Problem.
Definition: HierarchicalIK.cpp:44
const std::shared_ptr< optimizer::Function > & getNullSpaceObjective()
Get the null space objective for this HierarchicalIK.
Definition: HierarchicalIK.cpp:138
const std::vector< Eigen::MatrixXd > & computeNullSpaces() const
Compute the null spaces of each level of the hierarchy.
Definition: HierarchicalIK.cpp:213
void setObjective(const std::shared_ptr< optimizer::Function > &_objective)
Set the objective function for this HierarchicalIK.
Definition: HierarchicalIK.cpp:111
Eigen::MatrixXd mPartialNullspaceCache
Cache for a partial null space computation.
Definition: HierarchicalIK.hpp:296
std::shared_ptr< optimizer::Problem > mProblem
The Problem that this IK module is maintaining.
Definition: HierarchicalIK.hpp:275
Eigen::JacobiSVD< math::Jacobian > mSVDCache
Cache for the null space SVD.
Definition: HierarchicalIK.hpp:299
Eigen::VectorXd getPositions() const
Get the current joint positions of the Skeleton associated with this IK module.
Definition: HierarchicalIK.cpp:308
SkeletonPtr getSkeleton()
Get the Skeleton that this IK module is associated with.
Definition: HierarchicalIK.cpp:326
HierarchicalIK(const SkeletonPtr &_skeleton)
Constructor.
Definition: HierarchicalIK.cpp:540
math::Jacobian mJacCache
Cache for Jacobians.
Definition: HierarchicalIK.hpp:302
The WholeBodyIK class provides an interface for simultaneously solving all the IK constraints of all ...
Definition: HierarchicalIK.hpp:357
WholeBodyIK(const SkeletonPtr &_skel)
Constructor.
Definition: HierarchicalIK.cpp:802
virtual std::shared_ptr< WholeBodyIK > cloneWholeBodyIK(const SkeletonPtr &_newSkel) const
Same as clone(), but produces a more complete type.
Definition: HierarchicalIK.cpp:729
static std::shared_ptr< WholeBodyIK > create(const SkeletonPtr &_skel)
Create a WholeBodyIK.
Definition: HierarchicalIK.cpp:714
void refreshIKHierarchy() override
Refresh the IK hierarchy of this IK module.
Definition: HierarchicalIK.cpp:738
std::shared_ptr< HierarchicalIK > clone(const SkeletonPtr &_newSkel) const override
Clone this HierarchicalIK module.
Definition: HierarchicalIK.cpp:722
Definition: Function.hpp:46
std::shared_ptr< const Skeleton > ConstSkeletonPtr
Definition: SmartPointer.hpp:60
std::vector< std::vector< std::shared_ptr< InverseKinematics > > > IKHierarchy
An IKHierarchy is a sorted set of IK modules.
Definition: HierarchicalIK.hpp:48
std::weak_ptr< Skeleton > WeakSkeletonPtr
Definition: SmartPointer.hpp:60
std::shared_ptr< Skeleton > SkeletonPtr
Definition: SmartPointer.hpp:60
Eigen::Matrix< double, 6, Eigen::Dynamic > Jacobian
Definition: MathTypes.hpp:108
std::shared_ptr< Function > FunctionPtr
Definition: Function.hpp:84
Definition: BulletCollisionDetector.cpp:63