hpp-pinocchio 6.0.0
Wrapping of the kinematic/dynamic chain Pinocchio for HPP.
Loading...
Searching...
No Matches
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
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_CARTESIAN_PRODUCT_OPERATION_HH
30#define HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
31
32#include <hpp/util/exception-factory.hh>
33#include <pinocchio/multibody/liegroup/cartesian-product.hpp>
34
35namespace hpp {
36namespace pinocchio {
37namespace liegroup {
38template <typename LieGroup1, typename LieGroup2>
40 : public ::pinocchio::CartesianProductOperation<LieGroup1, LieGroup2> {
41 enum {
42 BoundSize = LieGroup1::BoundSize + LieGroup2::BoundSize,
43 NR = LieGroup1::NR + LieGroup2::NR,
44 NT = LieGroup1::NT + LieGroup2::NT
45 };
46
47 typedef ::pinocchio::CartesianProductOperation<LieGroup1, LieGroup2> Base;
48
49 template <class ConfigL_t, class ConfigR_t>
50 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
51 const Eigen::MatrixBase<ConfigR_t>& q1) {
52 return Base::squaredDistance(q0, q1);
53 }
54
55 template <class ConfigL_t, class ConfigR_t>
56 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
57 const Eigen::MatrixBase<ConfigR_t>& q1,
58 const typename ConfigL_t::Scalar& w) {
59 return LieGroup1().squaredDistance(q0.template head<LieGroup1::NQ>(),
60 q1.template head<LieGroup1::NQ>(), w) +
61 LieGroup2().squaredDistance(q0.template tail<LieGroup2::NQ>(),
62 q1.template tail<LieGroup2::NQ>(), w);
63 }
64
65 template <class ConfigIn_t, class ConfigOut_t>
66 static void setBound(const Eigen::MatrixBase<ConfigIn_t>& bound,
67 const Eigen::MatrixBase<ConfigOut_t>& out) {
68 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigOut_t, Base::ConfigVector_t)
69 ConfigOut_t& oout =
70 const_cast<Eigen::MatrixBase<ConfigOut_t>&>(out).derived();
71 if (bound.size() == BoundSize) {
72 if (LieGroup1::BoundSize > 0)
73 LieGroup1::setBound(bound.template head<LieGroup1::BoundSize>(),
74 oout.template head<LieGroup1::NQ>());
75 if (LieGroup2::BoundSize > 0)
76 LieGroup2::setBound(bound.template tail<LieGroup2::BoundSize>(),
77 oout.template tail<LieGroup2::NQ>());
78 } else if (bound.size() == Base::NQ) {
79 LieGroup1::setBound(bound.template head<LieGroup1::NQ>(),
80 oout.template head<LieGroup1::NQ>());
81 LieGroup2::setBound(bound.template tail<LieGroup2::NQ>(),
82 oout.template tail<LieGroup2::NQ>());
83 } else {
84 HPP_THROW(std::invalid_argument, "Expected vector of size "
85 << (int)BoundSize << " or "
86 << (int)Base::NQ << ", got size "
87 << bound.size());
88 }
89 }
90
91 template <class JacobianIn_t, class JacobianOut_t>
93 const Eigen::MatrixBase<JacobianIn_t>& Jin,
94 const Eigen::MatrixBase<JacobianOut_t>& Jout) {
95 JacobianOut_t& J =
96 const_cast<Eigen::MatrixBase<JacobianOut_t>&>(Jout).derived();
97 if (LieGroup1::NR > 0)
98 LieGroup1::getRotationSubJacobian(Jin.template leftCols<LieGroup1::NV>(),
99 J.template leftCols<LieGroup1::NR>());
100 if (LieGroup2::NR > 0)
101 LieGroup2::getRotationSubJacobian(Jin.template rightCols<LieGroup2::NV>(),
102 J.template rightCols<LieGroup2::NR>());
103 }
104
105 template <class ConfigIn_t>
106 static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t>& q,
107 const value_type& eps) {
108 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigIn_t, Base::ConfigVector_t);
109 return LieGroup1::isNormalized(q.template head<LieGroup1::NQ>(), eps) &&
110 LieGroup2::isNormalized(q.template tail<LieGroup2::NQ>(), eps);
111 }
112}; // struct CartesianProductOperation
113} // namespace liegroup
114} // namespace pinocchio
115} // namespace hpp
116
117#endif // HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
double value_type
Definition fwd.hh:51
Utility functions.
Definition body.hh:39
Definition collision-object.hh:40
Definition cartesian-product.hh:40
static void setBound(const Eigen::MatrixBase< ConfigIn_t > &bound, const Eigen::MatrixBase< ConfigOut_t > &out)
Definition cartesian-product.hh:66
static void getRotationSubJacobian(const Eigen::MatrixBase< JacobianIn_t > &Jin, const Eigen::MatrixBase< JacobianOut_t > &Jout)
Definition cartesian-product.hh:92
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1, const typename ConfigL_t::Scalar &w)
Definition cartesian-product.hh:56
@ NT
Definition cartesian-product.hh:44
@ BoundSize
Definition cartesian-product.hh:42
@ NR
Definition cartesian-product.hh:43
static bool isNormalized(const Eigen::MatrixBase< ConfigIn_t > &q, const value_type &eps)
Definition cartesian-product.hh:106
double squaredDistance(const Eigen::MatrixBase< ConfigL_t > &q0, const Eigen::MatrixBase< ConfigR_t > &q1)
Definition cartesian-product.hh:50
::pinocchio::CartesianProductOperation< LieGroup1, LieGroup2 > Base
Definition cartesian-product.hh:47