34 template <
class KINEMATICS,
bool FB,
size_t STATE_DIM,
size_t CONTROL_DIM>
35 class TermTaskspacePosition :
public optcon::TermBase<STATE_DIM, CONTROL_DIM, double, ct::core::ADCGScalar>
38 using SCALAR = ct::core::ADCGScalar;
40 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 TermTaskspacePosition() =
delete;
46 TermTaskspacePosition(
size_t eeInd,
47 const Eigen::Matrix<double, 3, 3>& Q,
48 const core::StateVector<3, double>& pos_des,
49 const std::string& name =
"TermTaskSpace")
50 :
optcon::TermBase<STATE_DIM, CONTROL_DIM, double,
ct::core::ADCGScalar>(name),
59 (STATE_DIM == 2 * (FB * 6 + KINEMATICS::NJOINTS)) || (STATE_DIM == 2 * (FB * 6 + KINEMATICS::NJOINTS) + 1),
60 "STATE_DIM does not have appropriate size.");
64 TermTaskspacePosition(std::string& configFile,
const std::string& termName,
bool verbose =
false)
66 loadConfigFile(configFile, termName,
verbose);
70 TermTaskspacePosition(
const TermTaskspacePosition& arg)
71 : eeInd_(arg.eeInd_), kinematics_(KINEMATICS()), QTaskSpace_(arg.QTaskSpace_), pos_ref_(arg.pos_ref_)
76 virtual ~TermTaskspacePosition() {}
78 TermTaskspacePosition<KINEMATICS, FB, STATE_DIM, CONTROL_DIM>* clone()
const override 80 return new TermTaskspacePosition(*
this);
82 virtual SCALAR evaluate(
const Eigen::Matrix<SCALAR, STATE_DIM, 1>& x,
83 const Eigen::Matrix<SCALAR, CONTROL_DIM, 1>& u,
86 return evalLocal<SCALAR>(x, u, t);
90 virtual ct::core::ADCGScalar evaluateCppadCg(
const core::StateVector<STATE_DIM, ct::core::ADCGScalar>& x,
91 const core::ControlVector<CONTROL_DIM, ct::core::ADCGScalar>& u,
92 ct::core::ADCGScalar t)
override 94 return evalLocal<ct::core::ADCGScalar>(x, u, t);
98 void loadConfigFile(
const std::string& filename,
const std::string& termName,
bool verbose =
false)
override 106 std::cout <<
"Read eeId as eeId = \n" << eeInd_ << std::endl;
107 std::cout <<
"Read Q as Q = \n" << QTaskSpace_ << std::endl;
108 std::cout <<
"Read x_des as x_des = \n" << pos_ref_.transpose() << std::endl;
115 template <
typename SC>
116 SC evalLocal(
const Eigen::Matrix<SC, STATE_DIM, 1>& x,
const Eigen::Matrix<SC, CONTROL_DIM, 1>& u,
const SC& t)
118 RBDState<KINEMATICS::NJOINTS, SC> rbdState = setStateFromVector<FB>(x);
120 Eigen::Matrix<SC, 3, 1> xDiff =
121 kinematics_.getEEPositionInWorld(eeInd_, rbdState.basePose(), rbdState.jointPositions())
122 .toImplementation() -
123 pos_ref_.template cast<SC>();
125 SC cost = (xDiff.transpose() * QTaskSpace_.template cast<SC>() * xDiff)(0, 0);
132 RBDState<KINEMATICS::NJOINTS, SCALAR> setStateFromVector(
const Eigen::Matrix<SCALAR, STATE_DIM, 1>& x,
133 typename std::enable_if<T, bool>::type =
true)
135 RBDState<KINEMATICS::NJOINTS, SCALAR> rbdState;
136 rbdState.fromStateVectorEulerXyz(x);
143 RBDState<KINEMATICS::NJOINTS, SCALAR> setStateFromVector(
const Eigen::Matrix<SCALAR, STATE_DIM, 1>& x,
144 typename std::enable_if<!T, bool>::type =
true)
146 RBDState<KINEMATICS::NJOINTS, SCALAR> rbdState;
147 rbdState.joints() = x;
155 KINEMATICS kinematics_;
158 Eigen::Matrix<double, 3, 3> QTaskSpace_;
161 Eigen::Matrix<double, 3, 1> pos_ref_;
CppAD::AD< CppAD::cg::CG< double > > SCALAR
bool verbose
Definition: rbdJITtests.h:15
void loadScalarCF(const std::string &filename, const std::string &scalarName, SCALAR &scalar, const std::string &termName="")
void loadMatrixCF(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &termName="")