pinocchio  UNKNOWN
vector-space.hpp
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_vector_space_operation_hpp__
19 #define __se3_vector_space_operation_hpp__
20 
21 #include <stdexcept>
22 
23 #include "pinocchio/multibody/liegroup/operation-base.hpp"
24 
25 #include <boost/integer/static_min_max.hpp>
26 
27 namespace se3
28 {
29  template<int Size> struct VectorSpaceOperation;
30  template<int Size> struct traits<VectorSpaceOperation<Size> > {
31  typedef double Scalar;
32  enum {
33  NQ = Size,
34  NV = Size
35  };
36  };
37 
38  template<int Size = Eigen::Dynamic>
39  struct VectorSpaceOperation : public LieGroupBase <VectorSpaceOperation<Size> >
40  {
41  SE3_LIE_GROUP_TPL_PUBLIC_INTERFACE(VectorSpaceOperation);
42 
46  VectorSpaceOperation (int size = boost::static_signed_max<0,Size>::value) : size_ (size)
47  {
48  assert (size_.value() >= 0);
49  }
50 
53  VectorSpaceOperation (const VectorSpaceOperation& other) : Base (), size_ (other.size_.value())
54  {
55  assert (size_.value() >= 0);
56  }
57 
58  Index nq () const
59  {
60  return size_.value();
61  }
62  Index nv () const
63  {
64  return size_.value();
65  }
66 
67  ConfigVector_t neutral () const
68  {
69  return ConfigVector_t::Zero(size_.value());;
70  }
71 
72  std::string name () const
73  {
74  std::ostringstream oss; oss << "R^" << nq();
75  return oss.str ();
76  }
77 
78  template <class ConfigL_t, class ConfigR_t, class Tangent_t>
79  static void difference_impl(const Eigen::MatrixBase<ConfigL_t> & q0,
80  const Eigen::MatrixBase<ConfigR_t> & q1,
81  const Eigen::MatrixBase<Tangent_t> & d)
82  {
83  const_cast< Eigen::MatrixBase<Tangent_t>& > (d) = q1 - q0;
84  }
85 
86  template <class ConfigL_t, class ConfigR_t, class JacobianLOut_t, class JacobianROut_t>
87  static void Jdifference_impl(const Eigen::MatrixBase<ConfigL_t> &,
88  const Eigen::MatrixBase<ConfigR_t> &,
89  const Eigen::MatrixBase<JacobianLOut_t>& J0,
90  const Eigen::MatrixBase<JacobianROut_t>& J1)
91  {
92  const_cast< JacobianLOut_t& > (J0.derived()).setZero();
93  const_cast< JacobianLOut_t& > (J0.derived()).diagonal().setConstant(-1);
94  const_cast< JacobianROut_t& > (J1.derived()).setIdentity();
95  }
96 
97  template <class ConfigIn_t, class Velocity_t, class ConfigOut_t>
98  static void integrate_impl(const Eigen::MatrixBase<ConfigIn_t> & q,
99  const Eigen::MatrixBase<Velocity_t> & v,
100  const Eigen::MatrixBase<ConfigOut_t> & qout)
101  {
102  const_cast< Eigen::MatrixBase<ConfigOut_t>& > (qout) = q + v;
103  }
104 
105  template <class Tangent_t, class JacobianOut_t>
106  static void Jintegrate_impl(const Eigen::MatrixBase<Tangent_t> &,
107  const Eigen::MatrixBase<JacobianOut_t> & J)
108  {
109  const_cast< JacobianOut_t& > (J.derived()).setIdentity();
110  }
111 
112  template <class Config_t, class Tangent_t, class JacobianOut_t>
113  static void dIntegrate_dq_impl(const Eigen::MatrixBase<Config_t > & /*q*/,
114  const Eigen::MatrixBase<Tangent_t> & /*v*/,
115  const Eigen::MatrixBase<JacobianOut_t>& J)
116  {
117  const_cast< JacobianOut_t& > (J.derived()).setIdentity();
118  }
119 
120  template <class Config_t, class Tangent_t, class JacobianOut_t>
121  static void dIntegrate_dv_impl(const Eigen::MatrixBase<Config_t > & /*q*/,
122  const Eigen::MatrixBase<Tangent_t> & /*v*/,
123  const Eigen::MatrixBase<JacobianOut_t>& J)
124  {
125  const_cast< JacobianOut_t& > (J.derived()).setIdentity();
126  }
127 
128 
129  // template <class ConfigL_t, class ConfigR_t>
130  // static double squaredDistance_impl(const Eigen::MatrixBase<ConfigL_t> & q0,
131  // const Eigen::MatrixBase<ConfigR_t> & q1)
132 
133  template <class Config_t>
134  static void normalize_impl (const Eigen::MatrixBase<Config_t>& /*qout*/)
135  {}
136 
137  template <class Config_t>
138  void random_impl (const Eigen::MatrixBase<Config_t>& qout) const
139  {
140  const_cast< Eigen::MatrixBase<Config_t>& > (qout).setRandom();
141  }
142 
143  template <class ConfigL_t, class ConfigR_t, class ConfigOut_t>
144  void randomConfiguration_impl
145  (const Eigen::MatrixBase<ConfigL_t> & lower_pos_limit,
146  const Eigen::MatrixBase<ConfigR_t> & upper_pos_limit,
147  const Eigen::MatrixBase<ConfigOut_t> & qout) const
148  {
149  ConfigOut_t& res = const_cast< Eigen::MatrixBase<ConfigOut_t>& > (qout).derived();
150  for (int i = 0; i < nq (); ++i)
151  {
152  if(lower_pos_limit[i] == -std::numeric_limits<Scalar>::infinity() ||
153  upper_pos_limit[i] == std::numeric_limits<Scalar>::infinity() )
154  {
155  std::ostringstream error;
156  error << "non bounded limit. Cannot uniformly sample joint at rank " << i;
157  // assert(false && "non bounded limit. Cannot uniformly sample joint revolute");
158  throw std::runtime_error(error.str());
159  }
160  res[i] = lower_pos_limit[i] + (( upper_pos_limit[i] - lower_pos_limit[i]) * rand())/RAND_MAX;
161  }
162  }
163  private:
164  Eigen::internal::variable_if_dynamic<Index, Size> size_;
165  }; // struct VectorSpaceOperation
166 
167 } // namespace se3
168 
169 #endif // ifndef __se3_vector_space_operation_hpp__
VectorSpaceOperation(int size=boost::static_signed_max< 0, Size >::value)
std::string name(const LieGroupVariant &lg)
Visit a LieGroupVariant to get the name of it.
Eigen::VectorXd neutral(const Model &model)
Return the neutral configuration element related to the model configuration space.
int nq(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNqVisitor to get the dimension of the joint configuration spac...
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
VectorSpaceOperation(const VectorSpaceOperation &other)