dubins_test.cpp
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 #include <gtest/gtest.h>
8 #include <numeric>
9 #include <fstream>
11 #include "fields2cover/types.h"
12 #include "../test_helpers/path_planning_checker.hpp"
13 
14 TEST(fields2cover_pp_dubins, turn_dist) {
16  robot.setCruiseVel(2.0);
17  robot.setMaxCurv(1.0);
18  robot.setMaxDiffCurv(1.0);
19 
21  F2CPoint start(0.0, 0.0), end(-3.0, 0.0);
22  auto path = turn.createTurn(robot,
23  start, boost::math::constants::half_pi<double>(),
24  end, 3.0 * boost::math::constants::half_pi<double>());
25  EXPECT_TRUE(IsPathCorrect(path, start, boost::math::constants::half_pi<double>(),
26  end, 3.0 * boost::math::constants::half_pi<double>()));
27 }
28 
29 TEST(fields2cover_pp_dubins, random_points) {
31  robot.setCruiseVel(2.0);
32  robot.setMaxCurv(1.0);
33  robot.setMaxDiffCurv(1.0);
35  EXPECT_TRUE(turn.getUsingCache());
36  turn.setUsingCache(false);
37  EXPECT_FALSE(turn.getUsingCache());
38  const double step = 0.1;
39  for (double ang = step; ang < boost::math::constants::pi<double>(); ang += step) {
40  F2CPoint start(0.0, 0.0), end(4.0, 0.0);
41  auto path = turn.createTurn(robot, start, ang,
42  end, ang + boost::math::constants::pi<double>());
43  EXPECT_TRUE(IsPathCorrect(path, start, ang,
44  end, ang + boost::math::constants::pi<double>()));
45  }
46 }
47 
48 
49 TEST(fields2cover_pp_dubins, cached_turn) {
51  robot.setCruiseVel(2.0);
52  robot.setMaxCurv(0.3);
53  robot.setMaxDiffCurv(1.0);
55  turn.setUsingCache(true);
56  EXPECT_TRUE(turn.getUsingCache());
57 
58  auto path1 = turn.createTurn(robot,
59  F2CPoint(-331.021, 418.463), 4.71239,
60  F2CPoint(-328.021, 404.284), 1.5708);
61  //auto path4 = turn.createTurnIfNotCached(14.4929, 0.208505, 3.35);
62  auto path2 = turn.createTurn(robot,
63  F2CPoint(-331.021, 418.463), 4.71239,
64  F2CPoint(-328.021, 404.284), 1.5708);
65  EXPECT_EQ(path1.size(), path2.size());
66  for (int i = 0; i < path1.size(); ++i) {
67  EXPECT_TRUE(path1[i].point == path2[i].point);
68  }
69 }
70 
71 TEST(fields2cover_pp_dubins, turn_valid) {
73  robot.setCruiseVel(2.0);
74  robot.setMaxCurv(0.3);
76  auto path3 = turn.createSimpleTurn(robot, 14.4929, 0.208505, 3.35);
77  path3.populate(100);
78  EXPECT_TRUE(turn.isTurnValid(path3, 14.4929, 3.35, 0.1, 0.1));
79 
80  path3[50].point.setY(-3);
81  EXPECT_FALSE(turn.isTurnValid(path3, 14.4929, 3.35, 0.1, 0.1));
82  path3.back().angle = 0;
83  EXPECT_FALSE(turn.isTurnValid(path3, 14.4929, 3.35, 0.1, 0.1));
84  path3.back().point.setY(3);
85  EXPECT_FALSE(turn.isTurnValid(path3, 14.4929, 3.35, 0.1, 0.1));
86  path3.back().point.setX(15);
87  EXPECT_FALSE(turn.isTurnValid(path3, 14.4929, 3.35, 0.1, 0.1));
88 }
89 
f2c::pp::DubinsCurves
Dubins' curves planner.
Definition: dubins_curves.h:17
types.h
2_objective_functions.path
path
Definition: 2_objective_functions.py:88
f2c::pp::TurningBase::getUsingCache
bool getUsingCache() const
Get if turns are being cached or not.
Definition: turning_base.cpp:122
1_basic_types.end
end
Definition: 1_basic_types.py:76
f2c::pp::DubinsCurves::createSimpleTurn
F2CPath createSimpleTurn(const F2CRobot &robot, double dist_start_pos, double start_angle, double end_angle) override
Create a turn.
Definition: dubins_curves.cpp:13
2_objective_functions.robot
robot
Definition: 2_objective_functions.py:76
f2c::types::Path::populate
Path & populate(int number_points=100)
Definition: Path.cpp:346
f2c::types::Point
Definition: Point.h:21
f2c::types::Robot
Definition: Robot.h:25
f2c::pp::TurningBase::setUsingCache
void setUsingCache(bool c)
Set if cache should be used when planning same turn as before.
Definition: turning_base.cpp:126
f2c::pp::TurningBase::isTurnValid
static bool isTurnValid(const F2CPath &path, double dist_start_end, double end_angle, double max_dist_error=0.05, double max_rot_error=0.1)
Check if turn is valid.
Definition: turning_base.cpp:100
dubins_curves.h
f2c::pp::TurningBase::createTurn
F2CPath createTurn(const F2CRobot &robot, const F2CPoint &start_pos, double start_angle, const F2CPoint &end_pos, double end_angle)
Create a turn that goes from one point with a certain angle to another point.
Definition: turning_base.cpp:30
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
TEST
TEST(fields2cover_pp_dubins, turn_dist)
Definition: dubins_test.cpp:14
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