aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-continuous-dynamics.cpp
Go to the documentation of this file.
1
9
10namespace aligator {
11namespace python {
12using namespace ::aligator::dynamics;
13using context::MatrixXs;
14using context::Scalar;
15using context::VectorXs;
16
21
22using CentroidalFwdDynamics = CentroidalFwdDynamicsTpl<Scalar>;
24 ContinuousCentroidalFwdDynamicsTpl<Scalar>;
25using Vector3s = typename math_types<Scalar>::Vector3s;
26using ContactMap = ContactMapTpl<Scalar>;
27
28struct ContinousDataWrapper : ContinuousDynamicsData,
29 bp::wrapper<ContinuousDynamicsData> {
30 using ContinuousDynamicsData::ContinuousDynamicsData;
31};
32
33void exposeODEs();
34
36 using ManifoldPtr = shared_ptr<context::Manifold>;
37
38 bp::register_ptr_to_python<shared_ptr<ContinuousDynamicsAbstract>>();
39 bp::class_<PyContinuousDynamics<>, boost::noncopyable>(
40 "ContinuousDynamicsAbstract",
41 "Base class for continuous-time dynamical models (DAEs and ODEs).",
42 bp::init<ManifoldPtr, int>("Default constructor: provide the working "
43 "manifold and control space "
44 "dimension.",
45 bp::args("self", "space", "nu")))
46 .add_property("ndx", &ContinuousDynamicsAbstract::ndx,
47 "State space dimension.")
48 .add_property("nu", &ContinuousDynamicsAbstract::nu,
49 "Control space dimension.")
50 .def("evaluate", bp::pure_virtual(&ContinuousDynamicsAbstract::evaluate),
51 bp::args("self", "x", "u", "xdot", "data"),
52 "Evaluate the DAE functions.")
53 .def("computeJacobians",
54 bp::pure_virtual(&ContinuousDynamicsAbstract::computeJacobians),
55 bp::args("self", "x", "u", "xdot", "data"),
56 "Evaluate the DAE function derivatives.")
57 .add_property("space",
58 bp::make_function(&ContinuousDynamicsAbstract::space,
59 bp::return_internal_reference<>()),
60 "Get the state space.")
61 .def(CreateDataPolymorphicPythonVisitor<ContinuousDynamicsAbstract,
62 PyContinuousDynamics<>>());
63
64 bp::register_ptr_to_python<shared_ptr<ContinuousDynamicsData>>();
65 auto cont_data_cls =
66 bp::class_<ContinousDataWrapper, boost::noncopyable>(
67 "ContinuousDynamicsData",
68 "Data struct for continuous dynamics/DAE models.",
69 bp::init<int, int>(bp::args("self", "ndx", "nu")))
70 .add_property("value",
71 bp::make_getter(&ContinuousDynamicsData::value_,
72 bp::return_internal_reference<>()),
73 "Vector value of the DAE residual.")
74 .add_property("Jx",
75 bp::make_getter(&ContinuousDynamicsData::Jx_,
76 bp::return_internal_reference<>()),
77 "Jacobian with respect to state.")
78 .add_property("Ju",
79 bp::make_getter(&ContinuousDynamicsData::Ju_,
80 bp::return_internal_reference<>()),
81 "Jacobian with respect to controls.")
82 .add_property("Jxdot",
83 bp::make_getter(&ContinuousDynamicsData::Jxdot_,
84 bp::return_internal_reference<>()),
85 "Jacobian with respect to :math:`\\dot{x}`.")
86 .add_property("xdot",
87 bp::make_getter(&ContinuousDynamicsData::xdot_,
88 bp::return_internal_reference<>()),
89 "Time derivative :math:`\\dot{x}`.");
90
91 // Alias this for back-compatibility
92 bp::scope().attr("ODEData") = cont_data_cls;
93
94 exposeODEs();
95
96 bp::class_<CentroidalFwdDynamics, bp::bases<ODEAbstract>>(
97 "CentroidalFwdDynamics",
98 "Nonlinear centroidal dynamics with preplanned feet positions",
99 bp::init<const shared_ptr<proxsuite::nlp::VectorSpaceTpl<Scalar>> &,
100 const double, const Vector3s &, const ContactMap &, const int>(
101 bp::args("self", "space", "total mass", "gravity", "contact_map",
102 "force_size")))
103 .def_readwrite("contact_map", &CentroidalFwdDynamics::contact_map_)
104 .def(CreateDataPythonVisitor<CentroidalFwdDynamics>());
105
106 bp::register_ptr_to_python<shared_ptr<CentroidalFwdDataTpl<Scalar>>>();
107 bp::class_<CentroidalFwdDataTpl<Scalar>, bp::bases<ODEData>>(
108 "CentroidalFwdData", bp::no_init);
109
110 bp::class_<ContinuousCentroidalFwdDynamics, bp::bases<ODEAbstract>>(
111 "ContinuousCentroidalFwdDynamics",
112 "Nonlinear centroidal dynamics with preplanned feet positions and smooth "
113 "forces",
114 bp::init<const shared_ptr<proxsuite::nlp::VectorSpaceTpl<Scalar>> &,
115 const double, const Vector3s &, const ContactMap &, const int>(
116 bp::args("self", "space", "total mass", "gravity", "contact_map",
117 "force_size")))
118 .def_readwrite("contact_map",
119 &ContinuousCentroidalFwdDynamics::contact_map_)
120 .def(CreateDataPythonVisitor<ContinuousCentroidalFwdDynamics>());
121
122 bp::register_ptr_to_python<
123 shared_ptr<ContinuousCentroidalFwdDataTpl<Scalar>>>();
124 bp::class_<ContinuousCentroidalFwdDataTpl<Scalar>, bp::bases<ODEData>>(
125 "ContinuousCentroidalFwdData", bp::no_init);
126}
127
128} // namespace python
129} // namespace aligator
dynamics::ContinuousDynamicsAbstractTpl< Scalar > ContinuousDynamicsAbstract
Definition context.hpp:9
dynamics::ODEDataTpl< Scalar > ODEData
Definition context.hpp:16
dynamics::ContinuousDynamicsDataTpl< Scalar > ContinuousDynamicsData
Definition context.hpp:12
dynamics::ODEAbstractTpl< Scalar > ODEAbstract
Definition context.hpp:14
Namespace for modelling system dynamics.
typename math_types< Scalar >::Vector3s Vector3s
CentroidalFwdDynamicsTpl< Scalar > CentroidalFwdDynamics
ContinuousCentroidalFwdDynamicsTpl< Scalar > ContinuousCentroidalFwdDynamics
shared_ptr< Manifold > ManifoldPtr
void exposeContinuousDynamics()
Expose continuous dynamics.
Main package namespace.