Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2018 CNRS |
2 |
|
|
// Authors: Joseph Mirabel |
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 |
|
|
#include <hpp/constraints/manipulability.hh> |
30 |
|
|
|
31 |
|
|
namespace hpp { |
32 |
|
|
namespace constraints { |
33 |
|
✗ |
Manipulability::Manipulability(DifferentiableFunctionPtr_t function, |
34 |
|
✗ |
DevicePtr_t robot, std::string name) |
35 |
|
|
: DifferentiableFunction(function->inputSize(), |
36 |
|
|
function->inputDerivativeSize(), 1, name), |
37 |
|
✗ |
function_(function), |
38 |
|
✗ |
robot_(robot), |
39 |
|
✗ |
J_(function->outputDerivativeSize(), function->inputDerivativeSize()) { |
40 |
|
✗ |
activeParameters_ = function->activeParameters(); |
41 |
|
✗ |
activeDerivativeParameters_ = function->activeDerivativeParameters(); |
42 |
|
✗ |
cols_ = Eigen::BlockIndex::fromLogicalExpression(activeDerivativeParameters_); |
43 |
|
✗ |
J_JT_.resize(J_.rows(), J_.rows()); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
✗ |
void Manipulability::impl_compute(LiegroupElementRef res, |
47 |
|
|
vectorIn_t arg) const { |
48 |
|
✗ |
assert(cols_.cols().size() > 0); |
49 |
|
|
|
50 |
|
✗ |
function_->jacobian(J_, arg); |
51 |
|
|
value_type logAbsDeterminant; |
52 |
|
|
|
53 |
|
|
// ------------ SVD --------------------------------------------------- // |
54 |
|
✗ |
J_JT_ = cols_.rview(J_); |
55 |
|
✗ |
Eigen::JacobiSVD<matrix_t> svd(J_JT_); |
56 |
|
✗ |
logAbsDeterminant = svd.singularValues() |
57 |
|
✗ |
.array() |
58 |
|
✗ |
.cwiseMax(std::numeric_limits<value_type>::min()) |
59 |
|
✗ |
.log10() |
60 |
|
✗ |
.sum(); |
61 |
|
|
|
62 |
|
|
/* |
63 |
|
|
// ------------ Other decomposition methods --------------------------- // |
64 |
|
|
|
65 |
|
|
// 1. Compute J * J^T |
66 |
|
|
if (cols_.cols().size() > 1) { |
67 |
|
|
typedef typename Eigen::ColBlockIndices::View<const matrix_t>::type |
68 |
|
|
MatrixView_t; MatrixView_t J (cols_.rview(J_)); |
69 |
|
|
//std::cout << J.eval() << std::endl; |
70 |
|
|
J_JT_.setZero(); |
71 |
|
|
for (MatrixView_t::block_iterator block (J); block.valid(); ++block) |
72 |
|
|
J_JT_.noalias() += J._block(block) * J._block(block).transpose(); |
73 |
|
|
} else { |
74 |
|
|
const segment_t& s = cols_.cols()[0]; |
75 |
|
|
//std::cout << J_.middleCols(s.first, s.second) << std::endl; |
76 |
|
|
J_JT_.noalias() = J_.middleCols(s.first, s.second) |
77 |
|
|
* J_.middleCols(s.first, s.second).transpose(); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
// 2. Compute decomposition |
81 |
|
|
|
82 |
|
|
// 2.1 LDLT |
83 |
|
|
Eigen::LDLT<matrix_t> ldlt (J_JT_); |
84 |
|
|
logAbsDeterminant = ldlt.matrixL().nestedExpression().diagonal().array() |
85 |
|
|
.cwiseMax(std::numeric_limits<value_type>::min()) |
86 |
|
|
.log10() |
87 |
|
|
.sum(); |
88 |
|
|
logAbsDeterminant += ldlt.vectorD().array() |
89 |
|
|
.cwiseMax(std::numeric_limits<value_type>::min()) |
90 |
|
|
.log10() |
91 |
|
|
.sum(); |
92 |
|
|
// 2.2 QRs (FullPiv is more robust that ColPiv) |
93 |
|
|
//Eigen::ColPivHouseholderQR<matrix_t> qr (J_JT_); |
94 |
|
|
Eigen::FullPivHouseholderQR<matrix_t> qr (J_JT_); |
95 |
|
|
logAbsDeterminant = qr.logAbsDeterminant(); |
96 |
|
|
// */ |
97 |
|
|
|
98 |
|
|
// This funcion will be used as a cost function whose squared norm is to |
99 |
|
|
// be minimized. |
100 |
|
✗ |
res.vector()[0] = std::max(-logAbsDeterminant, 0.); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
✗ |
void Manipulability::impl_jacobian(matrixOut_t jacobian, vectorIn_t arg) const { |
104 |
|
✗ |
finiteDifferenceCentral(jacobian, arg, robot_, 1e-8); |
105 |
|
|
} |
106 |
|
|
} // namespace constraints |
107 |
|
|
} // namespace hpp |
108 |
|
|
|