20 template <
typename KINEMATICS,
typename SCALAR =
double>
24 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 static const size_t NJOINTS = KINEMATICS::NJOINTS;
29 const Eigen::Matrix3d&
Qpos = Eigen::Matrix3d::Identity(),
30 const Eigen::Matrix3d&
Qrot = Eigen::Matrix3d::Identity())
33 jointRefTerm_(nullptr),
34 ikRegularizer_(nullptr)
39 const std::string& termTaskspaceName,
45 jointRefTerm_(nullptr),
46 ikRegularizer_(nullptr)
52 const std::string& termTaskspaceName,
53 const std::string& termJointPosName,
60 new
ct::
optcon::TermQuadratic<NJOINTS, NJOINTS,
SCALAR>(costFunctionPath, termJointPosName,
verbose)),
61 ikRegularizer_(nullptr)
71 void setRegularizer(std::shared_ptr<IKRegularizerBase> reg) { ikRegularizer_ = reg; }
78 goalCostTerm_->setReferencePosition(rbdPose.
position().toImplementation());
85 goalCostTerm_->setReferencePosition(w_pos_des);
86 goalCostTerm_->setReferenceOrientation(w_q_des);
92 goalCostTerm_->setReferencePosition(w_pos_des);
93 goalCostTerm_->setReferenceOrientation(
94 Eigen::Quaterniond(Eigen::AngleAxisd(eulerXyz(0), Eigen::Vector3d::UnitX()) *
95 Eigen::AngleAxisd(eulerXyz(1), Eigen::Vector3d::UnitY()) *
96 Eigen::AngleAxisd(eulerXyz(2), Eigen::Vector3d::UnitZ())));
105 goalCostTerm_->evaluate(w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
109 jointRefTerm_->evaluate(w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
114 throw std::runtime_error(
"IKCostEvaluator: optimization vector not set.");
118 virtual void evalGradient(
size_t grad_length, Eigen::Map<Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>>& grad)
override 120 assert(grad_length == NJOINTS);
124 grad = goalCostTerm_->stateDerivative(
125 w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
128 grad += jointRefTerm_->stateDerivative(
129 w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
132 throw std::runtime_error(
"IKCostEvaluator: optimization vector not set.");
140 iRow.resize(NJOINTS * NJOINTS);
141 jCol.resize(NJOINTS * NJOINTS);
146 for (
size_t j = 0; j <
NJOINTS; j++)
159 const Eigen::VectorXd& obj_fac,
160 Eigen::VectorXd& hes)
override 162 hes.resize(NJOINTS * NJOINTS);
167 Eigen::Map<Eigen::Matrix<SCALAR, NJOINTS, NJOINTS>> Hmat(hes.data(),
NJOINTS,
NJOINTS);
169 Hmat = goalCostTerm_->stateSecondDerivative(
170 w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
173 Hmat += jointRefTerm_->stateSecondDerivative(
174 w_->getOptimizationVars(), Eigen::Matrix<double, NJOINTS, 1>::Zero(), 0.0);
177 Hmat += ikRegularizer_->computeRegularizer(w_->getOptimizationVars());
179 Hmat *= obj_fac(0, 0);
182 throw std::runtime_error(
"IKCostEvaluator: optimization vector not set.");
187 std::shared_ptr<ct::optcon::tpl::OptVector<SCALAR>> w_;
189 std::shared_ptr<ct::rbd::TermTaskspaceGeometricJacobian<KINEMATICS, NJOINTS, NJOINTS>> goalCostTerm_;
191 std::shared_ptr<ct::optcon::TermQuadratic<NJOINTS, NJOINTS, SCALAR>> jointRefTerm_;
193 std::shared_ptr<IKRegularizerBase>
void setTargetPose(const core::StateVector< 3 > &w_pos_des, const Eigen::Quaterniond &w_q_des)
Definition: IKCostEvaluator.h:83
Inverse Kinematics cost evaluator for NLP.
Definition: IKCostEvaluator.h:21
void setTargetPose(const core::StateVector< 3 > &w_pos_des, const Eigen::Matrix3d &eulerXyz)
Definition: IKCostEvaluator.h:90
void sparseHessianValues(const Eigen::VectorXd &jointAngles, const Eigen::VectorXd &obj_fac, Eigen::VectorXd &hes) override
retrieve second order derivative
Definition: IKCostEvaluator.h:158
void setTargetPose(const ct::rbd::RigidBodyPose &rbdPose)
Definition: IKCostEvaluator.h:76
IKCostEvaluator(const std::string &costFunctionPath, const std::string &termTaskspaceName, const std::string &termJointPosName, const bool verbose=false)
Definition: IKCostEvaluator.h:51
const Position3Tpl & position() const
This method returns the position of the Base frame in the inertia frame.
Definition: RigidBodyPose.h:246
virtual void getSparsityPatternHessian(Eigen::VectorXi &iRow, Eigen::VectorXi &jCol) override
create sparsity pattern for the hessian (simply fill up completely)
Definition: IKCostEvaluator.h:138
A costfunction term that defines a cost on a task-space pose, for fix-base robots only...
Definition: TermTaskspaceGeometricJacobian.hpp:24
virtual SCALAR eval() override
evaluate cost function
Definition: IKCostEvaluator.h:100
CppAD::AD< CppAD::cg::CG< double > > SCALAR
bool verbose
Definition: rbdJITtests.h:15
~IKCostEvaluator() override=default
double Qrot
Definition: rbdJITtests.h:28
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t NJOINTS
Definition: IKCostEvaluator.h:26
kindr::RotationQuaternion< SCALAR > getRotationQuaternion() const
This method returns the quaternion rotation.
Definition: RigidBodyPose.h:134
IKCostEvaluator(size_t eeInd, const Eigen::Matrix3d &Qpos=Eigen::Matrix3d::Identity(), const Eigen::Matrix3d &Qrot=Eigen::Matrix3d::Identity())
Definition: IKCostEvaluator.h:28
void setRegularizer(std::shared_ptr< IKRegularizerBase > reg)
Definition: IKCostEvaluator.h:71
const Eigen::Matrix< double, 3, 3 > Qpos
Definition: rbdJITtests.h:27
void setOptVector(std::shared_ptr< ct::optcon::tpl::OptVector< SCALAR >> optVector)
opt vector needs to be set by NLP solver
Definition: IKCostEvaluator.h:68
ct::rbd::RigidBodyPose getTargetPose()
Definition: IKCostEvaluator.h:73
IKCostEvaluator(const std::string &costFunctionPath, const std::string &termTaskspaceName, const bool verbose=false)
Definition: IKCostEvaluator.h:38
virtual void evalGradient(size_t grad_length, Eigen::Map< Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 >> &grad) override
retrieve first-order derivative
Definition: IKCostEvaluator.h:118