GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/interpolation/time-constraint-path-validation.cc Lines: 0 31 0.0 %
Date: 2024-02-02 12:21:48 Branches: 0 64 0.0 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015 CNRS
3
// Authors: Florent Lamiraux
4
//
5
// This file is part of hpp-core
6
// hpp-core is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation, either version
9
// 3 of the License, or (at your option) any later version.
10
//
11
// hpp-core is distributed in the hope that it will be
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Lesser Public License for more details.  You should have
15
// received a copy of the GNU Lesser General Public License along with
16
// hpp-core  If not, see
17
// <http://www.gnu.org/licenses/>.
18
19
#include <hpp/core/collision-path-validation-report.hh>
20
#include <hpp/core/collision-validation.hh>
21
#include <hpp/core/config-validations.hh>
22
#include <hpp/core/joint-bound-validation.hh>
23
#include <hpp/core/path.hh>
24
#include <hpp/pinocchio/device.hh>
25
#include <hpp/rbprm/interpolation/time-constraint-path-validation.hh>
26
27
namespace hpp {
28
using namespace core;
29
namespace rbprm {
30
namespace interpolation {
31
32
TimeConstraintPathValidationPtr_t TimeConstraintPathValidation::create(
33
    const DevicePtr_t& robot, const value_type& stepSize,
34
    const std::size_t pathDofRank) {
35
  TimeConstraintPathValidation* ptr =
36
      new TimeConstraintPathValidation(robot, stepSize, pathDofRank);
37
  return TimeConstraintPathValidationPtr_t(ptr);
38
}
39
40
bool TimeConstraintPathValidation::validate(
41
    const PathPtr_t& path, bool reverse, PathPtr_t& validPart,
42
    PathValidationReportPtr_t& validationReport) {
43
  if (path->initial()[pathDofRank_] > path->end()[pathDofRank_]) {
44
    validPart = path->extract(
45
        interval_t(path->timeRange().first, path->timeRange().first));
46
    return false;
47
  }
48
  // to limit discontinuities, try to check that variation is not too important
49
  Configuration_t init = path->initial();
50
  Configuration_t end = path->end();
51
  std::size_t dim = init.rows() - 7;
52
  double totalDistance = (end.tail(dim) - init.tail(dim)).norm();
53
  double length = path->length();
54
  bool successPathOperator;
55
  // checking 10 points
56
  Configuration_t last_q = init;
57
  Configuration_t q = end;
58
  for (double i = 1; i < 10; ++i) {
59
    q = path->operator()(i / 10. * length, successPathOperator);
60
    assert(successPathOperator && "path operator () did not succeed");
61
    double distance = (last_q.tail(dim) - q.tail(dim)).norm();
62
    last_q = q;
63
    if (distance / totalDistance > 0.2) {
64
      validPart = path->extract(
65
          interval_t(path->timeRange().first, path->timeRange().first));
66
      return false;
67
    }
68
  }
69
  return core::pathValidation::Discretized::validate(path, reverse, validPart,
70
                                                     validationReport);
71
}
72
73
TimeConstraintPathValidation::TimeConstraintPathValidation(
74
    const DevicePtr_t& robot, const value_type& stepSize,
75
    const std::size_t pathDofRank)
76
    : core::pathValidation::Discretized(stepSize), pathDofRank_(pathDofRank) {
77
  add(CollisionValidation::create(robot));
78
  add(JointBoundValidation::create(robot));
79
}
80
}  // namespace interpolation
81
}  // namespace rbprm
82
}  // namespace hpp