liegroups.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_python_lie_group_hpp__
6 #define __pinocchio_python_lie_group_hpp__
7 
8 #include <eigenpy/memory.hpp>
9 
14 
15 namespace pinocchio
16 {
17  namespace python
18  {
19  namespace bp = boost::python;
20 
21  template<class LieGroupType>
23  {
24  typedef Eigen::Matrix<context::Scalar, Eigen::Dynamic, 1> ConfigVector_t;
25  typedef Eigen::Matrix<context::Scalar, Eigen::Dynamic, 1> TangentVector_t;
26  typedef Eigen::Matrix<context::Scalar, Eigen::Dynamic, Eigen::Dynamic> JacobianMatrix_t;
27 
28  static ConfigVector_t
29  integrate(const LieGroupType & lg, const ConfigVector_t & q, const TangentVector_t & v)
30  {
31  return lg.integrate(q, v);
32  }
33 
35  const LieGroupType & lg,
36  const ConfigVector_t & q0,
37  const ConfigVector_t & q1,
38  const context::Scalar & u)
39  {
40  return lg.interpolate(q0, q1, u);
41  }
42 
43  static TangentVector_t
44  difference(const LieGroupType & lg, const ConfigVector_t & q0, const ConfigVector_t & q1)
45  {
46  return lg.difference(q0, q1);
47  }
48 
50  const LieGroupType & lg,
51  const ConfigVector_t & q0,
52  const ConfigVector_t & q1,
53  const ArgumentPosition arg)
54  {
55  JacobianMatrix_t J(lg.nv(), lg.nv());
56  lg.dDifference(q0, q1, J, arg);
57  return J;
58  }
59 
61  const LieGroupType & lg,
62  const ConfigVector_t & q0,
63  const ConfigVector_t & q1,
64  const ArgumentPosition arg,
65  const JacobianMatrix_t & Jin,
66  int self)
67  {
68  JacobianMatrix_t J(Jin.rows(), Jin.cols());
69  switch (arg)
70  {
71  case ARG0:
72  lg.template dDifference<ARG0>(q0, q1, Jin, self, J, SETTO);
73  break;
74  case ARG1:
75  lg.template dDifference<ARG1>(q0, q1, Jin, self, J, SETTO);
76  break;
77  default:
78  throw std::invalid_argument("arg must be either ARG0 or ARG1");
79  }
80  return J;
81  }
82 
84  const LieGroupType & lg,
85  const ConfigVector_t & q0,
86  const ConfigVector_t & q1,
87  const ArgumentPosition arg,
88  int self,
89  const JacobianMatrix_t & Jin)
90  {
91  JacobianMatrix_t J(Jin.rows(), Jin.cols());
92  switch (arg)
93  {
94  case ARG0:
95  lg.template dDifference<ARG0>(q0, q1, self, Jin, J, SETTO);
96  break;
97  case ARG1:
98  lg.template dDifference<ARG1>(q0, q1, self, Jin, J, SETTO);
99  break;
100  default:
101  throw std::invalid_argument("arg must be either ARG0 or ARG1");
102  }
103  return J;
104  }
105 
107  const LieGroupType & lg,
108  const ConfigVector_t & q,
109  const TangentVector_t & v,
110  const ArgumentPosition arg)
111  {
112  JacobianMatrix_t J(lg.nv(), lg.nv());
113  lg.dIntegrate(q, v, J, arg);
114  return J;
115  }
116 
117  static JacobianMatrix_t
118  dIntegrate_dq1(const LieGroupType & lg, const ConfigVector_t & q, const TangentVector_t & v)
119  {
120  JacobianMatrix_t J(lg.nv(), lg.nv());
121  lg.dIntegrate_dq(q, v, J);
122  return J;
123  }
124 
126  const LieGroupType & lg,
127  const ConfigVector_t & q,
128  const TangentVector_t & v,
129  const JacobianMatrix_t & Jin,
130  int self)
131  {
132  JacobianMatrix_t J(Jin.rows(), lg.nv());
133  lg.dIntegrate_dq(q, v, Jin, self, J, SETTO);
134  return J;
135  }
136 
138  const LieGroupType & lg,
139  const ConfigVector_t & q,
140  const TangentVector_t & v,
141  int self,
142  const JacobianMatrix_t & Jin)
143  {
144  JacobianMatrix_t J(lg.nv(), Jin.cols());
145  lg.dIntegrate_dq(q, v, self, Jin, J, SETTO);
146  return J;
147  }
148 
149  static JacobianMatrix_t
150  dIntegrate_dv1(const LieGroupType & lg, const ConfigVector_t & q, const TangentVector_t & v)
151  {
152  JacobianMatrix_t J(lg.nv(), lg.nv());
153  lg.dIntegrate_dv(q, v, J);
154  return J;
155  }
156 
158  const LieGroupType & lg,
159  const ConfigVector_t & q,
160  const TangentVector_t & v,
161  const JacobianMatrix_t & Jin,
162  int self)
163  {
164  JacobianMatrix_t J(Jin.rows(), lg.nv());
165  lg.dIntegrate_dv(q, v, Jin, self, J, SETTO);
166  return J;
167  }
168 
170  const LieGroupType & lg,
171  const ConfigVector_t & q,
172  const TangentVector_t & v,
173  int self,
174  const JacobianMatrix_t & Jin)
175  {
176  JacobianMatrix_t J(lg.nv(), Jin.cols());
177  lg.dIntegrate_dv(q, v, self, Jin, J, SETTO);
178  return J;
179  }
180 
182  const LieGroupType & lg,
183  const ConfigVector_t & q,
184  const TangentVector_t & v,
185  const JacobianMatrix_t & J,
186  const ArgumentPosition arg)
187  {
188  JacobianMatrix_t Jout(lg.nv(), J.cols());
189  lg.dIntegrateTransport(q, v, J, Jout, arg);
190  return Jout;
191  }
192  };
193 
194  template<class LieGroupType>
196  : public boost::python::def_visitor<LieGroupPythonVisitor<LieGroupType>>
197  {
198  public:
199  /* --- Exposing C++ API to python through the handler ----------------- */
200  template<class PyClass>
201  void visit(PyClass & cl) const
202  {
203  typedef Eigen::Matrix<context::Scalar, Eigen::Dynamic, 1> ConfigVector_t;
204 
205  typedef LieGroupWrapperTpl<LieGroupType> LieGroupWrapper;
206  cl.def(bp::init<>("Default constructor"))
207  .def("integrate", LieGroupWrapper::integrate)
208  .def("dIntegrate", LieGroupWrapper::dIntegrate)
209  .def("dIntegrate_dq", LieGroupWrapper::dIntegrate_dq1)
210  .def("dIntegrate_dq", LieGroupWrapper::dIntegrate_dq2)
211  .def("dIntegrate_dq", LieGroupWrapper::dIntegrate_dq3)
212  .def("dIntegrate_dv", LieGroupWrapper::dIntegrate_dv1)
213  .def("dIntegrate_dv", LieGroupWrapper::dIntegrate_dv2)
214  .def("dIntegrate_dv", LieGroupWrapper::dIntegrate_dv3)
215  .def("dIntegrateTransport", LieGroupWrapper::dIntegrateTransport_proxy)
216  .def("difference", LieGroupWrapper::difference)
217  .def("dDifference", LieGroupWrapper::dDifference1)
218  .def("dDifference", LieGroupWrapper::dDifference2)
219  .def("dDifference", LieGroupWrapper::dDifference3)
220 
221  .def("interpolate", LieGroupWrapper::interpolate)
222 
223  .def(
224  "random", static_cast<typename LieGroupType::ConfigVector_t (LieGroupType::*)() const>(
226  .def(
227  "randomConfiguration",
228  &LieGroupType::template randomConfiguration<ConfigVector_t, ConfigVector_t>)
229  .def("distance", &LieGroupType::template distance<ConfigVector_t, ConfigVector_t>)
230  .def(
231  "squaredDistance",
232  &LieGroupType::template squaredDistance<ConfigVector_t, ConfigVector_t>)
233  .def("normalize", &LieGroupType::template normalize<ConfigVector_t>)
234 
235  .add_property("name", &LieGroupType::name)
236  .add_property("neutral", &LieGroupType::neutral)
237  .add_property("nq", &LieGroupType::nq)
238  .add_property("nv", &LieGroupType::nv)
239 
240  .def(bp::self * bp::self)
241  .def(bp::self *= bp::self)
242 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
243  .def(bp::self == bp::self)
244 #endif
245  ;
246  }
247 
248  static void expose(const char * name)
249  {
250  bp::class_<LieGroupType>(name, bp::no_init).def(LieGroupPythonVisitor<LieGroupType>());
251  }
252  };
253  } // namespace python
254 } // namespace pinocchio
255 
256 #endif // ifndef __pinocchio_python_geometry_model_hpp__
boost::python
pinocchio::python::LieGroupWrapperTpl::integrate
static ConfigVector_t integrate(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v)
Definition: liegroups.hpp:29
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dq1
static JacobianMatrix_t dIntegrate_dq1(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v)
Definition: liegroups.hpp:118
pinocchio::SETTO
@ SETTO
Definition: fwd.hpp:132
pinocchio::u
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > const Scalar & u
Definition: joint-configuration.hpp:1139
pinocchio::dIntegrate
void dIntegrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< JacobianMatrixType > &J, const ArgumentPosition arg, const AssignmentOperatorType op=SETTO)
Computes the Jacobian of a small variation of the configuration vector or the tangent vector into the...
Definition: joint-configuration.hpp:487
pinocchio::name
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
pinocchio::python::LieGroupWrapperTpl::dDifference3
static JacobianMatrix_t dDifference3(const LieGroupType &lg, const ConfigVector_t &q0, const ConfigVector_t &q1, const ArgumentPosition arg, int self, const JacobianMatrix_t &Jin)
Definition: liegroups.hpp:83
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dv3
static JacobianMatrix_t dIntegrate_dv3(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, int self, const JacobianMatrix_t &Jin)
Definition: liegroups.hpp:169
inverse-kinematics-3d.J
J
Definition: inverse-kinematics-3d.py:28
pinocchio::python::LieGroupWrapperTpl::TangentVector_t
Eigen::Matrix< context::Scalar, Eigen::Dynamic, 1 > TangentVector_t
Definition: liegroups.hpp:25
pinocchio::ArgumentPosition
ArgumentPosition
Argument position. Used as template parameter to refer to an argument.
Definition: fwd.hpp:121
pinocchio::difference
void difference(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1, const Eigen::MatrixBase< ReturnType > &dvout)
Compute the tangent vector that must be integrated during one unit time to go from q0 to q1.
Definition: joint-configuration.hpp:193
pinocchio::ARG0
@ ARG0
Definition: fwd.hpp:123
pinocchio::interpolate
void interpolate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1, const Scalar &u, const Eigen::MatrixBase< ReturnType > &qout)
Interpolate two configurations for a given model.
Definition: joint-configuration.hpp:127
cartesian-product-variant.hpp
codegen-rnea.nq
nq
Definition: codegen-rnea.py:18
pinocchio::python::LieGroupWrapperTpl::ConfigVector_t
Eigen::Matrix< context::Scalar, Eigen::Dynamic, 1 > ConfigVector_t
Definition: liegroups.hpp:24
pinocchio::random
void random(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< Config_t > &qout)
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dv2
static JacobianMatrix_t dIntegrate_dv2(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, const JacobianMatrix_t &Jin, int self)
Definition: liegroups.hpp:157
pinocchio::python::LieGroupWrapperTpl::dDifference1
static JacobianMatrix_t dDifference1(const LieGroupType &lg, const ConfigVector_t &q0, const ConfigVector_t &q1, const ArgumentPosition arg)
Definition: liegroups.hpp:49
pinocchio::integrate
void integrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< ReturnType > &qout)
Integrate a configuration vector for the specified model for a tangent vector during one unit time.
Definition: joint-configuration.hpp:70
pinocchio::python::LieGroupWrapperTpl::dDifference2
static JacobianMatrix_t dDifference2(const LieGroupType &lg, const ConfigVector_t &q0, const ConfigVector_t &q1, const ArgumentPosition arg, const JacobianMatrix_t &Jin, int self)
Definition: liegroups.hpp:60
python
pinocchio::python::v
const Vector3Like & v
Definition: bindings/python/spatial/explog.hpp:66
liegroup-generic.hpp
pinocchio::ARG1
@ ARG1
Definition: fwd.hpp:124
pinocchio::q0
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > & q0
Definition: joint-configuration.hpp:1137
pinocchio::python::LieGroupWrapperTpl::JacobianMatrix_t
Eigen::Matrix< context::Scalar, Eigen::Dynamic, Eigen::Dynamic > JacobianMatrix_t
Definition: liegroups.hpp:26
setup.name
name
Definition: cmake/cython/setup.in.py:179
pinocchio::python::LieGroupPythonVisitor
Definition: liegroups.hpp:195
pinocchio::python::LieGroupWrapperTpl::difference
static TangentVector_t difference(const LieGroupType &lg, const ConfigVector_t &q0, const ConfigVector_t &q1)
Definition: liegroups.hpp:44
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dv1
static JacobianMatrix_t dIntegrate_dv1(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v)
Definition: liegroups.hpp:150
pinocchio::python::dIntegrateTransport_proxy
context::MatrixXs dIntegrateTransport_proxy(const context::Model &model, const context::VectorXs &q, const context::VectorXs &v, const context::MatrixXs &Jin, const ArgumentPosition arg)
Definition: algorithm/expose-joints.cpp:51
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dq3
static JacobianMatrix_t dIntegrate_dq3(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, int self, const JacobianMatrix_t &Jin)
Definition: liegroups.hpp:137
pinocchio::python::LieGroupPythonVisitor::visit
void visit(PyClass &cl) const
Definition: liegroups.hpp:201
pinocchio::python::LieGroupWrapperTpl
Definition: liegroups.hpp:22
liegroup.hpp
cl
cl
pinocchio::python::LieGroupWrapperTpl::dIntegrateTransport_proxy
static JacobianMatrix_t dIntegrateTransport_proxy(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, const JacobianMatrix_t &J, const ArgumentPosition arg)
Definition: liegroups.hpp:181
pinocchio::q1
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
Definition: joint-configuration.hpp:1138
memory.hpp
codegen-rnea.nv
nv
Definition: codegen-rnea.py:19
pinocchio::python::LieGroupWrapperTpl::interpolate
static ConfigVector_t interpolate(const LieGroupType &lg, const ConfigVector_t &q0, const ConfigVector_t &q1, const context::Scalar &u)
Definition: liegroups.hpp:34
pinocchio::neutral
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
Definition: joint-configuration.hpp:363
liegroup-collection.hpp
pinocchio::python::LieGroupWrapperTpl::dIntegrate_dq2
static JacobianMatrix_t dIntegrate_dq2(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, const JacobianMatrix_t &Jin, int self)
Definition: liegroups.hpp:125
pinocchio::python::LieGroupWrapperTpl::dIntegrate
static JacobianMatrix_t dIntegrate(const LieGroupType &lg, const ConfigVector_t &q, const TangentVector_t &v, const ArgumentPosition arg)
Definition: liegroups.hpp:106
pinocchio::python::LieGroupPythonVisitor::expose
static void expose(const char *name)
Definition: liegroups.hpp:248
pinocchio::python::context::Scalar
PINOCCHIO_PYTHON_SCALAR_TYPE Scalar
Definition: bindings/python/context/generic.hpp:37
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:47