aligator 0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
expose-pinocchio-manifolds.cpp
Go to the documentation of this file.
1#ifdef ALIGATOR_WITH_PINOCCHIO
2
3// Boost.Python 1.74 include manually mpl/vector/vector20.hpp
4// that prevent us to define mpl::list and mpl::vector with
5// the right size.
6// To avoid this issue this header should be included first.
7#include <pinocchio/fwd.hpp>
8
11
14
15namespace aligator::python {
17using context::Scalar;
18using PolyManifold = xyz::polymorphic<Manifold>;
19
22template <typename LieGroup>
23void exposeLieGroup(const char *name, const char *docstring) {
24 using wrapper_t = PinocchioLieGroup<LieGroup>;
25 bp::class_<wrapper_t, bp::bases<Manifold>>(name, docstring,
26 bp::init<>("self"_a))
27 .add_property("lg", &wrapper_t::lieGroup)
29 .enable_pickling_(true);
30}
31
33template <typename M>
34bp::class_<TangentBundleTpl<M>, bp::bases<Manifold>>
35exposeTangentBundle(const char *name, const char *docstring) {
36 using OutType = TangentBundleTpl<M>;
37 return bp::class_<OutType, bp::bases<Manifold>>(
38 name, docstring, bp::init<const M &>(("self"_a, "base")))
39 .add_property("base",
40 bp::make_function(&OutType::getBaseSpace,
41 bp::return_internal_reference<>()),
42 "Get the base space.")
44}
45
47template <typename M, class Init>
48bp::class_<TangentBundleTpl<M>, bp::bases<Manifold>>
49exposeTangentBundle(const char *name, const char *docstring, Init init) {
50 return exposeTangentBundle<M>(name, docstring).def(init);
51}
52
54 bp::scope scope = get_namespace("manifolds");
55
56 namespace pin = pinocchio;
57 using pin::ModelTpl;
58 using pin::SpecialEuclideanOperationTpl;
59 using pin::SpecialOrthogonalOperationTpl;
60 using pin::VectorSpaceOperationTpl;
61
62 using DynSizeEuclideanSpace = VectorSpaceOperationTpl<Eigen::Dynamic, Scalar>;
63 bp::class_<PinocchioLieGroup<DynSizeEuclideanSpace>, bp::bases<Manifold>>(
64 "EuclideanSpace", "Pinocchio's n-dimensional Euclidean vector space.",
65 bp::no_init)
66 .def(bp::init<int>(("self"_a, "dim")))
68
70 "R", "One-dimensional Euclidean space AKA real number line.");
72 "R2", "Two-dimensional Euclidean space.");
74 "R3", "Three-dimensional Euclidean space.");
76 "R4", "Four-dimensional Euclidean space.");
78 "SO2", "SO(2) special orthogonal group.");
80 "SO3", "SO(3) special orthogonal group.");
82 "SE2", "SE(2) special Euclidean group.");
84 "SE3", "SE(3) special Euclidean group.");
85
90
91 /* Expose tangent bundles */
92
93 exposeTangentBundle<SO2>("TSO2", "Tangent bundle of the SO(2) group.")
94 .def(bp::init<>(bp::args("self")));
95 exposeTangentBundle<SO3>("TSO3", "Tangent bundle of the SO(3) group.")
96 .def(bp::init<>(bp::args("self")));
97 exposeTangentBundle<SE2>("TSE2", "Tangent bundle of the SE(2) group.")
98 .def(bp::init<>(bp::args("self")));
99 exposeTangentBundle<SE3>("TSE3", "Tangent bundle of the SE(3) group.")
100 .def(bp::init<>(bp::args("self")));
101
102 /* Groups associated w/ Pinocchio models */
103 using Multibody = MultibodyConfiguration<Scalar>;
104 using Model = ModelTpl<Scalar>;
105 bp::class_<Multibody, bp::bases<Manifold>>(
106 "MultibodyConfiguration", "Configuration group of a multibody",
107 bp::init<const Model &>(bp::args("self", "model")))
108 .add_property("model",
109 bp::make_function(&Multibody::getModel,
110 bp::return_internal_reference<>()),
111 "Return the Pinocchio model instance.")
113 .enable_pickling_(true);
114
115 using MultiPhase = MultibodyPhaseSpace<Scalar>;
116 bp::class_<MultiPhase, bp::bases<Manifold>>(
117 "MultibodyPhaseSpace",
118 "Tangent space of the multibody configuration group.",
119 bp::init<const Model &>(("self"_a, "model")))
120 .add_property("model",
121 bp::make_function(&MultiPhase::getModel,
122 bp::return_internal_reference<>()),
123 "Return the Pinocchio model instance.")
124 .add_property("base", bp::make_function(
125 +[](const MultiPhase &m) -> const Multibody & {
126 return m.getBaseSpace();
127 },
128 bp::return_internal_reference<>()))
130 .enable_pickling_(true);
131}
132
133} // namespace aligator::python
134
135#endif // ifdef ALIGATOR_WITH_PINOCCHIO
ManifoldAbstractTpl< Scalar > Manifold
Definition context.hpp:14
MultibodyPhaseSpace< Scalar > MultibodyPhaseSpace
Definition fwd.hpp:29
The Python bindings.
Definition blk-matrix.hpp:7
xyz::polymorphic< Manifold > PolyManifold
void exposeLieGroup(const char *name, const char *docstring)
bp::class_< TangentBundleTpl< M >, bp::bases< Manifold > > exposeTangentBundle(const char *name, const char *docstring)
Expose the tangent bundle of a manifold type M.
bp::object get_namespace(const std::string &name)
Create or retrieve a Python scope (that is, a class or module namespace).
Definition utils.hpp:22
Multibody configuration group , defined using the Pinocchio library.
Definition multibody.hpp:17
Wrap a Pinocchio Lie group into a ManifoldAbstractTpl object.
Tangent bundle of a base manifold M.