hpp-pinocchio  6.0.0
Wrapping of the kinematic/dynamic chain Pinocchio for HPP.
liegroup-element.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, CNRS
2 // Authors: Florent Lamiraux
3 //
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 
29 #ifndef HPP_PINOCCHIO_LIEGROUP_ELEMENT_HH
30 #define HPP_PINOCCHIO_LIEGROUP_ELEMENT_HH
31 
34 #include <pinocchio/math/quaternion.hpp>
35 
36 namespace hpp {
37 namespace pinocchio {
40 
44 template <typename vector_type>
46  public:
50  template <typename Derived>
51  LiegroupElementConstBase(const Eigen::EigenBase<Derived>& value,
52  const LiegroupSpacePtr_t& liegroupSpace)
53  : value_(value.derived()), space_(liegroupSpace) {
54  check();
55  }
56 
61  template <typename Derived>
62  explicit LiegroupElementConstBase(const Eigen::EigenBase<Derived>& value)
63  : value_(value.derived()),
64  space_(LiegroupSpace::create(value.derived().size())) {}
65 
68  template <typename vector_type2>
70  : value_(other.vector()), space_(other.space()) {}
71 
73  const LiegroupSpacePtr_t& space() const { return space_; }
74 
76  const vector_type& vector() const { return value_; }
77 
79  size_type size() const { return value_.size(); }
80 
83  void check() const { assert(value_.size() == space_->nq()); }
84 
86  template <typename vector_type2>
88  return ((*space_ == *(other.space_)) && (value_ == other.value_));
89  }
90 
92  template <typename vector_type2>
94  return ((*space_ != *(other.space_)) || (value_ != other.value_));
95  }
96 
97  protected:
98  template <typename Derived>
99  LiegroupElementConstBase(const Eigen::EigenBase<Derived>& value,
100  const LiegroupSpacePtr_t& space,
101  void* /*to enable this constructor*/)
102  : value_(const_cast<Derived&>(value.derived())), space_(space) {}
103 
104  vector_type value_;
106 
107  template <typename vector_type2>
109  template <typename vector_type2>
110  friend class LiegroupElementBase;
111 };
112 
116 template <typename vector_type>
117 class LiegroupElementBase : public LiegroupElementConstBase<vector_type> {
118  public:
120 
124  LiegroupElementBase(const vector_type& value, const LiegroupSpacePtr_t& space)
125  : Base(value, space, NULL) {}
126 
130  : Base(vector_t(space->nq()), space) {}
131 
136  explicit LiegroupElementBase(const vector_type& value)
137  : Base(value, LiegroupSpace::create(value.size()), NULL) {}
138 
141  template <typename vector_type2>
143  : Base(other.value_, other.space()) {}
144 
149  template <typename vector_type2>
151  : Base(other.value_, other.space()) {}
152 
154  template <typename vector_type2>
156  : Base(other.value_, other.space(), NULL) {}
157 
160 
162  const vector_type& vector() const { return Base::vector(); }
163 
165  vector_type& vector() { return this->value_; }
166 
168  void setNeutral() { this->value_ = this->space_->neutral().vector(); }
169 
172 
174  template <typename vector_type2>
177  this->space_ = other.space();
178  this->value_ = other.vector();
179  return *this;
180  }
181 
183  template <typename Vector>
184  LiegroupElementBase& operator=(const Eigen::MatrixBase<Vector>& v) {
185  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Vector);
186  assert(this->space_->nq() == v.derived().size());
187  this->value_.noalias() = v.derived();
188  return *this;
189  }
190 };
191 
200 template <typename vector_type>
202  vectorIn_t v);
203 
211 template <typename vector_type1, typename vector_type2>
214 
221 template <typename vector_type>
224  const value_type& eps = PINOCCHIO_DEFAULT_QUATERNION_NORM_TOLERANCE_VALUE);
226 
228 template <typename vector_type>
230 
231 template <typename vector_type>
232 inline std::ostream& operator<<(
233  std::ostream& os, const LiegroupElementConstBase<vector_type>& e) {
234  os << "Lie group element in " << *(e.space()) << " represented by vector ("
235  << e.vector().transpose() << ")";
236  return os;
237 }
238 } // namespace pinocchio
239 } // namespace hpp
240 
241 HPP_SERIALIZABLE_SPLIT_FREE(hpp::pinocchio::LiegroupElement)
242 
243 #endif // HPP_PINOCCHIO_LIEGROUP_ELEMENT_HH
Definition: liegroup-element.hh:117
void setNeutral()
Set element to neutral element.
Definition: liegroup-element.hh:168
LiegroupElementBase(const vector_type &value)
Definition: liegroup-element.hh:136
LiegroupElementBase(LiegroupElementBase< vector_type2 > &other)
Casting operator from LiegroupElement to LiegroupElementRef
Definition: liegroup-element.hh:155
const vector_type & vector() const
Const vector representation.
Definition: liegroup-element.hh:162
LiegroupElementBase & operator=(const Eigen::MatrixBase< Vector > &v)
Assignment from a vector.
Definition: liegroup-element.hh:184
LiegroupElementBase(const LiegroupElementConstBase< vector_type2 > &other)
Definition: liegroup-element.hh:142
LiegroupElementConstBase< vector_type > Base
Definition: liegroup-element.hh:119
LiegroupElementBase()
Constructor of trivial element.
Definition: liegroup-element.hh:159
vector_type & vector()
Modifiable vector representation.
Definition: liegroup-element.hh:165
LiegroupElementBase(const LiegroupSpacePtr_t &space)
Definition: liegroup-element.hh:129
LiegroupElementBase & operator=(const LiegroupElementConstBase< vector_type2 > &other)
Assignment from another LiegroupElement.
Definition: liegroup-element.hh:175
LiegroupElementBase(const vector_type &value, const LiegroupSpacePtr_t &space)
Definition: liegroup-element.hh:124
LiegroupElementBase & operator+=(vectorIn_t v)
Inplace integration of a velocity vector.
LiegroupElementBase(const LiegroupElementBase< vector_type2 > &other)
Definition: liegroup-element.hh:150
Definition: liegroup-element.hh:45
LiegroupElementConstBase(const Eigen::EigenBase< Derived > &value, const LiegroupSpacePtr_t &space, void *)
Definition: liegroup-element.hh:99
void check() const
Definition: liegroup-element.hh:83
vector_type value_
Definition: liegroup-element.hh:104
size_type size() const
Size of the vector representation.
Definition: liegroup-element.hh:79
const LiegroupSpacePtr_t & space() const
get reference to vector of Lie groups
Definition: liegroup-element.hh:73
LiegroupElementConstBase(const LiegroupElementConstBase< vector_type2 > &other)
Definition: liegroup-element.hh:69
bool operator!=(const LiegroupElementConstBase< vector_type2 > &other)
Equality operator.
Definition: liegroup-element.hh:93
bool operator==(const LiegroupElementConstBase< vector_type2 > &other)
Equality operator.
Definition: liegroup-element.hh:87
const vector_type & vector() const
Const vector representation.
Definition: liegroup-element.hh:76
LiegroupElementConstBase(const Eigen::EigenBase< Derived > &value)
Definition: liegroup-element.hh:62
LiegroupSpacePtr_t space_
Definition: liegroup-element.hh:105
LiegroupElementConstBase(const Eigen::EigenBase< Derived > &value, const LiegroupSpacePtr_t &liegroupSpace)
Definition: liegroup-element.hh:51
Definition: liegroup-space.hh:101
vector_t operator-(const LiegroupElementConstBase< vector_type1 > &e1, const LiegroupElementConstBase< vector_type2 > &e2)
LiegroupElement operator+(const LiegroupElementConstBase< vector_type > &e, vectorIn_t v)
bool checkNormalized(const LiegroupElementConstBase< vector_type > &e1, const value_type &eps=PINOCCHIO_DEFAULT_QUATERNION_NORM_TOLERANCE_VALUE)
Eigen::Matrix< value_type, Eigen::Dynamic, 1 > vector_t
Definition: fwd.hh:88
std::ostream & operator<<(std::ostream &os, const hpp::pinocchio::Device &device)
Definition: device.hh:366
shared_ptr< LiegroupSpace > LiegroupSpacePtr_t
Definition: fwd.hh:150
matrix_t::Index size_type
Definition: fwd.hh:97
double value_type
Definition: fwd.hh:51
Eigen::Ref< const vector_t > vectorIn_t
Definition: fwd.hh:93
vector_t log(const LiegroupElementConstBase< vector_type > &lge)
Compute the log as a tangent vector of a Lie group element.
Utility functions.
Definition: body.hh:39
Definition: collision-object.hh:40