29 static constexpr int Options = Inertia::Options;
30 typedef typename Inertia::Scalar Scalar;
31 typedef typename Inertia::Vector3 Vector3;
32 typedef typename Inertia::Matrix3 Matrix3;
33 typedef typename Inertia::Vector6 Vector6;
34 typedef typename Inertia::Matrix6 Matrix6;
36 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs;
37 typedef MotionTpl<Scalar, Options> Motion;
38 typedef ForceTpl<Scalar, Options> Force;
41 template<
class PyClass>
42 void visit(PyClass & cl)
const 44 static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision();
48 &InertiaPythonVisitor::makeFromMCI, bp::default_call_policies(),
49 bp::args(
"mass",
"lever",
"inertia")),
50 "Initialize from mass, lever and 3d inertia.")
52 .def(bp::init<>(bp::arg(
"self"),
"Default constructor."))
53 .def(bp::init<const Inertia &>((bp::arg(
"self"), bp::arg(
"clone")),
"Copy constructor"))
56 "mass", &InertiaPythonVisitor::getMass, &InertiaPythonVisitor::setMass,
57 "Mass of the Spatial Inertia.")
61 (
typename Inertia::Vector3 & (Inertia::*)()) & Inertia::lever,
62 bp::return_internal_reference<>()),
63 &InertiaPythonVisitor::setLever,
64 "Center of mass location of the Spatial Inertia. It corresponds to the location of the " 65 "center of mass regarding to the frame where the Spatial Inertia is expressed.")
67 "inertia", &InertiaPythonVisitor::getInertia, &InertiaPythonVisitor::setInertia,
68 "Rotational part of the Spatial Inertia, i.e. a symmetric matrix representing the " 69 "rotational inertia around the center of mass.")
71 .def(
"matrix", (Matrix6 (Inertia::*)()
const) & Inertia::matrix, bp::arg(
"self"))
72 .def(
"inverse", (Matrix6 (Inertia::*)()
const) & Inertia::inverse, bp::arg(
"self"))
74 "se3Action", &Inertia::template se3Action<Scalar, Options>, bp::args(
"self",
"M"),
75 "Returns the result of the action of M on *this.")
77 "se3ActionInverse", &Inertia::template se3ActionInverse<Scalar, Options>,
78 bp::args(
"self",
"M"),
"Returns the result of the action of the inverse of M on *this.")
81 "setIdentity", &Inertia::setIdentity, bp::arg(
"self"),
82 "Set *this to be the Identity inertia.")
84 "setZero", &Inertia::setZero, bp::arg(
"self"),
85 "Set all the components of *this to zero.")
87 "setRandom", &Inertia::setRandom, bp::arg(
"self"),
88 "Set all the components of *this to random values.")
90 .def(bp::self + bp::self)
91 .def(bp::self += bp::self)
92 .def(bp::self - bp::self)
93 .def(bp::self -= bp::self)
94 .def(bp::self * bp::other<Motion>())
96 .add_property(
"np", (Matrix6 (Inertia::*)()
const) & Inertia::matrix)
98 "vxiv", &Inertia::template vxiv<Motion>, bp::args(
"self",
"v"),
99 "Returns the result of v x Iv.")
101 "vtiv", &Inertia::template vtiv<Motion>, bp::args(
"self",
"v"),
102 "Returns the result of v.T * Iv.")
105 (Matrix6 (Inertia::*)(
const MotionDense<Motion> &)
const)
106 & Inertia::template vxi<Motion>,
107 bp::args(
"self",
"v"),
"Returns the result of v x* I, a 6x6 matrix.")
110 (Matrix6 (Inertia::*)(
const MotionDense<Motion> &)
const)
111 & Inertia::template ivx<Motion>,
112 bp::args(
"self",
"v"),
"Returns the result of I vx, a 6x6 matrix.")
115 (Matrix6 (Inertia::*)(
const MotionDense<Motion> &)
const)
116 & Inertia::template variation<Motion>,
117 bp::args(
"self",
"v"),
"Returns the time derivative of the inertia.")
119#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS 120 .def(bp::self == bp::self)
121 .def(bp::self != bp::self)
124#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS 126 "isApprox", &Inertia::isApprox,
127 (bp::arg(
"self"), bp::arg(
"other"), bp::arg(
"prec") = dummy_precision),
128 "Returns true if *this is approximately equal to other, within the precision given by " 132 "isZero", &Inertia::isZero, (bp::arg(
"self"), bp::arg(
"prec") = dummy_precision),
133 "Returns true if *this is approximately equal to the zero Inertia, within the " 134 "precision given by prec.")
137 .def(
"Identity", &Inertia::Identity,
"Returns the identity Inertia.")
138 .staticmethod(
"Identity")
139 .def(
"Zero", &Inertia::Zero,
"Returns the zero Inertia.")
140 .staticmethod(
"Zero")
141 .def(
"Random", &Inertia::Random,
"Returns a random Inertia.")
142 .staticmethod(
"Random")
145 "toDynamicParameters", &InertiaPythonVisitor::toDynamicParameters_proxy,
147 "Returns the representation of the matrix as a vector of dynamic parameters." 148 "\nThe parameters are given as v = [m, mc_x, mc_y, mc_z, I_{xx}, I_{xy}, I_{yy}, " 149 "I_{xz}, I_{yz}, I_{zz}]^T " 150 "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter")
152 "FromDynamicParameters", &InertiaPythonVisitor::fromDynamicParameters_proxy,
153 bp::args(
"dynamic_parameters"),
154 "Builds and inertia matrix from a vector of dynamic parameters." 155 "\nThe parameters are given as dynamic_parameters = [m, mc_x, mc_y, mc_z, I_{xx}, " 156 "I_{xy}, I_{yy}, I_{xz}, I_{yz}, I_{zz}]^T " 157 "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter.")
158 .staticmethod(
"FromDynamicParameters")
161 "FromSphere", &Inertia::FromSphere, bp::args(
"mass",
"radius"),
162 "Returns the Inertia of a sphere defined by a given mass and radius.")
163 .staticmethod(
"FromSphere")
165 "FromEllipsoid", &Inertia::FromEllipsoid,
166 bp::args(
"mass",
"length_x",
"length_y",
"length_z"),
167 "Returns the Inertia of an ellipsoid shape defined by a mass and given dimensions the " 168 "semi-axis of values length_{x,y,z}.")
169 .staticmethod(
"FromEllipsoid")
171 "FromCylinder", &Inertia::FromCylinder, bp::args(
"mass",
"radius",
"length"),
172 "Returns the Inertia of a cylinder defined by its mass, radius and length along the Z " 174 .staticmethod(
"FromCylinder")
176 "FromBox", &Inertia::FromBox, bp::args(
"mass",
"length_x",
"length_y",
"length_z"),
177 "Returns the Inertia of a box shape with a mass and of dimension the semi axis of " 179 .staticmethod(
"FromBox")
181 "FromCapsule", &Inertia::FromCapsule, bp::args(
"mass",
"radius",
"height"),
182 "Computes the Inertia of a capsule defined by its mass, radius and length along the Z " 183 "axis. Assumes a uniform density.")
184 .staticmethod(
"FromCapsule")
187 "FromPseudoInertia", &Inertia::FromPseudoInertia, bp::args(
"pseudo_inertia"),
188 "Returns the Inertia created from a pseudo inertia object.")
189 .staticmethod(
"FromPseudoInertia")
192 "toPseudoInertia", &Inertia::toPseudoInertia, bp::arg(
"self"),
193 "Returns the pseudo inertia representation of the inertia.")
196 "FromLogCholeskyParameters", &Inertia::FromLogCholeskyParameters,
197 bp::args(
"log_cholesky_parameters"),
198 "Returns the Inertia created from log Cholesky parameters.")
199 .staticmethod(
"FromLogCholeskyParameters")
201 .def(
"__array__", (Matrix6 (Inertia::*)()
const) & Inertia::matrix)
203 "__array__", &__array__,
204 (bp::arg(
"self"), bp::arg(
"dtype") = bp::object(), bp::arg(
"copy") = bp::object()))
205#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION 206 .def_pickle(Pickle())
211 static Scalar getMass(
const Inertia & self)
215 static void setMass(Inertia & self, Scalar mass)
220 static void setLever(Inertia & self,
const Vector3 & lever)
222 self.lever() = lever;
225 static Matrix3 getInertia(
const Inertia & self)
227 return self.inertia().matrix();
231 static void setInertia(Inertia & self,
const Matrix3 & symmetric_inertia)
233 if (!check_expression_if_real<Scalar>(
234 isZero(symmetric_inertia - symmetric_inertia.transpose())))
235 throw eigenpy::Exception(
"The 3d inertia should be symmetric.");
236 self.inertia().data() << symmetric_inertia(0, 0), symmetric_inertia(1, 0),
237 symmetric_inertia(1, 1), symmetric_inertia(0, 2), symmetric_inertia(1, 2),
238 symmetric_inertia(2, 2);
241 static VectorXs toDynamicParameters_proxy(
const Inertia & self)
243 return self.toDynamicParameters();
246 static Inertia fromDynamicParameters_proxy(
const VectorXs & params)
248 if (params.rows() != 10 || params.cols() != 1)
250 std::ostringstream shape;
251 shape <<
"(" << params.rows() <<
", " << params.cols() <<
")";
252 throw std::invalid_argument(
253 "Wrong size: params" + shape.str() +
" but should have the following shape (10, 1)");
255 return Inertia::FromDynamicParameters(params);
259 makeFromMCI(
const Scalar & mass,
const Vector3 & lever,
const Matrix3 & inertia)
261#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS 262 if (!inertia.isApprox(inertia.transpose()))
263 throw eigenpy::Exception(
"The 3d inertia should be symmetric.");
265 (Vector3::UnitX().transpose() * inertia * Vector3::UnitX() < 0)
266 || (Vector3::UnitY().transpose() * inertia * Vector3::UnitY() < 0)
267 || (Vector3::UnitZ().transpose() * inertia * Vector3::UnitZ() < 0))
268 throw eigenpy::Exception(
"The 3d inertia should be positive.");
270 return new Inertia(mass, lever, inertia);
275 typedef ::boost::python::detail::not_specified HolderType;
276 bp::class_<Inertia, HolderType>(
278 "This class represenses a sparse version of a Spatial Inertia and its is defined by its " 279 "mass, its center of mass location and the rotational inertia expressed around this " 280 "center of mass.\n\n" 281 "Supported operations ...",
286 .def(::eigenpy::CopyableVisitor<Inertia>())
291 static Matrix6 __array__(
const Inertia & self, bp::object, bp::object)
293 return self.matrix();
296 struct Pickle : bp::pickle_suite
298 static boost::python::tuple getinitargs(
const Inertia & I)
300 return bp::make_tuple(I.mass(), (Vector3)I.lever(), I.inertia().matrix());
303 static bool getstate_manages_dict()
313 :
public boost::python::def_visitor<PseudoInertiaPythonVisitor<PseudoInertia>>
315 static constexpr int Options = PseudoInertia::Options;
316 typedef typename PseudoInertia::Scalar Scalar;
317 typedef typename PseudoInertia::Vector3 Vector3;
318 typedef typename PseudoInertia::Matrix3 Matrix3;
319 typedef typename PseudoInertia::Vector10 Vector10;
320 typedef typename PseudoInertia::Matrix4 Matrix4;
321 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs;
324 template<
class PyClass>
325 void visit(PyClass & cl)
const 328 bp::init<const Scalar &, const Vector3 &, const Matrix3 &>(
329 (bp::arg(
"self"), bp::arg(
"mass"), bp::arg(
"h"), bp::arg(
"sigma")),
330 "Initialize from mass, vector part of the pseudo inertia and matrix part of the " 333 bp::init<const PseudoInertia &>(
334 (bp::arg(
"self"), bp::arg(
"clone")),
"Copy constructor"))
336 "mass", &PseudoInertiaPythonVisitor::getMass, &PseudoInertiaPythonVisitor::setMass,
337 "Mass of the Pseudo Inertia.")
339 "h", &PseudoInertiaPythonVisitor::getH, &PseudoInertiaPythonVisitor::setH,
340 "Vector part of the Pseudo Inertia.")
342 "sigma", &PseudoInertiaPythonVisitor::getSigma, &PseudoInertiaPythonVisitor::setSigma,
343 "Matrix part of the Pseudo Inertia.")
346 "toMatrix", &PseudoInertia::toMatrix, bp::arg(
"self"),
347 "Returns the pseudo inertia as a 4x4 matrix.")
349 "toDynamicParameters", &PseudoInertiaPythonVisitor::toDynamicParameters_proxy,
350 bp::arg(
"self"),
"Returns the dynamic parameters representation.")
352 "toInertia", &PseudoInertia::toInertia, bp::arg(
"self"),
353 "Returns the inertia representation.")
355 "FromDynamicParameters", &PseudoInertiaPythonVisitor::fromDynamicParameters_proxy,
356 bp::args(
"dynamic_parameters"),
357 "Builds a pseudo inertia matrix from a vector of dynamic parameters." 358 "\nThe parameters are given as dynamic_parameters = [m, h_x, h_y, h_z, I_{xx}, " 359 "I_{xy}, I_{yy}, I_{xz}, I_{yz}, I_{zz}]^T.")
360 .staticmethod(
"FromDynamicParameters")
363 "FromMatrix", &PseudoInertia::FromMatrix, bp::args(
"pseudo_inertia_matrix"),
364 "Returns the Pseudo Inertia from a 4x4 matrix.")
365 .staticmethod(
"FromMatrix")
368 "FromInertia", &PseudoInertia::FromInertia, bp::args(
"inertia"),
369 "Returns the Pseudo Inertia from an Inertia object.")
370 .staticmethod(
"FromInertia")
372 .def(
"__array__", &PseudoInertia::toMatrix)
374 "__array__", &__array__,
375 (bp::arg(
"self"), bp::arg(
"dtype") = bp::object(), bp::arg(
"copy") = bp::object()))
376#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION 377 .def_pickle(Pickle())
382 static Scalar getMass(
const PseudoInertia & self)
386 static void setMass(PseudoInertia & self, Scalar mass)
391 static Vector3 getH(
const PseudoInertia & self)
395 static void setH(PseudoInertia & self,
const Vector3 & h)
400 static Matrix3 getSigma(
const PseudoInertia & self)
404 static void setSigma(PseudoInertia & self,
const Matrix3 & sigma)
409 static VectorXs toDynamicParameters_proxy(
const PseudoInertia & self)
411 return self.toDynamicParameters();
414 static PseudoInertia fromDynamicParameters_proxy(
const VectorXs & params)
416 if (params.rows() != 10 || params.cols() != 1)
418 std::ostringstream shape;
419 shape <<
"(" << params.rows() <<
", " << params.cols() <<
")";
420 throw std::invalid_argument(
421 "Wrong size: params" + shape.str() +
" but should have the following shape (10, 1)");
423 return PseudoInertia::FromDynamicParameters(params);
428 typedef ::boost::python::detail::not_specified HolderType;
429 bp::class_<PseudoInertia, HolderType>(
431 "This class represents a pseudo inertia matrix and it is defined by its mass, vector " 432 "part, and 3x3 matrix part.\n\n" 433 "Supported operations ...",
436 .def(::eigenpy::CopyableVisitor<PseudoInertia>())
443 static Matrix4 __array__(
const PseudoInertia & self, bp::object, bp::object)
445 return self.toMatrix();
448 struct Pickle : bp::pickle_suite
450 static boost::python::tuple getinitargs(
const PseudoInertia & pi)
452 return bp::make_tuple(pi.mass, pi.h, pi.sigma);
455 static bool getstate_manages_dict()
465 :
public boost::python::def_visitor<LogCholeskyParametersPythonVisitor<LogCholeskyParameters>>
467 static constexpr int Options = LogCholeskyParameters::Options;
468 typedef typename LogCholeskyParameters::Scalar Scalar;
469 typedef typename LogCholeskyParameters::Vector10 Vector10;
470 typedef typename LogCholeskyParameters::Matrix10 Matrix10;
471 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs;
472 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXs;
475 template<
class PyClass>
476 void visit(PyClass & cl)
const 480 bp::make_constructor(
481 &LogCholeskyParametersPythonVisitor::makeFromParameters, bp::default_call_policies(),
482 bp::args(
"log_cholesky_parameters")),
483 "Initialize from log cholesky parameters.")
485 bp::init<const LogCholeskyParameters &>(
486 (bp::arg(
"self"), bp::arg(
"clone")),
"Copy constructor"))
489 "parameters", &LogCholeskyParametersPythonVisitor::getParameters,
490 &LogCholeskyParametersPythonVisitor::setParameters,
"Log Cholesky parameters.")
493 "toDynamicParameters", &LogCholeskyParametersPythonVisitor::toDynamicParameters_proxy,
494 bp::arg(
"self"),
"Returns the dynamic parameters representation.")
496 "toPseudoInertia", &LogCholeskyParameters::toPseudoInertia, bp::arg(
"self"),
497 "Returns the Pseudo Inertia representation.")
499 "toInertia", &LogCholeskyParameters::toInertia, bp::arg(
"self"),
500 "Returns the Inertia representation.")
502 "calculateJacobian", &LogCholeskyParametersPythonVisitor::calculateJacobian_proxy,
503 bp::arg(
"self"),
"Calculates the Jacobian of the log Cholesky parameters.")
505 .def(
"__array__", &LogCholeskyParametersPythonVisitor::getParameters)
507 "__array__", &__array__,
508 (bp::arg(
"self"), bp::arg(
"dtype") = bp::object(), bp::arg(
"copy") = bp::object()))
509#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION 510 .def_pickle(Pickle())
515 static LogCholeskyParameters * makeFromParameters(
const VectorXs & params)
517 if (params.rows() != 10 || params.cols() != 1)
519 std::ostringstream shape;
520 shape <<
"(" << params.rows() <<
", " << params.cols() <<
")";
521 throw std::invalid_argument(
522 "Wrong size: params" + shape.str() +
" but should have the following shape (10, 1)");
524 return new LogCholeskyParameters(params);
527 static VectorXs getParameters(
const LogCholeskyParameters & self)
529 return self.parameters;
531 static void setParameters(LogCholeskyParameters & self,
const Vector10 & parameters)
533 self.parameters = parameters;
536 static VectorXs toDynamicParameters_proxy(
const LogCholeskyParameters & self)
538 return self.toDynamicParameters();
541 static MatrixXs calculateJacobian_proxy(
const LogCholeskyParameters & self)
543 return self.calculateJacobian();
548 typedef ::boost::python::detail::not_specified HolderType;
549 bp::class_<LogCholeskyParameters, HolderType>(
550 "LogCholeskyParameters",
551 "This class represents log Cholesky parameters.\n\n" 552 "Supported operations ...",
555 .def(::eigenpy::CopyableVisitor<LogCholeskyParameters>())
560 LogCholeskyParameters, ::pinocchio::LogCholeskyParameters>());
564 static VectorXs __array__(
const LogCholeskyParameters & self, bp::object, bp::object)
566 return self.parameters;
569 struct Pickle : bp::pickle_suite
571 static boost::python::tuple getinitargs(
const LogCholeskyParameters & lcp)
573 return bp::make_tuple(lcp.parameters);
576 static bool getstate_manages_dict()