Directory: | ./ |
---|---|
File: | python/centroidal_dynamics_python.cpp |
Date: | 2025-03-17 04:04:52 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 55 | 58 | 94.8% |
Branches: | 48 | 96 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <boost/python.hpp> | ||
2 | #include <eigenpy/eigenpy.hpp> | ||
3 | #include <eigenpy/memory.hpp> | ||
4 | |||
5 | #include "hpp/centroidal-dynamics/centroidal_dynamics.hh" | ||
6 | #include "hpp/centroidal-dynamics/util.hh" | ||
7 | |||
8 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(centroidal_dynamics::Equilibrium) | ||
9 | |||
10 | namespace centroidal_dynamics { | ||
11 | using namespace boost::python; | ||
12 | |||
13 | 1 | boost::python::tuple wrapComputeQuasiEquilibriumRobustness(Equilibrium& self, | |
14 | const Vector3& com) { | ||
15 | double robustness; | ||
16 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | LP_status status = self.computeEquilibriumRobustness(com, robustness); |
17 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return boost::python::make_tuple(status, robustness); |
18 | } | ||
19 | |||
20 | 1 | boost::python::tuple wrapComputeEquilibriumRobustness(Equilibrium& self, | |
21 | const Vector3& com, | ||
22 | const Vector3& acc) { | ||
23 | double robustness; | ||
24 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | LP_status status = self.computeEquilibriumRobustness(com, acc, robustness); |
25 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return boost::python::make_tuple(status, robustness); |
26 | } | ||
27 | |||
28 | 1 | boost::python::tuple wrapCheckRobustEquilibrium(Equilibrium& self, | |
29 | const Vector3& com) { | ||
30 | bool robustness; | ||
31 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | LP_status status = self.checkRobustEquilibrium(com, robustness); |
32 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return boost::python::make_tuple(status, robustness); |
33 | } | ||
34 | |||
35 | ✗ | bool wrapSetNewContacts(Equilibrium& self, | |
36 | const MatrixX3ColMajor& contactPoints, | ||
37 | const MatrixX3ColMajor& contactNormals, | ||
38 | const double frictionCoefficient, | ||
39 | const EquilibriumAlgorithm alg) { | ||
40 | ✗ | return self.setNewContacts(contactPoints, contactNormals, frictionCoefficient, | |
41 | ✗ | alg); | |
42 | } | ||
43 | |||
44 | 2 | bool wrapSetNewContactsFull(Equilibrium& self, | |
45 | const MatrixX3ColMajor& contactPoints, | ||
46 | const MatrixX3ColMajor& contactNormals, | ||
47 | const double frictionCoefficient, | ||
48 | const EquilibriumAlgorithm alg) { | ||
49 | 2 | return self.setNewContacts(contactPoints, contactNormals, frictionCoefficient, | |
50 | 2 | alg); | |
51 | } | ||
52 | |||
53 | 1 | boost::python::tuple wrapGetPolytopeInequalities(Equilibrium& self) { | |
54 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | MatrixXX H; |
55 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | VectorX h; |
56 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | H = MatrixXX::Zero(6, 6); |
57 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | h = VectorX::Zero(6, 1); |
58 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | self.getPolytopeInequalities(H, h); |
59 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | MatrixXXColMajor _H = H; |
60 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return boost::python::make_tuple(_H, h); |
61 | 1 | } | |
62 | |||
63 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
4 | BOOST_PYTHON_MODULE(hpp_centroidal_dynamics) { |
64 | /** BEGIN eigenpy init**/ | ||
65 | 2 | eigenpy::enableEigenPy(); | |
66 | |||
67 | // eigenpy::enableEigenPySpecific<MatrixX3ColMajor, MatrixX3ColMajor>(); | ||
68 | // eigenpy::enableEigenPySpecific<MatrixXXColMajor, MatrixXXColMajor>(); | ||
69 | // eigenpy::enableEigenPySpecific<Vector3, Vector3>(); | ||
70 | // eigenpy::enableEigenPySpecific<VectorX, VectorX>(); | ||
71 | /*eigenpy::exposeAngleAxis(); | ||
72 | eigenpy::exposeQuaternion();*/ | ||
73 | |||
74 | /** END eigenpy init**/ | ||
75 | |||
76 | /** BEGIN enum types **/ | ||
77 | #ifdef CLP_FOUND | ||
78 | enum_<SolverLP>("SolverLP") | ||
79 | .value("SOLVER_LP_QPOASES", SOLVER_LP_QPOASES) | ||
80 | .value("SOLVER_LP_CLP", SOLVER_LP_CLP) | ||
81 | .export_values(); | ||
82 | #else | ||
83 | 4 | enum_<SolverLP>("SolverLP") | |
84 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("SOLVER_LP_QPOASES", SOLVER_LP_QPOASES) |
85 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .export_values(); |
86 | #endif | ||
87 | |||
88 | 4 | enum_<EquilibriumAlgorithm>("EquilibriumAlgorithm") | |
89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_LP", EQUILIBRIUM_ALGORITHM_LP) |
90 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_LP2", EQUILIBRIUM_ALGORITHM_LP2) |
91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_DLP", EQUILIBRIUM_ALGORITHM_DLP) |
92 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_PP", EQUILIBRIUM_ALGORITHM_PP) |
93 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_IP", EQUILIBRIUM_ALGORITHM_IP) |
94 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("EQUILIBRIUM_ALGORITHM_DIP", EQUILIBRIUM_ALGORITHM_DIP) |
95 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .export_values(); |
96 | |||
97 | 4 | enum_<LP_status>("LP_status") | |
98 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_UNKNOWN", LP_STATUS_UNKNOWN) |
99 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_OPTIMAL", LP_STATUS_OPTIMAL) |
100 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_INFEASIBLE", LP_STATUS_INFEASIBLE) |
101 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_UNBOUNDED", LP_STATUS_UNBOUNDED) |
102 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_MAX_ITER_REACHED", LP_STATUS_MAX_ITER_REACHED) |
103 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .value("LP_STATUS_ERROR", LP_STATUS_ERROR) |
104 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .export_values(); |
105 | |||
106 | /** END enum types **/ | ||
107 | |||
108 | // bool (Equilibrium::*setNewContacts) | ||
109 | // (const MatrixX3ColMajor&, const MatrixX3ColMajor&, const double, | ||
110 | // const EquilibriumAlgorithm, const int graspIndex, const double | ||
111 | // maxGraspForce) = &Equilibrium::setNewContacts; | ||
112 | |||
113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | class_<Equilibrium>( |
114 | "Equilibrium", | ||
115 | 2 | init<std::string, double, unsigned int, | |
116 | optional<SolverLP, bool, const unsigned int, const bool> >()) | ||
117 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("useWarmStart", &Equilibrium::useWarmStart) |
118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("setUseWarmStart", &Equilibrium::setUseWarmStart) |
119 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("getName", &Equilibrium::getName) |
120 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("getAlgorithm", &Equilibrium::getAlgorithm) |
121 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("setNewContacts", wrapSetNewContacts) |
122 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("setNewContacts", wrapSetNewContactsFull) |
123 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("computeEquilibriumRobustness", |
124 | wrapComputeQuasiEquilibriumRobustness) | ||
125 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("computeEquilibriumRobustness", wrapComputeEquilibriumRobustness) |
126 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("checkRobustEquilibrium", wrapCheckRobustEquilibrium) |
127 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | .def("getPolytopeInequalities", wrapGetPolytopeInequalities); |
128 | 2 | } | |
129 | |||
130 | } // namespace centroidal_dynamics | ||
131 |