bindings/python/multibody/data.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2021 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_python_multibody_data_hpp__
6 #define __pinocchio_python_multibody_data_hpp__
7 
8 #include <boost/python.hpp>
9 
10 #include "pinocchio/multibody/data.hpp"
11 #include "pinocchio/serialization/data.hpp"
12 
13 #include <eigenpy/memory.hpp>
15 #include <eigenpy/exception.hpp>
16 
20 
22 
24 
25 namespace pinocchio
26 {
27  namespace python
28  {
29  namespace bp = boost::python;
30 
31  template<typename Data>
32  struct PickleData : bp::pickle_suite
33  {
34  static bp::tuple getinitargs(const Data &)
35  {
36  return bp::make_tuple();
37  }
38 
39  static bp::tuple getstate(const Data & data)
40  {
41  const std::string str(data.saveToString());
42  return bp::make_tuple(bp::str(str));
43  }
44 
45  static void setstate(Data & data, bp::tuple tup)
46  {
47  if(bp::len(tup) == 0 || bp::len(tup) > 1)
48  {
49  throw eigenpy::Exception("Pickle was not able to reconstruct the model from the loaded data.\n"
50  "The pickle data structure contains too many elements.");
51  }
52 
53  bp::object py_obj = tup[0];
54  boost::python::extract<std::string> obj_as_string(py_obj.ptr());
55  if(obj_as_string.check())
56  {
57  const std::string str = obj_as_string;
58  data.loadFromString(str);
59  }
60  else
61  {
62  throw eigenpy::Exception("Pickle was not able to reconstruct the model from the loaded data.\n"
63  "The entry is not a string.");
64  }
65 
66  }
67  };
68 
70  : public boost::python::def_visitor< DataPythonVisitor >
71  {
75 
76  public:
77 
78 #define ADD_DATA_PROPERTY(NAME,DOC) \
79  def_readwrite(#NAME, \
80  &Data::NAME, \
81  DOC)
82 
83 #define ADD_DATA_PROPERTY_READONLY(NAME,DOC) \
84  def_readonly(#NAME, \
85  &Data::NAME, \
86  DOC)
87 
88 #define ADD_DATA_PROPERTY_READONLY_BYVALUE(NAME,DOC) \
89  add_property(#NAME, \
90  make_getter(&Data::NAME,bp::return_value_policy<bp::return_by_value>()), \
91  DOC)
92 
93 
94  /* --- Exposing C++ API to python through the handler ----------------- */
95  template<class PyClass>
96  void visit(PyClass& cl) const
97  {
98  cl
99  .def(bp::init<>(bp::arg("self"),"Default constructor."))
100  .def(bp::init<Model>(bp::arg("model"),"Constructs a data structure from a given model."))
101 
102  .ADD_DATA_PROPERTY(a,"Joint spatial acceleration")
103  .ADD_DATA_PROPERTY(oa,
104  "Joint spatial acceleration expressed at the origin of the world frame.")
105  .ADD_DATA_PROPERTY(a_gf,
106  "Joint spatial acceleration containing also the contribution of the gravity acceleration")
107  .ADD_DATA_PROPERTY(oa_gf,"Joint spatial acceleration containing also the contribution of the gravity acceleration, but expressed at the origin of the world frame.")
108 
109  .ADD_DATA_PROPERTY(v,"Joint spatial velocity expressed in the joint frame.")
110  .ADD_DATA_PROPERTY(ov,"Joint spatial velocity expressed at the origin of the world frame.")
111 
112  .ADD_DATA_PROPERTY(f,"Joint spatial force expresssed in the joint frame.")
113  .ADD_DATA_PROPERTY(of,"Joint spatial force expresssed at the origin of the world frame.")
114  .ADD_DATA_PROPERTY(h,"Vector of spatial momenta expressed in the local frame of the joint.")
115  .ADD_DATA_PROPERTY(oMi,"Body absolute placement (wrt world)")
116  .ADD_DATA_PROPERTY(oMf,"frames absolute placement (wrt world)")
117  .ADD_DATA_PROPERTY(liMi,"Body relative placement (wrt parent)")
118  .ADD_DATA_PROPERTY(tau,"Joint torques (output of RNEA)")
119  .ADD_DATA_PROPERTY(nle,"Non Linear Effects (output of nle algorithm)")
120  .ADD_DATA_PROPERTY(ddq,"Joint accelerations (output of ABA)")
121  .ADD_DATA_PROPERTY(Ycrb,"Inertia of the sub-tree composit rigid body")
122  .ADD_DATA_PROPERTY(M,"The joint space inertia matrix")
123  .ADD_DATA_PROPERTY(Minv,"The inverse of the joint space inertia matrix")
124  .ADD_DATA_PROPERTY(C,"The Coriolis C(q,v) matrix such that the Coriolis effects are given by c(q,v) = C(q,v)v")
125  .ADD_DATA_PROPERTY(g,"Vector of generalized gravity (dim model.nv).")
126  .ADD_DATA_PROPERTY(Fcrb,"Spatial forces set, used in CRBA")
127  .ADD_DATA_PROPERTY(lastChild,"Index of the last child (for CRBA)")
128  .ADD_DATA_PROPERTY(nvSubtree,"Dimension of the subtree motion space (for CRBA)")
129  .ADD_DATA_PROPERTY(U,"Joint Inertia square root (upper triangle)")
130  .ADD_DATA_PROPERTY(D,"Diagonal of UDUT inertia decomposition")
131  .ADD_DATA_PROPERTY(parents_fromRow,"First previous non-zero row in M (used in Cholesky)")
132  .ADD_DATA_PROPERTY(nvSubtree_fromRow,"Subtree of the current row index (used in Cholesky)")
133  .ADD_DATA_PROPERTY(J,"Jacobian of joint placement")
134  .ADD_DATA_PROPERTY(dJ,"Time variation of the Jacobian of joint placement (data.J).")
135  .ADD_DATA_PROPERTY(iMf,"Body placement wrt to algorithm end effector.")
136 
137  .ADD_DATA_PROPERTY(Ag,
138  "Centroidal matrix which maps from joint velocity to the centroidal momentum.")
139  .ADD_DATA_PROPERTY(dAg,
140  "Time derivative of the centroidal momentum matrix Ag.")
141  .ADD_DATA_PROPERTY(hg,
142  "Centroidal momentum (expressed in the frame centered at the CoM and aligned with the world frame).")
143  .ADD_DATA_PROPERTY(dhg,
144  "Centroidal momentum time derivative (expressed in the frame centered at the CoM and aligned with the world frame).")
145  .ADD_DATA_PROPERTY(Ig,
146  "Centroidal Composite Rigid Body Inertia.")
147 
148  .ADD_DATA_PROPERTY(com,"CoM position of the subtree starting at joint index i.")
149  .ADD_DATA_PROPERTY(vcom,"CoM velocity of the subtree starting at joint index i.")
150  .ADD_DATA_PROPERTY(acom,"CoM acceleration of the subtree starting at joint index i.")
151  .ADD_DATA_PROPERTY(mass,"Mass of the subtree starting at joint index i.")
152  .ADD_DATA_PROPERTY(Jcom,"Jacobian of center of mass.")
153 
154  .ADD_DATA_PROPERTY(dtau_dq,"Partial derivative of the joint torque vector with respect to the joint configuration.")
155  .ADD_DATA_PROPERTY(dtau_dv,"Partial derivative of the joint torque vector with respect to the joint velocity.")
156  .ADD_DATA_PROPERTY(ddq_dq,"Partial derivative of the joint acceleration vector with respect to the joint configuration.")
157  .ADD_DATA_PROPERTY(ddq_dv,"Partial derivative of the joint acceleration vector with respect to the joint velocity.")
158 
159  .ADD_DATA_PROPERTY(kinetic_energy,"Kinetic energy in [J] computed by computeKineticEnergy")
160  .ADD_DATA_PROPERTY(potential_energy,"Potential energy in [J] computed by computePotentialEnergy")
161 
162  .ADD_DATA_PROPERTY(lambda_c,"Lagrange Multipliers linked to contact forces")
163  .ADD_DATA_PROPERTY(impulse_c,"Lagrange Multipliers linked to contact impulses")
164 
165  .ADD_DATA_PROPERTY(dq_after,"Generalized velocity after the impact.")
166  .ADD_DATA_PROPERTY(staticRegressor,"Static regressor.")
167  .ADD_DATA_PROPERTY(jointTorqueRegressor,"Joint torque regressor.")
168 
169  .def(bp::self == bp::self)
170  .def(bp::self != bp::self)
171  ;
172  }
173 
174  /* --- Expose --------------------------------------------------------- */
175  static void expose()
176  {
177  bp::class_<Data>("Data",
178  "Articulated rigid body data related to a Model.\n"
179  "It contains all the data that can be modified by the Pinocchio algorithms.",
180  bp::no_init)
181  .def(DataPythonVisitor())
182  .def(CopyableVisitor<Data>())
184  .def_pickle(PickleData<Data>());
185 
186  typedef PINOCCHIO_ALIGNED_STD_VECTOR(Vector3) StdVec_Vector3;
187  typedef PINOCCHIO_ALIGNED_STD_VECTOR(Matrix6x) StdVec_Matrix6x;
188 
191  serialize<StdAlignedVectorPythonVisitor<Vector3,false>::vector_type>();
192 
195  serialize<StdAlignedVectorPythonVisitor<Matrix6x,false>::vector_type>();
196 
198  serialize<StdVectorPythonVisitor<int>::vector_type>();
199  }
200 
201  };
202 
203  }} // namespace pinocchio::python
204 
205 #endif // ifndef __pinocchio_python_multibody_data_hpp__
static void setstate(Data &data, bp::tuple tup)
std::string saveToString() const
Saves a Derived object to a string.
Expose an std::vector from a type given as template argument.
Definition: std-vector.hpp:170
Expose an container::aligned_vector from a type given as template argument.
v
D
C
Definition: dcrba.py:412
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
U
Definition: ocp.py:61
Add the Python method copy to allow a copy of this by calling the copy constructor.
Definition: copyable.hpp:21
static bp::tuple getinitargs(const Data &)
Main pinocchio namespace.
Definition: timings.cpp:30
static bp::tuple getstate(const Data &data)
void loadFromString(const std::string &str)
Loads a Derived object from a string.
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
The 3d jacobian type (temporary)
list a
h
Definition: ur5x4.py:45
M
#define EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(...)
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
The 6d jacobian type (temporary)
Eigen::Matrix< Scalar, 3, 1, Options > Vector3


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02