3#ifdef ALIGATOR_WITH_PINOCCHIO
11#ifdef ALIGATOR_PINOCCHIO_V3
17using context::ConstMatrixRef;
18using context::ConstVectorRef;
29#ifdef ALIGATOR_PINOCCHIO_V3
30void exposeContactForce();
32void exposeCenterOfMassFunctions();
33void exposeFrameFunctions();
40void exposeFrameFunctions() {
43 using SE3 = pinocchio::SE3Tpl<Scalar>;
44 using Motion = pinocchio::MotionTpl<Scalar>;
46 using FramePlacement = FramePlacementResidualTpl<Scalar>;
47 using FramePlacementData = FramePlacementDataTpl<Scalar>;
49 using FrameVelocity = FrameVelocityResidualTpl<Scalar>;
50 using FrameVelocityData = FrameVelocityDataTpl<Scalar>;
52 using FrameTranslation = FrameTranslationResidualTpl<Scalar>;
53 using FrameTranslationData = FrameTranslationDataTpl<Scalar>;
55 bp::register_ptr_to_python<shared_ptr<PinData>>();
57 PolymorphicMultiBaseVisitor<UnaryFunction, StageFunction>
unary_visitor;
59 bp::class_<FramePlacement, bp::bases<UnaryFunction>>(
60 "FramePlacementResidual",
"Frame placement residual function.",
61 bp::init<int, int, const PinModel &, const SE3 &, pinocchio::FrameIndex>(
62 (
"self"_a,
"ndx",
"nu",
"model",
"p_ref",
"id")))
63 .def(FrameAPIVisitor<FramePlacement>())
65 .def(
"getReference", &FramePlacement::getReference,
"self"_a,
66 bp::return_internal_reference<>(),
"Get the target frame in SE3.")
67 .def(
"setReference", &FramePlacement::setReference, (
"self"_a,
"p_new"),
68 "Set the target frame in SE3.");
70 bp::register_ptr_to_python<shared_ptr<FramePlacementData>>();
72 bp::class_<FramePlacementData, bp::bases<context::StageFunctionData>>(
73 "FramePlacementData",
"Data struct for FramePlacementResidual.",
75 .def_readonly(
"rMf", &FramePlacementData::rMf_,
"Frame placement error.")
76 .def_readonly(
"rJf", &FramePlacementData::rJf_)
77 .def_readonly(
"fJf", &FramePlacementData::fJf_)
78 .def_readonly(
"pin_data", &FramePlacementData::pin_data_,
79 "Pinocchio data struct.");
81 bp::class_<FrameVelocity, bp::bases<UnaryFunction>>(
82 "FrameVelocityResidual",
"Frame velocity residual function.",
83 bp::init<int, int,
const PinModel &,
const Motion &,
84 pinocchio::FrameIndex, pinocchio::ReferenceFrame>(
85 (
"self"_a,
"ndx",
"nu",
"model",
"v_ref",
"id",
"reference_frame")))
86 .def(FrameAPIVisitor<FrameVelocity>())
88 .def(
"getReference", &FrameVelocity::getReference,
"self"_a,
89 bp::return_internal_reference<>(),
"Get the target frame velocity.")
90 .def(
"setReference", &FrameVelocity::setReference, (
"self"_a,
"v_new"),
91 "Set the target frame velocity.");
93 bp::register_ptr_to_python<shared_ptr<FrameVelocityData>>();
95 bp::class_<FrameVelocityData, bp::bases<context::StageFunctionData>>(
96 "FrameVelocityData",
"Data struct for FrameVelocityResidual.",
98 .def_readonly(
"pin_data", &FrameVelocityData::pin_data_,
99 "Pinocchio data struct.");
101 bp::class_<FrameTranslation, bp::bases<UnaryFunction>>(
102 "FrameTranslationResidual",
"Frame placement residual function.",
103 bp::init<int, int,
const PinModel &,
const context::Vector3s &,
104 pinocchio::FrameIndex>(
105 (
"self"_a,
"ndx",
"nu",
"model",
"p_ref",
"id")))
106 .def(FrameAPIVisitor<FrameTranslation>())
108 .def(
"getReference", &FrameTranslation::getReference,
"self"_a,
109 bp::return_internal_reference<>(),
110 "Get the target frame translation.")
111 .def(
"setReference", &FrameTranslation::setReference, (
"self"_a,
"p_new"),
112 "Set the target frame translation.");
114 bp::register_ptr_to_python<shared_ptr<FrameTranslationData>>();
116 bp::class_<FrameTranslationData, bp::bases<context::StageFunctionData>>(
117 "FrameTranslationData",
"Data struct for FrameTranslationResidual.",
119 .def_readonly(
"fJf", &FrameTranslationData::fJf_)
120 .def_readonly(
"pin_data", &FrameTranslationData::pin_data_,
121 "Pinocchio data struct.");
124#ifdef ALIGATOR_PINOCCHIO_V3
125auto underactuatedConstraintInvDyn_proxy(
126 const PinModel &model, PinData &data,
const ConstVectorRef &q,
127 const ConstVectorRef &v,
const ConstMatrixRef &actMatrix,
128 const StdVectorEigenAligned<context::RCM> &constraint_models,
129 StdVectorEigenAligned<context::RCD> &constraint_datas) {
130 long nu = actMatrix.cols();
132 for (
size_t k = 0; k < constraint_models.size(); ++k) {
133 d += (int)constraint_models[k].size();
135 context::VectorXs out(nu + d);
137 model, data, q, v, actMatrix, constraint_models, constraint_datas, out);
139 return bp::make_tuple((context::VectorXs)out.head(nu),
140 (context::VectorXs)out.tail(d));
144void exposePinocchioFunctions() {
145 exposeFrameFunctions();
147#ifdef ALIGATOR_PINOCCHIO_V3
148 exposeContactForce();
150 exposeCenterOfMassFunctions();
153#ifdef ALIGATOR_PINOCCHIO_V3
154 bp::def(
"underactuatedConstrainedInverseDynamics",
155 underactuatedConstraintInvDyn_proxy,
156 (
"model"_a,
"data",
"q",
"v",
"actMatrix",
"constraint_model",
158 "Compute the gravity-compensating torque for a pinocchio Model under "
159 "a rigid constraint.");
ManifoldAbstractTpl< Scalar > Manifold
pinocchio::ModelTpl< Scalar, Options > PinModel
StageFunctionTpl< Scalar > StageFunction
UnaryFunctionTpl< Scalar > UnaryFunction
pinocchio::DataTpl< Scalar, Options > PinData
void exposeGravityCompensation()
const PolymorphicMultiBaseVisitor< UnaryFunction, StageFunction > unary_visitor
void underactuatedConstrainedInverseDynamics(const ModelTpl< Scalar, Options > &model, DataTpl< Scalar, Options > &data, const Eigen::MatrixBase< ConfigType > &q, Eigen::MatrixBase< VelType > const &v, const Eigen::MatrixBase< MatrixType > &actMatrix, const StdVectorEigenAligned< RigidConstraintModelTpl< Scalar, Options > > &constraint_models, StdVectorEigenAligned< RigidConstraintDataTpl< Scalar, Options > > &constraint_datas, const Eigen::MatrixBase< OutType > &res_)