hpp-pinocchio  4.14.0
Wrapping of the kinematic/dynamic chain Pinocchio for HPP.
vector-space.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
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_VECTOR_SPACE_OPERATION_HH
30 #define HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
31 
32 #include <hpp/pinocchio/fwd.hh>
33 #include <hpp/util/exception-factory.hh>
34 #include <pinocchio/multibody/liegroup/vector-space.hpp>
35 
36 namespace hpp {
37 namespace pinocchio {
38 namespace liegroup {
40 namespace details {
41 template <bool Test>
42 struct assign_if {
43  template <class D1, class D2>
44  static void run(const Eigen::MatrixBase<D1>& /*Jin*/,
45  const Eigen::MatrixBase<D2>& /*Jout*/) {}
46 };
47 template <>
48 struct assign_if<true> {
49  template <class D1, class D2>
50  static void run(const Eigen::MatrixBase<D1>& Jin,
51  const Eigen::MatrixBase<D2>& Jout) {
52  const_cast<Eigen::MatrixBase<D2>&>(Jout) = Jin;
53  }
54 };
55 } // namespace details
57 
58 template <int Size, bool rot>
60  : public ::pinocchio::VectorSpaceOperationTpl<Size, value_type> {
61  typedef ::pinocchio::VectorSpaceOperationTpl<Size, value_type> Base;
62  enum { BoundSize = Size, NR = (rot ? Size : 0), NT = (rot ? 0 : Size) };
63 
67  VectorSpaceOperation(int size = std::max(0, Size)) : Base(size) {}
68 
69  template <class ConfigL_t, class ConfigR_t>
70  double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
71  const Eigen::MatrixBase<ConfigR_t>& q1) {
72  return Base::squaredDistance(q0, q1);
73  }
74 
75  template <class ConfigL_t, class ConfigR_t>
76  double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
77  const Eigen::MatrixBase<ConfigR_t>& q1,
78  const typename ConfigL_t::Scalar& w) {
79  if (rot)
80  return w * squaredDistance(q0, q1);
81  else
82  return squaredDistance(q0, q1);
83  }
84 
85  template <class ConfigIn_t, class ConfigOut_t>
86  static void setBound(const Eigen::MatrixBase<ConfigIn_t>& bounds,
87  const Eigen::MatrixBase<ConfigOut_t>& out) {
88  if (bounds.size() != BoundSize) {
89  HPP_THROW(std::invalid_argument, "Expected vector of size "
90  << (int)BoundSize << ", got size "
91  << bounds.size());
92  }
93  const_cast<Eigen::MatrixBase<ConfigOut_t>&>(out) = bounds;
94  }
95 
96  template <class JacobianIn_t, class JacobianOut_t>
98  const Eigen::MatrixBase<JacobianIn_t>& Jin,
99  const Eigen::MatrixBase<JacobianOut_t>& Jout) {
100  details::assign_if<rot>::run(Jin, Jout);
101  }
102 
103  template <class ConfigIn_t>
104  static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t>&,
105  const value_type&) {
106  return true;
107  }
108 };
109 } // namespace liegroup
110 } // namespace pinocchio
111 } // namespace hpp
112 
113 namespace pinocchio {
114 template <int Size, bool rot>
115 struct traits<hpp::pinocchio::liegroup::VectorSpaceOperation<Size, rot> >
116  : public traits<typename hpp::pinocchio::liegroup::VectorSpaceOperation<
117  Size, rot>::Base> {};
118 } // namespace pinocchio
119 
120 #endif // HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
double value_type
Definition: fwd.hh:50
Utility functions.
Definition: body.hh:39
Definition: collision-object.hh:40
static bool isNormalized(const Eigen::MatrixBase< ConfigIn_t > &, const value_type &)
Definition: vector-space.hh:104
static void setBound(const Eigen::MatrixBase< ConfigIn_t > &bounds, const Eigen::MatrixBase< ConfigOut_t > &out)
Definition: vector-space.hh:86
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1)
Definition: vector-space.hh:70
VectorSpaceOperation(int size=std::max(0, Size))
Definition: vector-space.hh:67
::pinocchio::VectorSpaceOperationTpl< Size, value_type > Base
Definition: vector-space.hh:61
static void getRotationSubJacobian(const Eigen::MatrixBase< JacobianIn_t > &Jin, const Eigen::MatrixBase< JacobianOut_t > &Jout)
Definition: vector-space.hh:97
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const typename ConfigL_t::Scalar &w)
Definition: vector-space.hh:76
@ NR
Definition: vector-space.hh:62
@ BoundSize
Definition: vector-space.hh:62
@ NT
Definition: vector-space.hh:62