pinocchio  2.4.4
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
cartesian-product-variant.hpp
1 //
2 // Copyright (c) 2018 CNRS
3 //
4 
5 #ifndef __pinocchio_cartesian_product_variant_hpp__
6 #define __pinocchio_cartesian_product_variant_hpp__
7 
8 #include "pinocchio/multibody/liegroup/operation-base.hpp"
9 #include "pinocchio/multibody/liegroup/liegroup-variant.hpp"
10 #include "pinocchio/multibody/liegroup/liegroup-variant-visitors.hpp"
11 
12 #include <vector>
13 
14 namespace pinocchio
15 {
16 
17  struct CartesianProductOperationVariant;
18 
19  template<>
21  {
22  typedef double Scalar;
23  enum {
24  NQ = Eigen::Dynamic,
25  NV = Eigen::Dynamic
26  };
27  };
28 
32  struct CartesianProductOperationVariant : public LieGroupOperationBase<CartesianProductOperationVariant>
33  {
34  PINOCCHIO_LIE_GROUP_PUBLIC_INTERFACE(CartesianProductOperationVariant);
35 
38  : m_nq(0), m_nv(0)
39  , lg_nqs(0), lg_nvs(0)
40  , m_neutral(0)
41  {};
42 
48  CartesianProductOperationVariant(const LieGroupVariant & lg)
49  {
50  append(lg);
51  };
52 
59  CartesianProductOperationVariant(const LieGroupVariant & lg1,
60  const LieGroupVariant & lg2)
61  {
62  append(lg1); append(lg2);
63  };
64 
70  void append(const LieGroupVariant & lg)
71  {
72  liegroups.push_back(lg);
73  const Index lg_nq = ::pinocchio::nq(lg); lg_nqs.push_back(lg_nq); m_nq += lg_nq;
74  const Index lg_nv = ::pinocchio::nv(lg); lg_nvs.push_back(lg_nv); m_nv += lg_nv;
75 
76  if(liegroups.size() > 1)
77  m_name += " x ";
78  m_name += ::pinocchio::name(lg);
79 
80  m_neutral.conservativeResize(m_nq);
81  m_neutral.tail(lg_nq) = ::pinocchio::neutral(lg);
82 
83  }
84 
85  int nq() const { return m_nq; }
86  int nv() const { return m_nv; }
87 
88  std::string name() const { return m_name; }
89 
90  ConfigVector_t neutral() const { return m_neutral; }
91 
92  template <class ConfigIn_t, class Velocity_t, class ConfigOut_t>
93  void integrate_impl(const Eigen::MatrixBase<ConfigIn_t> & q,
94  const Eigen::MatrixBase<Velocity_t> & v,
95  const Eigen::MatrixBase<ConfigOut_t> & qout) const
96  {
97  assert(q.size() == m_nq);
98  assert(v.size() == m_nv);
99  assert(qout.size() == m_nq);
100 
101  ConfigOut_t & qout_ = PINOCCHIO_EIGEN_CONST_CAST(ConfigOut_t,qout);
102  Index id_q = 0, id_v = 0;
103  for(size_t k = 0; k < liegroups.size(); ++k)
104  {
105  const Index & nq = lg_nqs[k];
106  const Index & nv = lg_nvs[k];
107  ::pinocchio::integrate(liegroups[k],
108  q.segment(id_q,lg_nqs[k]),
109  v.segment(id_v,lg_nvs[k]),
110  qout_.segment(id_q,lg_nqs[k]));
111 
112  id_q += nq; id_v += nv;
113  }
114 
115  }
116 
117 // template <class Config_t>
118 // void random_impl (const Eigen::MatrixBase<Config_t>& qout) const
119 // {
120 // R3crossSO3_t().random(qout);
121 // }
122 //
123 // template <class ConfigL_t, class ConfigR_t, class ConfigOut_t>
124 // void randomConfiguration_impl(const Eigen::MatrixBase<ConfigL_t> & lower,
125 // const Eigen::MatrixBase<ConfigR_t> & upper,
126 // const Eigen::MatrixBase<ConfigOut_t> & qout)
127 // const
128 // {
129 // R3crossSO3_t ().randomConfiguration(lower, upper, qout);
130 // }
131 
132  protected:
133 
134  std::vector<LieGroupVariant> liegroups;
135  Index m_nq, m_nv;
136  std::vector<Index> lg_nqs, lg_nvs;
137  std::string m_name;
138 
139  ConfigVector_t m_neutral;
140 
141  };
142 
143 } // namespace pinocchio
144 
145 #endif // ifndef __pinocchio_cartesian_product_variant_hpp__
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space...
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
void append(const LieGroupVariant &lg)
Append a Lie group to the Cartesian product.
CartesianProductOperationVariant(const LieGroupVariant &lg)
Constructor with one single Lie group.
Dynamic Cartesian product composed of elementary Lie groups defined in LieGroupVariant.
Main pinocchio namespace.
Definition: treeview.dox:24
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:35
CartesianProductOperationVariant(const LieGroupVariant &lg1, const LieGroupVariant &lg2)
Constructor with two Lie groups.