10 #include "../InverseKinematicsBase.h" 15 #ifdef BUILD_WITH_IPOPT_SUPPORT // build IPOPT interface 24 template <
typename IKNLP,
typename VALIDATION_KIN>
25 class IKNLPSolverIpopt final
30 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
45 const size_t eeInd = 0)
48 kinematics_(VALIDATION_KIN()),
58 const size_t eeInd = 0)
67 iknlp_->setInitialGuess(q_init);
69 throw std::runtime_error(
"IKNLPSolverIpopt needs to be be initialized before setting an initial guess!");
74 const std::vector<size_t>& freeJoints = std::vector<size_t>())
override 79 JointPosition_t jointsLower = iknlp_->getIKConstraintContainer()->getJointLimitConstraints()->getLowerBound();
80 JointPosition_t jointsUpper = iknlp_->getIKConstraintContainer()->getJointLimitConstraints()->getUpperBound();
82 iknlp_->getIKCostEvaluator()->setTargetPose(ee_W_base);
86 bool solutionFound =
false;
88 while (count < this->
getSettings().maxNumTrials_ && !solutionFound)
91 if (this->
getSettings().randomizeInitialGuess_ && count != 0)
94 JointPosition_t randomJoints = noise_.gen<IKNLP::Kinematics_t::NJOINTS>();
98 jointsLower +
JointPosition_t((jointsUpper - jointsLower).array() * randomJoints.array());
109 RigidBodyPose forwardEval = kinematics_.getEEPoseInBase(eeInd_, sol);
112 if (forwardEval.isNear(ee_W_base, this->getSettings().validationTol_))
114 ikSolutions.push_back(sol);
115 solutionFound =
true;
121 return solutionFound;
127 const std::vector<size_t>& freeJoints)
override 133 std::shared_ptr<IKNLP> iknlp_;
135 VALIDATION_KIN kinematics_;
141 #else // BUILD_WITH_IPOPT_SUPPORT -- not building with IPOPT support, create dummy class 143 template <
typename IKNLP,
typename VALIDATION_KIN>
159 const size_t eeInd = 0)
161 throw(std::runtime_error(
"Error - IPOPT interface not compiled."));
168 const size_t eeInd = 0)
171 throw(std::runtime_error(
"Error - IPOPT interface not compiled."));
177 const std::vector<size_t>& freeJoints = std::vector<size_t>())
override 185 const std::vector<size_t>& freeJoints)
override 191 #endif // BUILD_WITH_IPOPT_SUPPORT
InverseKinematicsBase()=default
default constructor
KINEMATICS Kinematics_t
Definition: IKNLP.h:23
tpl::RigidBodyPose< double > RigidBodyPose
Definition: RigidBodyPose.h:426
typename InverseKinematicsBase::JointPositionsVector_t JointPositionsVector_t
Definition: IKNLPSolverIpopt.h:152
const InverseKinematicsSettings & getSettings() const
Definition: InverseKinematicsBase.h:122
IKNLPSolverIpopt(std::shared_ptr< IKNLP > iknlp, ct::optcon::NlpSolverSettings nlpSolverSettings, const size_t eeInd=0)
constructor
Definition: IKNLPSolverIpopt.h:157
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Definition: IKNLPSolverIpopt.h:144
Definition: InverseKinematicsBase.h:25
Definition: InverseKinematicsBase.h:15
typename InverseKinematicsBase::JointPosition_t JointPosition_t
Definition: IKNLPSolverIpopt.h:151
SCALAR Scalar_t
Definition: IKNLP.h:22
void setInitialGuess(const JointPosition_t &q_init)
Definition: IKNLPSolverIpopt.h:174
typename JointState< NJOINTS, SCALAR >::Position JointPosition_t
Definition: InverseKinematicsBase.h:30
typename IKNLP::Scalar_t SCALAR
Definition: IKNLPSolverIpopt.h:148
IKNLPSolverIpopt(std::shared_ptr< IKNLP > iknlp, ct::optcon::NlpSolverSettings nlpSolverSettings, const ct::rbd::InverseKinematicsSettings &ikSettings, const size_t eeInd=0)
constructor with additional inverse kinematics settings
Definition: IKNLPSolverIpopt.h:165
bool computeInverseKinematics(JointPositionsVector_t &ikSolutions, const RigidBodyPoseTpl &ee_W_base, const std::vector< size_t > &freeJoints=std::vector< size_t >()) override
Definition: IKNLPSolverIpopt.h:175
tpl::IpoptSolver< double > IpoptSolver
typename InverseKinematicsBase::RigidBodyPoseTpl RigidBodyPoseTpl
Definition: IKNLPSolverIpopt.h:153
bool computeInverseKinematics(JointPositionsVector_t &ikSolutions, const RigidBodyPoseTpl &eeWorldPose, const RigidBodyPoseTpl &baseWorldPose, const std::vector< size_t > &freeJoints) override
Definition: IKNLPSolverIpopt.h:182
tpl::RigidBodyPose< SCALAR > RigidBodyPoseTpl
Definition: InverseKinematicsBase.h:32
void updateSettings(const InverseKinematicsSettings &settings)
Definition: InverseKinematicsBase.h:123
IKNLPSolverIpopt()
Definition: IKNLPSolverIpopt.h:155
typename IKNLP::Kinematics_t KINEMATICS
Definition: IKNLPSolverIpopt.h:147
std::vector< JointPosition_t, Eigen::aligned_allocator< JointPosition_t > > JointPositionsVector_t
Definition: InverseKinematicsBase.h:31