aligator 0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
expose-centroidal.cpp
Go to the documentation of this file.
1
15
16#include <eigenpy/eigenpy.hpp>
17#include <eigenpy/std-vector.hpp>
18
19namespace aligator {
20namespace python {
21
22using context::Scalar;
27
29 bp::class_<ContactMap>(
30 "ContactMap", "Store contact state and pose for centroidal problem",
31 bp::init<const std::vector<std::string> &, const std::vector<bool> &,
32 const ContactMap::PoseVec &>(
33 ("self"_a, "contact_names", "contact_states", "contact_poses")))
34 .def("addContact", &ContactMap::addContact,
35 ("self"_a, "name", "state", "pose"),
36 "Add a contact to the contact map.")
37 .def("removeContact", &ContactMap::removeContact, ("self"_a, "i"),
38 "Remove contact i from the contact map.")
39 .def("setContactPose", &ContactMap::setContactPose,
40 ("self"_a, "name", "ref"))
41 .def("getContactPose", &ContactMap::getContactPose, ("self"_a, "name"),
42 bp::return_internal_reference<>())
43 .def_readonly("size", &ContactMap::size_)
44 .def_readwrite("contact_states", &ContactMap::contact_states_)
45 .def_readwrite("contact_poses", &ContactMap::contact_poses_)
46 .def_readwrite("contact_names", &ContactMap::contact_names_);
47}
48
50 using CentroidalCoMResidual = CentroidalCoMResidualTpl<Scalar>;
51 using CentroidalCoMData = CentroidalCoMDataTpl<Scalar>;
52
53 using LinearMomentumResidual = LinearMomentumResidualTpl<Scalar>;
54 using LinearMomentumData = LinearMomentumDataTpl<Scalar>;
55
56 using AngularMomentumResidual = AngularMomentumResidualTpl<Scalar>;
57 using AngularMomentumData = AngularMomentumDataTpl<Scalar>;
58
59 using CentroidalAccelerationResidual =
61 using CentroidalAccelerationData = CentroidalAccelerationDataTpl<Scalar>;
62
63 using CentroidalFrictionConeResidual =
65 using CentroidalFrictionConeData = CentroidalFrictionConeDataTpl<Scalar>;
66
67 using CentroidalWrenchConeResidual = CentroidalWrenchConeResidualTpl<Scalar>;
68 using CentroidalWrenchConeData = CentroidalWrenchConeDataTpl<Scalar>;
69
70 using AngularAccelerationResidual = AngularAccelerationResidualTpl<Scalar>;
71 using AngularAccelerationData = AngularAccelerationDataTpl<Scalar>;
72
73 using CentroidalWrapperResidual = CentroidalWrapperResidualTpl<Scalar>;
74 using CentroidalWrapperData = CentroidalWrapperDataTpl<Scalar>;
75
78
79 bp::class_<CentroidalCoMResidual, bp::bases<UnaryFunction>>(
80 "CentroidalCoMResidual", "A residual function :math:`r(x) = com(x)` ",
81 bp::init<const int, const int, const context::Vector3s &>(
82 ("self"_a, "ndx", "nu", "p_ref")))
83 .def("getReference", &CentroidalCoMResidual::getReference, ("self"_a),
84 bp::return_internal_reference<>(),
85 "Get the target Centroidal CoM translation.")
86 .def("setReference", &CentroidalCoMResidual::setReference,
87 ("self"_a, "p_new"), "Set the target Centroidal CoM translation.")
88 .def(unary_visitor);
89
90 bp::register_ptr_to_python<shared_ptr<CentroidalCoMData>>();
91
92 bp::class_<CentroidalCoMData, bp::bases<StageFunctionData>>(
93 "CentroidalCoMData", "Data Structure for CentroidalCoM", bp::no_init);
94
95 bp::class_<LinearMomentumResidual, bp::bases<UnaryFunction>>(
96 "LinearMomentumResidual", "A residual function :math:`r(x) = h(x)` ",
97 bp::init<const int, const int, const context::Vector3s &>(
98 ("self"_a, "ndx", "nu", "h_ref")))
99 .def("getReference", &LinearMomentumResidual::getReference, ("self"_a),
100 bp::return_internal_reference<>(), "Get the target Linear Momentum.")
101 .def("setReference", &LinearMomentumResidual::setReference,
102 ("self"_a, "h_new"), "Set the target Linear Momentum.")
103 .def(unary_visitor);
104
105 bp::register_ptr_to_python<shared_ptr<LinearMomentumData>>();
106
107 bp::class_<LinearMomentumData, bp::bases<StageFunctionData>>(
108 "LinearMomentumData", "Data Structure for LinearMomentum", bp::no_init);
109
110 bp::class_<AngularMomentumResidual, bp::bases<UnaryFunction>>(
111 "AngularMomentumResidual", "A residual function :math:`r(x) = L(x)` ",
112 bp::init<const int, const int, const context::Vector3s &>(
113 ("self"_a, "ndx", "nu", "L_ref")))
114 .def("getReference", &AngularMomentumResidual::getReference, "self"_a,
115 bp::return_internal_reference<>(),
116 "Get the target Angular Momentum.")
117 .def("setReference", &AngularMomentumResidual::setReference,
118 ("self"_a, "L_new"), "Set the target Angular Momentum.")
119 .def(unary_visitor);
120
121 bp::register_ptr_to_python<shared_ptr<AngularMomentumData>>();
122
123 bp::class_<AngularMomentumData, bp::bases<StageFunctionData>>(
124 "AngularMomentumData", "Data Structure for AngularMomentum", bp::no_init);
125
126 bp::class_<CentroidalAccelerationResidual, bp::bases<StageFunction>>(
127 "CentroidalAccelerationResidual",
128 "A residual function :math:`r(x) = cddot(x)` ",
129 bp::init<const int, const int, const double, const context::Vector3s &,
130 const ContactMap &, const int>(("self"_a, "ndx", "nu", "mass",
131 "gravity", "contact_map",
132 "force_size")))
133 .def_readwrite("contact_map",
134 &CentroidalAccelerationResidual::contact_map_)
136 .def(func_visitor);
137
138 bp::register_ptr_to_python<shared_ptr<CentroidalAccelerationData>>();
139
140 bp::class_<CentroidalAccelerationData, bp::bases<StageFunctionData>>(
141 "CentroidalAccelerationData", "Data Structure for CentroidalAcceleration",
142 bp::no_init);
143
144 bp::class_<CentroidalFrictionConeResidual, bp::bases<StageFunction>>(
145 "CentroidalFrictionConeResidual",
146 "A residual function :math:`r(x) = [fz, mu2 * fz2 - (fx2 + fy2)]` ",
147 bp::init<const int, const int, const int, const double, const double>(
148 ("self"_a, "ndx", "nu", "k", "mu", "epsilon")))
149 .def(func_visitor);
150
151 bp::register_ptr_to_python<shared_ptr<CentroidalFrictionConeData>>();
152
153 bp::class_<CentroidalFrictionConeData, bp::bases<StageFunctionData>>(
154 "CentroidalFrictionConeData", "Data Structure for CentroidalFrictionCone",
155 bp::no_init);
156
157 bp::class_<CentroidalWrenchConeResidual, bp::bases<StageFunction>>(
158 "CentroidalWrenchConeResidual",
159 "A residual function :math:`r(x) = [fz, mu2 * fz2 - (fx2 + fy2)]` for "
160 "centroidal case ",
161 bp::init<const int, const int, const int, const double, const double,
162 const double>(("self"_a, "ndx", "nu", "k", "mu", "L", "W")))
163 .def(func_visitor);
164
165 bp::register_ptr_to_python<shared_ptr<CentroidalWrenchConeData>>();
166
167 bp::class_<CentroidalWrenchConeData, bp::bases<StageFunctionData>>(
168 "CentroidalWrenchConeData", "Data Structure for CentroidalWrenchCone",
169 bp::no_init);
170
171 bp::class_<AngularAccelerationResidual, bp::bases<StageFunction>>(
172 "AngularAccelerationResidual",
173 "A residual function :math:`r(x) = Ldot(x)` ",
174 bp::init<const int, const int, const double, const context::Vector3s &,
175 const ContactMap &, const int>(("self"_a, "ndx", "nu", "mass",
176 "gravity", "contact_map",
177 "force_size")))
178 .def_readwrite("contact_map", &AngularAccelerationResidual::contact_map_)
180 .def(func_visitor);
181
182 bp::register_ptr_to_python<shared_ptr<AngularAccelerationData>>();
183
184 bp::class_<AngularAccelerationData, bp::bases<StageFunctionData>>(
185 "AngularAccelerationData", "Data Structure for AngularAcceleration",
186 bp::no_init);
187
188 bp::class_<CentroidalWrapperResidual, bp::bases<UnaryFunction>>(
189 "CentroidalWrapperResidual",
190 "A wrapper for centroidal cost with smooth control",
191 bp::init<xyz::polymorphic<StageFunction>>(("self"_a, "centroidal_cost")))
192 .def_readwrite("centroidal_cost",
193 &CentroidalWrapperResidual::centroidal_cost_)
195 .def(unary_visitor);
196
197 bp::register_ptr_to_python<shared_ptr<CentroidalWrapperData>>();
198
199 bp::class_<CentroidalWrapperData, bp::bases<StageFunctionData>>(
200 "CentroidalWrapperData", "Data Structure for CentroidalWrapper",
201 bp::no_init);
202}
203
204} // namespace python
205} // namespace aligator
StageFunctionTpl< Scalar > StageFunction
Definition context.hpp:17
UnaryFunctionTpl< Scalar > UnaryFunction
Definition context.hpp:18
StageFunctionDataTpl< Scalar > StageFunctionData
Definition context.hpp:19
The Python bindings.
Definition blk-matrix.hpp:7
void exposeContactMap()
Centroidal cost functions.
const PolymorphicMultiBaseVisitor< UnaryFunction, StageFunction > unary_visitor
ContactMapTpl< Scalar > ContactMap
PolymorphicMultiBaseVisitor< StageFunction > func_visitor
Main package namespace.
This residual returns the angular acceleration of a centroidal model with state , computed from the e...
This residual returns the angular momentum for a centroidal model with state .
This residual returns the linear acceleration of a centroidal model with state , computed from the ex...
This residual implements the "ice cream" friction cone for a centroidal model with state .
This residual acts as a wrapper for centroidal model cost functions in which the external forces are ...
This residual implements the wrench cone for a centroidal model with control with 6D spatial force.
Contact map for centroidal costs and dynamics.
std::vector< bool > contact_states_
void addContact(std::string_view name, const bool state, const Vector3s &pose)
void setContactPose(std::string_view name, const Vector3s &ref)
std::vector< std::string > contact_names_
void removeContact(const size_t i)
const Vector3s & getContactPose(std::string_view name) const
std::vector< Vector3s > PoseVec
This residual returns the linear momentum for a centroidal model with state .