hpp-pinocchio  4.9.1
Wrapping of the kinematic/dynamic chain Pinocchio for HPP.
cartesian-product.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-pinocchio.
5 // hpp-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 // hpp-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 // hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
18 #define HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
19 
20 #include <pinocchio/multibody/liegroup/cartesian-product.hpp>
21 
22 #include <hpp/util/exception-factory.hh>
23 
24 namespace hpp {
25  namespace pinocchio {
26  namespace liegroup {
27  template<typename LieGroup1, typename LieGroup2>
29  {
30  enum {
31  BoundSize = LieGroup1::BoundSize + LieGroup2::BoundSize,
32  NR = LieGroup1::NR + LieGroup2::NR,
33  NT = LieGroup1::NT + LieGroup2::NT
34  };
35 
36  typedef ::pinocchio::CartesianProductOperation<LieGroup1, LieGroup2> Base;
37 
38  template <class ConfigL_t, class ConfigR_t>
40  const Eigen::MatrixBase<ConfigL_t> & q0,
41  const Eigen::MatrixBase<ConfigR_t> & q1)
42  {
43  return Base::squaredDistance(q0, q1);
44  }
45 
46  template <class ConfigL_t, class ConfigR_t>
48  const Eigen::MatrixBase<ConfigL_t> & q0,
49  const Eigen::MatrixBase<ConfigR_t> & q1,
50  const typename ConfigL_t::Scalar& w)
51  {
52  return LieGroup1().squaredDistance(q0.template head<LieGroup1::NQ>(), q1.template head<LieGroup1::NQ>(), w)
53  + LieGroup2().squaredDistance(q0.template tail<LieGroup2::NQ>(), q1.template tail<LieGroup2::NQ>(), w);
54  }
55 
56  template <class ConfigIn_t, class ConfigOut_t>
57  static void setBound(
58  const Eigen::MatrixBase<ConfigIn_t > & bound,
59  const Eigen::MatrixBase<ConfigOut_t> & out)
60  {
61  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigOut_t, Base::ConfigVector_t)
62  ConfigOut_t& oout = const_cast<Eigen::MatrixBase<ConfigOut_t>&> (out).derived();
63  if (bound.size() == BoundSize) {
64  if (LieGroup1::BoundSize > 0)
65  LieGroup1::setBound(bound.template head<LieGroup1::BoundSize>(),
66  oout. template head<LieGroup1::NQ >());
67  if (LieGroup2::BoundSize > 0)
68  LieGroup2::setBound(bound.template tail<LieGroup2::BoundSize>(),
69  oout. template tail<LieGroup2::NQ >());
70  } else if (bound.size() == Base::NQ) {
71  LieGroup1::setBound(bound.template head<LieGroup1::NQ>(),
72  oout. template head<LieGroup1::NQ>());
73  LieGroup2::setBound(bound.template tail<LieGroup2::NQ>(),
74  oout. template tail<LieGroup2::NQ>());
75  } else {
76  HPP_THROW(std::invalid_argument,
77  "Expected vector of size " << (int)BoundSize << " or " << (int)Base::NQ
78  << ", got size " << bound.size());
79  }
80  }
81 
82  template <class JacobianIn_t, class JacobianOut_t>
84  const Eigen::MatrixBase<JacobianIn_t > & Jin,
85  const Eigen::MatrixBase<JacobianOut_t> & Jout)
86  {
87  JacobianOut_t& J = const_cast<Eigen::MatrixBase<JacobianOut_t>&> (Jout).derived();
88  if (LieGroup1::NR > 0)
89  LieGroup1::getRotationSubJacobian(Jin.template leftCols<LieGroup1::NV>(),
90  J .template leftCols<LieGroup1::NR>());
91  if (LieGroup2::NR > 0)
92  LieGroup2::getRotationSubJacobian(Jin.template rightCols<LieGroup2::NV>(),
93  J .template rightCols<LieGroup2::NR>());
94  }
95 
96  template <class ConfigIn_t>
97  static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t > & q, const value_type& eps)
98  {
99  EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigIn_t , Base::ConfigVector_t);
100  return LieGroup1::isNormalized(q.template head<LieGroup1::NQ>(), eps)
101  && LieGroup2::isNormalized(q.template tail<LieGroup2::NQ>(), eps);
102  }
103  }; // struct CartesianProductOperation
104  } // namespace liegroup
105  } // namespace pinocchio
106 } // namespace hpp
107 
108 #endif // HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
#define HPP_THROW(TYPE, MSG)
Utility functions.
Definition: cartesian-product.hh:28
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const typename ConfigL_t::Scalar &w)
Definition: cartesian-product.hh:47
static void setBound(const Eigen::MatrixBase< ConfigIn_t > &bound, const Eigen::MatrixBase< ConfigOut_t > &out)
Definition: cartesian-product.hh:57
bool isNormalized(const DevicePtr_t &robot, ConfigurationIn_t q, const value_type &eps)
::pinocchio::CartesianProductOperation< LieGroup1, LieGroup2 > Base
Definition: cartesian-product.hh:36
Scalar squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1) const
static void getRotationSubJacobian(const Eigen::MatrixBase< JacobianIn_t > &Jin, const Eigen::MatrixBase< JacobianOut_t > &Jout)
Definition: cartesian-product.hh:83
double value_type
Definition: fwd.hh:40
static bool isNormalized(const Eigen::MatrixBase< ConfigIn_t > &q, const value_type &eps)
Definition: cartesian-product.hh:97
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1)
Definition: cartesian-product.hh:39