Line |
Branch |
Exec |
Source |
1 |
|
|
// Copyright (c) 2015, 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 |
|
|
#include <hpp/core/config-projector.hh> |
30 |
|
|
#include <hpp/core/path-vector.hh> |
31 |
|
|
#include <hpp/core/path.hh> |
32 |
|
|
#include <hpp/core/problem.hh> |
33 |
|
|
#include <hpp/manipulation/constraint-set.hh> |
34 |
|
|
#include <hpp/manipulation/graph-optimizer.hh> |
35 |
|
|
#include <hpp/manipulation/graph-path-validation.hh> |
36 |
|
|
#include <hpp/manipulation/graph/edge.hh> |
37 |
|
|
|
38 |
|
|
namespace hpp { |
39 |
|
|
namespace manipulation { |
40 |
|
✗ |
PathVectorPtr_t GraphOptimizer::optimize(const PathVectorPtr_t& path) { |
41 |
|
✗ |
PathVectorPtr_t opted = PathVector::create(path->outputSize(), |
42 |
|
✗ |
path->outputDerivativeSize()), |
43 |
|
✗ |
expanded = PathVector::create(path->outputSize(), |
44 |
|
✗ |
path->outputDerivativeSize()), |
45 |
|
✗ |
toConcat; |
46 |
|
✗ |
GraphPathValidationPtr_t gpv = HPP_DYNAMIC_PTR_CAST( |
47 |
|
|
GraphPathValidation, this->problem()->pathValidation()); |
48 |
|
|
|
49 |
|
✗ |
path->flatten(expanded); |
50 |
|
✗ |
ConstraintSetPtr_t c; |
51 |
|
✗ |
for (std::size_t i_s = 0; i_s < expanded->numberPaths();) { |
52 |
|
|
PathVectorPtr_t toOpt = |
53 |
|
✗ |
PathVector::create(path->outputSize(), path->outputDerivativeSize()); |
54 |
|
✗ |
PathPtr_t current = expanded->pathAtRank(i_s); |
55 |
|
✗ |
toOpt->appendPath(current); |
56 |
|
✗ |
graph::EdgePtr_t edge; |
57 |
|
✗ |
c = HPP_DYNAMIC_PTR_CAST(ConstraintSet, current->constraints()); |
58 |
|
✗ |
if (c) edge = c->edge(); |
59 |
|
✗ |
bool isShort = edge && edge->isShort(); |
60 |
|
✗ |
std::size_t i_e = i_s + 1; |
61 |
|
✗ |
for (; i_e < expanded->numberPaths(); ++i_e) { |
62 |
|
✗ |
current = expanded->pathAtRank(i_e); |
63 |
|
✗ |
c = HPP_DYNAMIC_PTR_CAST(ConstraintSet, current->constraints()); |
64 |
|
✗ |
if (!c && edge) { |
65 |
|
|
hppDout(info, "No manipulation::ConstraintSet"); |
66 |
|
✗ |
break; |
67 |
|
|
} |
68 |
|
✗ |
if (c && edge->state() != c->edge()->state()) break; |
69 |
|
✗ |
if (isShort != |
70 |
|
✗ |
c->edge()->isShort()) // We do not optimize edges marked as short |
71 |
|
✗ |
break; |
72 |
|
✗ |
toOpt->appendPath(current); |
73 |
|
|
} |
74 |
|
|
hppDout(info, "Edge name: " << edge->name()); |
75 |
|
✗ |
if (isShort) |
76 |
|
✗ |
toConcat = toOpt; |
77 |
|
|
else { |
78 |
|
✗ |
core::ProblemPtr_t p = core::Problem::create(problem()->robot()); |
79 |
|
✗ |
p->distance(problem()->distance()); |
80 |
|
|
// It should be ok to use the path validation of each edge because it |
81 |
|
|
// corresponds to the global path validation minus the collision pairs |
82 |
|
|
// disabled using the edge constraint. |
83 |
|
|
// p.pathValidation(gpv->innerValidation()); |
84 |
|
✗ |
p->pathProjector(problem()->pathProjector()); |
85 |
|
✗ |
p->steeringMethod(edge->steeringMethod()->copy()); |
86 |
|
✗ |
p->constraints(edge->pathConstraint()); |
87 |
|
✗ |
if (p->constraints() && p->constraints()->configProjector()) { |
88 |
|
✗ |
p->constraints()->configProjector()->rightHandSideFromConfig( |
89 |
|
✗ |
toOpt->initial()); |
90 |
|
|
} |
91 |
|
✗ |
p->pathValidation(edge->pathValidation()); |
92 |
|
✗ |
pathOptimizer_ = factory_(p); |
93 |
|
✗ |
toConcat = pathOptimizer_->optimize(toOpt); |
94 |
|
|
} |
95 |
|
✗ |
i_s = i_e; |
96 |
|
✗ |
opted->concatenate(toConcat); |
97 |
|
|
} |
98 |
|
✗ |
pathOptimizer_.reset(); |
99 |
|
✗ |
return opted; |
100 |
|
|
} |
101 |
|
|
} // namespace manipulation |
102 |
|
|
} // namespace hpp |
103 |
|
|
|