1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015-2020 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#include "pinocchio/bindings/python/algorithm/algorithms.hpp" |
6 |
|
|
#include "pinocchio/bindings/python/utils/deprecation.hpp" |
7 |
|
|
#include "pinocchio/algorithm/center-of-mass.hpp" |
8 |
|
|
|
9 |
|
|
#include <boost/python/overloads.hpp> |
10 |
|
|
|
11 |
|
|
namespace pinocchio |
12 |
|
|
{ |
13 |
|
|
namespace python |
14 |
|
|
{ |
15 |
|
|
|
16 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(jacobianCenterOfMassUpdate_overload,jacobianCenterOfMass,3,4) |
17 |
|
|
|
18 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(jacobianCenterOfMassNoUpdate_overload,jacobianCenterOfMass,2,3) |
19 |
|
|
|
20 |
|
|
static SE3::Vector3 |
21 |
|
2 |
com_0_proxy(const Model& model, |
22 |
|
|
Data & data, |
23 |
|
|
const Eigen::VectorXd & q, |
24 |
|
|
bool computeSubtreeComs = true) |
25 |
|
|
{ |
26 |
|
2 |
return centerOfMass(model,data,q,computeSubtreeComs); |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
static SE3::Vector3 |
30 |
|
|
com_1_proxy(const Model& model, |
31 |
|
|
Data & data, |
32 |
|
|
const Eigen::VectorXd & q, |
33 |
|
|
const Eigen::VectorXd & v, |
34 |
|
|
bool computeSubtreeComs = true) |
35 |
|
|
{ |
36 |
|
|
return centerOfMass(model,data,q,v,computeSubtreeComs); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
static SE3::Vector3 |
40 |
|
|
com_2_proxy(const Model & model, |
41 |
|
|
Data & data, |
42 |
|
|
const Eigen::VectorXd & q, |
43 |
|
|
const Eigen::VectorXd & v, |
44 |
|
|
const Eigen::VectorXd & a, |
45 |
|
|
bool computeSubtreeComs = true) |
46 |
|
|
{ |
47 |
|
|
return centerOfMass(model,data,q,v,a,computeSubtreeComs); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
static const Data::Vector3 & |
51 |
|
|
com_level_proxy(const Model & model, |
52 |
|
|
Data & data, |
53 |
|
|
KinematicLevel kinematic_level, |
54 |
|
|
bool computeSubtreeComs = true) |
55 |
|
|
{ |
56 |
|
|
return centerOfMass(model,data,kinematic_level,computeSubtreeComs); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
static void |
60 |
|
|
com_level_proxy_deprecated_signature(const Model & model, |
61 |
|
|
Data & data, |
62 |
|
|
int kinematic_level, |
63 |
|
|
bool computeSubtreeComs = true) |
64 |
|
|
{ |
65 |
|
|
centerOfMass(model,data,static_cast<KinematicLevel>(kinematic_level),computeSubtreeComs); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
static const Data::Vector3 & |
69 |
|
|
com_default_proxy(const Model & model, |
70 |
|
|
Data & data, |
71 |
|
|
bool computeSubtreeComs = true) |
72 |
|
|
{ |
73 |
|
|
return centerOfMass(model,data,computeSubtreeComs); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
static Data::Matrix3x |
77 |
|
|
jacobian_subtree_com_kinematics_proxy(const Model & model, |
78 |
|
|
Data & data, |
79 |
|
|
const Eigen::VectorXd & q, |
80 |
|
|
Model::JointIndex jointId) |
81 |
|
|
{ |
82 |
|
|
Data::Matrix3x J(3,model.nv); J.setZero(); |
83 |
|
|
jacobianSubtreeCenterOfMass(model, data, q, jointId, J); |
84 |
|
|
|
85 |
|
|
return J; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
static Data::Matrix3x |
89 |
|
|
jacobian_subtree_com_proxy(const Model & model, |
90 |
|
|
Data & data, |
91 |
|
|
Model::JointIndex jointId) |
92 |
|
|
{ |
93 |
|
|
Data::Matrix3x J(3,model.nv); J.setZero(); |
94 |
|
|
jacobianSubtreeCenterOfMass(model, data, jointId, J); |
95 |
|
|
|
96 |
|
|
return J; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
static Data::Matrix3x |
100 |
|
|
get_jacobian_subtree_com_proxy(const Model & model, |
101 |
|
|
Data & data, |
102 |
|
|
Model::JointIndex jointId) |
103 |
|
|
{ |
104 |
|
|
Data::Matrix3x J(3,model.nv); J.setZero(); |
105 |
|
|
getJacobianSubtreeCenterOfMass(model, data, jointId, J); |
106 |
|
|
|
107 |
|
|
return J; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
42 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_0_overload, com_0_proxy, 3, 4) |
111 |
|
|
|
112 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_1_overload, com_1_proxy, 4, 5) |
113 |
|
|
|
114 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_2_overload, com_2_proxy, 5, 6) |
115 |
|
|
|
116 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_level_overload, com_level_proxy, 3, 4) |
117 |
|
19 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_level_overload_deprecated_signature, com_level_proxy_deprecated_signature, 3, 4) |
118 |
|
|
|
119 |
|
38 |
BOOST_PYTHON_FUNCTION_OVERLOADS(com_default_overload, com_default_proxy, 2, 3) |
120 |
|
|
|
121 |
|
19 |
void exposeCOM() |
122 |
|
|
{ |
123 |
|
|
using namespace Eigen; |
124 |
|
|
|
125 |
✓✗ |
19 |
bp::def("computeTotalMass", |
126 |
|
|
(double (*)(const Model &))&computeTotalMass<double,0,JointCollectionDefaultTpl>, |
127 |
|
38 |
bp::args("model"), |
128 |
|
|
"Compute the total mass of the model and return it."); |
129 |
|
|
|
130 |
✓✗ |
19 |
bp::def("computeTotalMass", |
131 |
|
|
(double (*)(const Model &, Data &))&computeTotalMass<double,0,JointCollectionDefaultTpl>, |
132 |
|
38 |
bp::args("model","data"), |
133 |
|
|
"Compute the total mass of the model, put it in data.mass[0] and return it."); |
134 |
|
|
|
135 |
✓✗ |
19 |
bp::def("computeSubtreeMasses", |
136 |
|
|
(void (*)(const Model &, Data &))&computeSubtreeMasses<double,0,JointCollectionDefaultTpl>, |
137 |
|
38 |
bp::args("model","data"), |
138 |
|
|
"Compute the mass of each kinematic subtree and store it in the vector data.mass."); |
139 |
|
|
|
140 |
✓✗ |
19 |
bp::def("centerOfMass", |
141 |
|
|
com_0_proxy, |
142 |
✓✗✓✗
|
19 |
com_0_overload(bp::args("model","data", |
143 |
|
|
"q", |
144 |
|
|
"compute_subtree_coms"), |
145 |
|
|
"Compute the center of mass, putting the result in Data and return it." |
146 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees." |
147 |
✓✗ |
38 |
)[bp::return_value_policy<bp::return_by_value>()] |
148 |
|
|
); |
149 |
|
|
|
150 |
✓✗ |
19 |
bp::def("centerOfMass", |
151 |
|
|
com_1_proxy, |
152 |
✓✗ |
19 |
com_1_overload( |
153 |
✓✗ |
19 |
bp::args("model","data", |
154 |
|
|
"q","v", |
155 |
|
|
"compute_subtree_coms"), |
156 |
|
|
"Computes the center of mass position and velocity by storing the result in Data. It returns the center of mass position expressed in the WORLD frame.\n" |
157 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees." |
158 |
✓✗ |
38 |
)[bp::return_value_policy<bp::return_by_value>()] |
159 |
|
|
); |
160 |
|
|
|
161 |
✓✗ |
19 |
bp::def("centerOfMass", |
162 |
|
|
com_2_proxy, |
163 |
✓✗ |
19 |
com_2_overload( |
164 |
✓✗ |
19 |
bp::args("model","data", |
165 |
|
|
"q","v","a", |
166 |
|
|
"compute_subtree_coms"), |
167 |
|
|
"Computes the center of mass position, velocity and acceleration by storing the result in Data. It returns the center of mass position expressed in the WORLD frame.\n" |
168 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees." |
169 |
✓✗ |
38 |
)[bp::return_value_policy<bp::return_by_value>()] |
170 |
|
|
); |
171 |
|
|
|
172 |
✓✗✓✗
|
19 |
bp::def("centerOfMass", |
173 |
|
|
com_level_proxy_deprecated_signature, |
174 |
✓✗ |
19 |
com_level_overload_deprecated_signature( |
175 |
✓✗ |
38 |
bp::args("Model","Data", |
176 |
|
|
"kinematic_level", |
177 |
|
|
"computeSubtreeComs If true, the algorithm computes also the center of mass of the subtrees" |
178 |
|
|
), |
179 |
|
|
"Computes the center of mass position, velocity and acceleration of a given model according to the current kinematic values contained in data and the requested kinematic_level.\n" |
180 |
|
|
"If kinematic_level = 0, computes the CoM position, if kinematic_level = 1, also computes the CoM velocity and if kinematic_level = 2, it also computes the CoM acceleration." |
181 |
✓✗✓✗
|
38 |
)[deprecated_function<>()] |
182 |
|
|
); |
183 |
|
|
|
184 |
✓✗ |
19 |
bp::def("centerOfMass", |
185 |
|
|
com_level_proxy, |
186 |
✓✗✓✗
|
19 |
com_level_overload(bp::args("model","data", |
187 |
|
|
"kinematic_level", |
188 |
|
|
"compute_subtree_coms"), |
189 |
|
|
"Computes the center of mass position, velocity or acceleration of a given model according to the current kinematic values contained in data and the requested kinematic_level.\n" |
190 |
|
|
"If kinematic_level = POSITION, computes the CoM position, if kinematic_level = VELOCITY, also computes the CoM velocity and if kinematic_level = ACCELERATION, it also computes the CoM acceleration.\n" |
191 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees." |
192 |
✓✗ |
38 |
)[bp::return_value_policy<bp::return_by_value>()] |
193 |
|
|
); |
194 |
|
|
|
195 |
✓✗ |
19 |
bp::def("centerOfMass", |
196 |
|
|
com_default_proxy, |
197 |
✓✗ |
19 |
com_default_overload( |
198 |
✓✗ |
19 |
bp::args("model", |
199 |
|
|
"data", |
200 |
|
|
"compute_subtree_coms"), |
201 |
|
|
"Computes the center of mass position, velocity and acceleration of a given model according to the current kinematic values contained in data.\n" |
202 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees." |
203 |
✓✗ |
38 |
)[bp::return_value_policy<bp::return_by_value>()] |
204 |
|
|
); |
205 |
|
|
|
206 |
✓✗ |
19 |
bp::def("jacobianCenterOfMass", |
207 |
|
|
(const Data::Matrix3x & (*)(const Model &, Data &, const Eigen::MatrixBase<Eigen::VectorXd> &, bool))&jacobianCenterOfMass<double,0,JointCollectionDefaultTpl,VectorXd>, |
208 |
✓✗✓✗
|
19 |
jacobianCenterOfMassUpdate_overload(bp::args("model", |
209 |
|
|
"data", |
210 |
|
|
"q", |
211 |
|
|
"compute_subtree_coms"), |
212 |
|
|
"Computes the Jacobian of the center of mass, puts the result in Data and return it.\n" |
213 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees.")[ |
214 |
✓✗ |
38 |
bp::return_value_policy<bp::return_by_value>()]); |
215 |
|
|
|
216 |
✓✗ |
19 |
bp::def("jacobianCenterOfMass", |
217 |
|
|
(const Data::Matrix3x & (*)(const Model &, Data &, bool))&jacobianCenterOfMass<double,0,JointCollectionDefaultTpl>, |
218 |
✓✗✓✗
|
19 |
jacobianCenterOfMassNoUpdate_overload(bp::args("model", |
219 |
|
|
"data", |
220 |
|
|
"compute_subtree_coms"), |
221 |
|
|
"Computes the Jacobian of the center of mass, puts the result in Data and return it.\n" |
222 |
|
|
"If compute_subtree_coms is True, the algorithm also computes the center of mass of the subtrees.")[ |
223 |
✓✗ |
38 |
bp::return_value_policy<bp::return_by_value>()]); |
224 |
|
|
|
225 |
✓✗ |
19 |
bp::def("jacobianSubtreeCenterOfMass",jacobian_subtree_com_kinematics_proxy, |
226 |
|
38 |
bp::args("model", |
227 |
|
|
"data", |
228 |
|
|
"q", |
229 |
|
|
"subtree_root_joint_id"), |
230 |
|
|
"Computes the Jacobian of the CoM of the given subtree (subtree_root_joint_id) expressed in the WORLD frame, according to the given joint configuration."); |
231 |
✓✗ |
19 |
bp::def("jacobianSubtreeCoMJacobian",jacobian_subtree_com_kinematics_proxy, |
232 |
✓✗ |
38 |
bp::args("model", |
233 |
|
|
"data", |
234 |
|
|
"q", |
235 |
|
|
"subtree_root_joint_id"), |
236 |
|
|
"Computes the Jacobian of the CoM of the given subtree expressed in the world frame, according to the given joint configuration.", |
237 |
✓✗✓✗
|
38 |
deprecated_function<>("This function is now deprecated. It has been renamed jacobianSubtreeCenterOfMass.")); |
238 |
|
|
|
239 |
✓✗ |
19 |
bp::def("jacobianSubtreeCenterOfMass",jacobian_subtree_com_proxy, |
240 |
|
38 |
bp::args("model", |
241 |
|
|
"data", |
242 |
|
|
"subtree_root_joint_id"), |
243 |
|
|
"Computes the Jacobian of the CoM of the given subtree (subtree_root_joint_id) expressed in the WORLD frame, according to the given entries in data."); |
244 |
|
|
|
245 |
✓✗ |
19 |
bp::def("jacobianSubtreeCoMJacobian",jacobian_subtree_com_proxy, |
246 |
✓✗ |
38 |
bp::args("model", |
247 |
|
|
"data", |
248 |
|
|
"subtree_root_joint_id"), |
249 |
|
|
"Computes the Jacobian of the CoM of the given subtree expressed in the world frame, according to the given entries in data.", |
250 |
✓✗✓✗
|
38 |
deprecated_function<>("This function is now deprecated. It has been renamed jacobianSubtreeCenterOfMass.")); |
251 |
|
|
|
252 |
✓✗ |
19 |
bp::def("getJacobianSubtreeCenterOfMass",get_jacobian_subtree_com_proxy, |
253 |
|
38 |
bp::args("model", |
254 |
|
|
"data", |
255 |
|
|
"subtree_root_joint_id"), |
256 |
|
|
"Get the Jacobian of the CoM of the given subtree expressed in the world frame, according to the given entries in data. It assumes that jacobianCenterOfMass has been called first."); |
257 |
|
|
|
258 |
|
19 |
} |
259 |
|
|
|
260 |
|
|
} // namespace python |
261 |
|
|
} // namespace pinocchio |