aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-pinocchio-functions.cpp
Go to the documentation of this file.
1
3#ifdef ALIGATOR_WITH_PINOCCHIO
4#include "aligator/fwd.hpp"
6
11#ifdef ALIGATOR_PINOCCHIO_V3
13#endif
14
15namespace aligator {
16namespace python {
17using context::ConstMatrixRef;
18using context::ConstVectorRef;
23
24//
25// FORWARD DECLARATIONS
26//
27
28void exposeFlyHigh();
29#ifdef ALIGATOR_PINOCCHIO_V3
30void exposeContactForce();
31#endif
32void exposeCenterOfMassFunctions();
33void exposeFrameFunctions();
34void exposeGravityCompensation();
35
36//
37// DEFINITIONS
38//
39
40void exposeFrameFunctions() {
42 using context::Scalar;
43 using SE3 = pinocchio::SE3Tpl<Scalar>;
44 using Motion = pinocchio::MotionTpl<Scalar>;
45
46 using FramePlacement = FramePlacementResidualTpl<Scalar>;
47 using FramePlacementData = FramePlacementDataTpl<Scalar>;
48
49 using FrameVelocity = FrameVelocityResidualTpl<Scalar>;
50 using FrameVelocityData = FrameVelocityDataTpl<Scalar>;
51
52 using FrameTranslation = FrameTranslationResidualTpl<Scalar>;
53 using FrameTranslationData = FrameTranslationDataTpl<Scalar>;
54
55 bp::register_ptr_to_python<shared_ptr<PinData>>();
56
57 PolymorphicMultiBaseVisitor<UnaryFunction, StageFunction> unary_visitor;
58
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>())
64 .def(unary_visitor)
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.");
69
70 bp::register_ptr_to_python<shared_ptr<FramePlacementData>>();
71
72 bp::class_<FramePlacementData, bp::bases<context::StageFunctionData>>(
73 "FramePlacementData", "Data struct for FramePlacementResidual.",
74 bp::no_init)
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.");
80
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>())
87 .def(unary_visitor)
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.");
92
93 bp::register_ptr_to_python<shared_ptr<FrameVelocityData>>();
94
95 bp::class_<FrameVelocityData, bp::bases<context::StageFunctionData>>(
96 "FrameVelocityData", "Data struct for FrameVelocityResidual.",
97 bp::no_init)
98 .def_readonly("pin_data", &FrameVelocityData::pin_data_,
99 "Pinocchio data struct.");
100
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>())
107 .def(unary_visitor)
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.");
113
114 bp::register_ptr_to_python<shared_ptr<FrameTranslationData>>();
115
116 bp::class_<FrameTranslationData, bp::bases<context::StageFunctionData>>(
117 "FrameTranslationData", "Data struct for FrameTranslationResidual.",
118 bp::no_init)
119 .def_readonly("fJf", &FrameTranslationData::fJf_)
120 .def_readonly("pin_data", &FrameTranslationData::pin_data_,
121 "Pinocchio data struct.");
122}
123
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();
131 int d = 0;
132 for (size_t k = 0; k < constraint_models.size(); ++k) {
133 d += (int)constraint_models[k].size();
134 }
135 context::VectorXs out(nu + d);
137 model, data, q, v, actMatrix, constraint_models, constraint_datas, out);
138
139 return bp::make_tuple((context::VectorXs)out.head(nu),
140 (context::VectorXs)out.tail(d));
141}
142#endif
143
144void exposePinocchioFunctions() {
145 exposeFrameFunctions();
146 exposeFlyHigh();
147#ifdef ALIGATOR_PINOCCHIO_V3
148 exposeContactForce();
149#endif
150 exposeCenterOfMassFunctions();
151 exposeGravityCompensation();
152
153#ifdef ALIGATOR_PINOCCHIO_V3
154 bp::def("underactuatedConstrainedInverseDynamics",
155 underactuatedConstraintInvDyn_proxy,
156 ("model"_a, "data", "q", "v", "actMatrix", "constraint_model",
157 "constraint_data"),
158 "Compute the gravity-compensating torque for a pinocchio Model under "
159 "a rigid constraint.");
160#endif
161}
162} // namespace python
163} // namespace aligator
164
165#endif
Forward declarations.
ManifoldAbstractTpl< Scalar > Manifold
Definition context.hpp:14
pinocchio::ModelTpl< Scalar, Options > PinModel
Definition context.hpp:9
StageFunctionTpl< Scalar > StageFunction
Definition context.hpp:16
UnaryFunctionTpl< Scalar > UnaryFunction
Definition context.hpp:17
pinocchio::DataTpl< Scalar, Options > PinData
Definition context.hpp:10
const PolymorphicMultiBaseVisitor< UnaryFunction, StageFunction > unary_visitor
Main package namespace.
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_)