6 #ifndef __pinocchio_python_spatial_inertia_hpp__
7 #define __pinocchio_python_spatial_inertia_hpp__
12 #include <boost/python/tuple.hpp>
20 #if EIGENPY_VERSION_AT_MOST(2, 8, 1)
30 template<
typename Inertia>
39 typedef typename Inertia::Matrix3
Matrix3;
40 typedef typename Inertia::Vector6
Vector6;
41 typedef typename Inertia::Matrix6
Matrix6;
43 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options>
VectorXs;
48 template<
class PyClass>
51 static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision();
58 bp::args(
"mass",
"lever",
"inertia")),
59 "Initialize from mass, lever and 3d inertia.")
61 .def(bp::init<>(bp::arg(
"self"),
"Default constructor."))
62 .def(bp::init<const Inertia &>((bp::arg(
"self"), bp::arg(
"clone")),
"Copy constructor"))
66 "Mass of the Spatial Inertia.")
71 bp::return_internal_reference<>()),
73 "Center of mass location of the Spatial Inertia. It corresponds to the location of the "
74 "center of mass regarding to the frame where the Spatial Inertia is expressed.")
77 "Rotational part of the Spatial Inertia, i.e. a symmetric matrix "
78 "representing the rotational inertia around the center of mass.")
80 .def(
"matrix", (
Matrix6(
Inertia::*)()
const) & Inertia::matrix, bp::arg(
"self"))
83 "se3Action", &Inertia::template se3Action<Scalar, Options>, bp::args(
"self",
"M"),
84 "Returns the result of the action of M on *this.")
86 "se3ActionInverse", &Inertia::template se3ActionInverse<Scalar, Options>,
87 bp::args(
"self",
"M"),
"Returns the result of the action of the inverse of M on *this.")
91 "Set *this to be the Identity inertia.")
94 "Set all the components of *this to zero.")
97 "Set all the components of *this to random values.")
99 .def(bp::self + bp::self)
100 .def(bp::self += bp::self)
101 .def(bp::self - bp::self)
102 .def(bp::self -= bp::self)
103 .def(bp::self * bp::other<Motion>())
105 .add_property(
"np", (
Matrix6(
Inertia::*)()
const) & Inertia::matrix)
107 "vxiv", &Inertia::template vxiv<Motion>, bp::args(
"self",
"v"),
108 "Returns the result of v x Iv.")
110 "vtiv", &Inertia::template vtiv<Motion>, bp::args(
"self",
"v"),
111 "Returns the result of v.T * Iv.")
115 & Inertia::template vxi<Motion>,
116 bp::args(
"self",
"v"),
"Returns the result of v x* I, a 6x6 matrix.")
120 & Inertia::template ivx<Motion>,
121 bp::args(
"self",
"v"),
"Returns the result of I vx, a 6x6 matrix.")
125 & Inertia::template variation<Motion>,
126 bp::args(
"self",
"v"),
"Returns the time derivative of the inertia.")
128 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
129 .def(bp::self == bp::self)
130 .def(bp::self != bp::self)
133 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
135 "isApprox", &Inertia::isApprox,
136 (bp::arg(
"self"), bp::arg(
"other"), bp::arg(
"prec") = dummy_precision),
137 "Returns true if *this is approximately equal to other, within the precision given "
141 "isZero", &
Inertia::isZero, (bp::arg(
"self"), bp::arg(
"prec") = dummy_precision),
142 "Returns true if *this is approximately equal to the zero Inertia, within the "
143 "precision given by prec.")
147 .staticmethod(
"Identity")
149 .staticmethod(
"Zero")
151 .staticmethod(
"Random")
156 "Returns the representation of the matrix as a vector of dynamic parameters."
157 "\nThe parameters are given as v = [m, mc_x, mc_y, mc_z, I_{xx}, I_{xy}, I_{yy}, "
158 "I_{xz}, I_{yz}, I_{zz}]^T "
159 "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter")
161 "FromDynamicParameters", &Inertia::template FromDynamicParameters<VectorXs>,
162 bp::args(
"dynamic_parameters"),
163 "Builds and inertia matrix from a vector of dynamic parameters."
164 "\nThe parameters are given as dynamic_parameters = [m, mc_x, mc_y, mc_z, I_{xx}, "
165 "I_{xy}, I_{yy}, I_{xz}, I_{yz}, I_{zz}]^T "
166 "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter.")
167 .staticmethod(
"FromDynamicParameters")
171 "Returns the Inertia of a sphere defined by a given mass and radius.")
172 .staticmethod(
"FromSphere")
175 bp::args(
"mass",
"length_x",
"length_y",
"length_z"),
176 "Returns the Inertia of an ellipsoid shape defined by a mass and given dimensions "
177 "the semi-axis of values length_{x,y,z}.")
178 .staticmethod(
"FromEllipsoid")
181 "Returns the Inertia of a cylinder defined by its mass, radius and length along the "
183 .staticmethod(
"FromCylinder")
185 "FromBox", &
Inertia::FromBox, bp::args(
"mass",
"length_x",
"length_y",
"length_z"),
186 "Returns the Inertia of a box shape with a mass and of dimension the semi axis of "
188 .staticmethod(
"FromBox")
191 "Computes the Inertia of a capsule defined by its mass, radius and length along the "
192 "Z axis. Assumes a uniform density.")
193 .staticmethod(
"FromCapsule")
195 .def(
"__array__", (
Matrix6(
Inertia::*)()
const) & Inertia::matrix)
197 #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
215 self.lever() = lever;
220 return self.inertia().matrix();
226 if (!check_expression_if_real<Scalar>(
227 isZero(symmetric_inertia - symmetric_inertia.transpose())))
229 self.inertia().data() << symmetric_inertia(0, 0), symmetric_inertia(1, 0),
230 symmetric_inertia(1, 1), symmetric_inertia(0, 2), symmetric_inertia(1, 2),
231 symmetric_inertia(2, 2);
236 return self.toDynamicParameters();
242 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
243 if (!inertia.isApprox(inertia.transpose()))
246 (Vector3::UnitX().transpose() * inertia * Vector3::UnitX() < 0)
247 || (Vector3::UnitY().transpose() * inertia * Vector3::UnitY() < 0)
248 || (Vector3::UnitZ().transpose() * inertia * Vector3::UnitZ() < 0))
256 #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0)
259 typedef ::boost::python::detail::not_specified HolderType;
261 bp::class_<Inertia, HolderType>(
263 "This class represenses a sparse version of a Spatial Inertia and its is defined by its "
264 "mass, its center of mass location and the rotational inertia expressed around this "
265 "center of mass.\n\n"
266 "Supported operations ...",
278 return self.matrix();
299 #endif // ifndef __pinocchio_python_spatial_inertia_hpp__