path_planning_checker.hpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef PATH_PLANNING_CHECKER_HPP_
9 #define PATH_PLANNING_CHECKER_HPP_
10 
11 #include <gtest/gtest.h>
12 #include <fstream>
13 #include "fields2cover.h"
14 
15 
16 inline testing::AssertionResult isPathCorrect(const F2CPath& path) {
17  if (path.size() < 1) {
18  return testing::AssertionFailure() <<
19  "Error 3001: The path do not have any state";
20  } else if (path.size() > 1) {
21 
22  int errors_big_dist {0};
23  int errors_big_angle {0};
24  for (size_t i = 0; i < path.size() - 1; ++i) {
25  F2CPoint p2 = path[i].atEnd();
26  if (p2.distance(path[i + 1].point) > 5e-3) {
27  std::cerr << "Path checker Error 3009: dist between end of state " << i <<
28  " " << p2 << " and start of next one " <<
29  path[i + 1].point << " is " <<
30  p2.distance(path[i + 1].point) << std::endl;
31  ++errors_big_dist;
32  }
34  path[i + 1].angle, path[i].angle) > M_PI / 8.0) {
35  std::cerr << "Path checker Error 3010: Angle between state " << i <<
36  " " << p2 << " and start of next one " <<
37  path[i + 1].point << " is " <<
39  path[i + 1].angle, path[i].angle) << std::endl;
40  ++errors_big_angle;
41  }
42  }
43  if (errors_big_dist) {
44  return testing::AssertionFailure() <<
45  "Error 3009: The end of one state and the next one doesn't connect on" <<
46  errors_big_dist << " states";
47  }
48  if (errors_big_angle) {
49  return testing::AssertionFailure() <<
50  "Error 3010: The end of one state and the next one doesn't connect on" <<
51  errors_big_angle << " states";
52  }
53  }
54  return testing::AssertionSuccess();
55 }
56 
57 inline testing::AssertionResult IsPathCorrect(
58  const F2CPath& path, F2CPoint start, double start_ang,
59  F2CPoint end, double end_ang, bool check_y_lower_limit = true) {
60  if (path.size() < 1) {
61  return testing::AssertionFailure() <<
62  "Error 3001: The path do not have any state";
63  } else if (check_y_lower_limit &&
64  std::any_of(path.begin(), path.end(),
65  [] (const f2c::types::PathState& p) {return p.point.getY() < -0.05;})) {
66  return testing::AssertionFailure() <<
67  "Error 3002: Lower limit on Y axis is crossed.";
68  } else if (path[0].point.distance(start) > 1e-2) {
69  return testing::AssertionFailure() <<
70  "Error 3003: Start point should be " << start << ", but is " <<
71  path[0].point <<".";
72  } else if (path.atEnd().distance(end) > 1e-2) {
73  return testing::AssertionFailure() <<
74  "Error 3004: End point should be " << end << ", but is " <<
75  path.atEnd() <<".";
76  } else if (F2CPoint::getAngleDiffAbs(path[0].angle, start_ang) > 0.1) {
77  return testing::AssertionFailure() <<
78  "Error 3006: Start angle should be " << start_ang <<
79  ", but computed angle is " << path[0].angle << ".";
80  } else if (F2CPoint::getAngleDiffAbs(path.back().angle, end_ang) > 0.1) {
81  return testing::AssertionFailure() <<
82  "Error 3007: End angle should be " << end_ang <<
83  ", but computed angle is " << path.back().angle << ".";
84  } else if (start.distance(end) > path.length()) {
85  return testing::AssertionFailure() <<
86  "Error 3008: Length of the curve (" << path.length() <<
87  ") is smaller than the distance between start to end points (" <<
88  start.distance(end) << ").";
89  }
90  return isPathCorrect(path);
91 }
92 
93 #endif // PATH_PLANNING_CHECKER_HPP_
2_objective_functions.path
path
Definition: 2_objective_functions.py:88
1_basic_types.end
end
Definition: 1_basic_types.py:76
fields2cover.h
f2c::types::PathState
Definition: PathState.h:27
1_basic_types.p2
p2
Definition: 1_basic_types.py:15
f2c::types::Path
Definition: Path.h:23
f2c::types::Point
Definition: Point.h:21
f2c::types::Geometry< OGRPoint, wkbPoint >::getAngleDiffAbs
static double getAngleDiffAbs(double a, double b)
Definition: Geometry_impl.hpp:204
f2c::types::Geometry::distance
double distance(const Geometry< T2, R2 > &p) const
Compute shortest distance between this and another geometry.
Definition: Geometry_impl.hpp:139
isPathCorrect
testing::AssertionResult isPathCorrect(const F2CPath &path)
Definition: path_planning_checker.hpp:16
IsPathCorrect
testing::AssertionResult IsPathCorrect(const F2CPath &path, F2CPoint start, double start_ang, F2CPoint end, double end_ang, bool check_y_lower_limit=true)
Definition: path_planning_checker.hpp:57


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31