complete_turn_path_obj_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 "fields2cover/types.h"
16 
17 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost) {
18  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
19  F2CSwath swath2(F2CLineString({F2CPoint(1.0, 1.0), F2CPoint(1.0, 0.0)}));
21  F2CSwaths swaths2 {swath2};
22 
23  F2CRobot robot(2.1);
24  robot.setMinTurningRadius(0.5);
25 
28  f2c::pp::DubinsCurvesCC dubinscc;
29  f2c::obj::CompleteTurnPathObj length2(robot, dubinscc);
32  f2c::pp::ReedsSheppCurvesHC reeds_shepphc;
33  f2c::obj::CompleteTurnPathObj length4(robot, reeds_shepphc);
34 
35  // Precision is quite low so this is just checking a prediction is done
36  EXPECT_NEAR(length1.computeCost(swath1, swath2), M_PI/2.0, 0.1);
37  EXPECT_NEAR(length2.computeCost(swath1, swath2),
38  dubinscc.createSimpleTurn(robot, 1, 0.5*M_PI, 1.5*M_PI).length(), 0.1);
39  EXPECT_NEAR(length3.computeCost(swath1, swath2), M_PI/2.0, 0.1);
40  EXPECT_NEAR(length4.computeCost(swath1, swath2),
41  reeds_shepphc.createSimpleTurn(robot, 1, 0.5*M_PI, 1.5*M_PI).length(), 0.1);
42 }
43 
44 
45 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost_2) {
46  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
47  F2CSwath swath2(F2CLineString({F2CPoint(1.0, 1.0), F2CPoint(1.0, 0.0)}));
49  F2CSwaths swaths2 {swath2};
50 
51  F2CRobot robot(2.1);
52  robot.setMinTurningRadius(0.5);
53 
56  length.setTurnPlanner(dubins);
57  EXPECT_NEAR(length.computeCost(
58  F2CPoint(0.0, 1.0), M_PI/2.0, F2CPoint(1.0, 1.0), -M_PI/2.0), M_PI/2.0, 0.1);
59 }
60 
61 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost_long_swath) {
62  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
63  F2CSwath swath2(F2CLineString({F2CPoint(100.0, 1.0), F2CPoint(100.0, 0.0)}));
65 
66  F2CRobot robot(2.1);
67  robot.setMinTurningRadius(0.5);
68 
71 
72  // Precision is quite low so this is just checking a prediction is done
73  EXPECT_NEAR(length.computeCost(swath1, swath2), 99 + 0.5 * M_PI, 0.01);
74  EXPECT_NEAR(length.computeCost(swaths), 101 + 0.5 * M_PI, 0.01);
75 }
76 
77 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost_dubinsCC) {
78  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
79  F2CSwath swath2(F2CLineString({F2CPoint(100.0, 1.0), F2CPoint(100.0, 0.0)}));
81 
82  F2CRobot robot(2.1);
83  robot.setMinTurningRadius(0.5);
84 
87 
88  EXPECT_NEAR(length.computeCost(swath1, swath2), 103 + 0.5 * M_PI, 0.4);
89  EXPECT_NEAR(length.computeCost(swaths), 105 + 0.5 * M_PI, 0.4);
90 }
91 
92 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost_reedsshepp) {
93  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
94  F2CSwath swath2(F2CLineString({F2CPoint(100.0, 1.0), F2CPoint(100.0, 0.0)}));
96  F2CRobot robot(2.1);
97  robot.setMinTurningRadius(0.5);
98 
101 
102  // Precision is quite low so this is just checking a prediction is done
103  EXPECT_NEAR(length.computeCost(swath1, swath2), 99 + 0.5 * M_PI, 0.01);
104  EXPECT_NEAR(length.computeCost(swaths), 101 + 0.5 * M_PI, 0.01);
105 }
106 
107 TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost_reedssheppHC) {
108  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)}));
109  F2CSwath swath2(F2CLineString({F2CPoint(100.0, 1.0), F2CPoint(100.0, 0.0)}));
111  F2CRobot robot(2.1);
112  robot.setMinTurningRadius(0.5);
113 
116 
117  EXPECT_NEAR(length.computeCost(swath1, swath2), 103 + 0.5 * M_PI, 0.3);
118  EXPECT_NEAR(length.computeCost(swaths), 105 + 0.5 * M_PI, 0.3);
119 }
120 
121 TEST(fields2cover_complete_pred_turn_path_obj, params_check) {
123 
124  EXPECT_FALSE(objective.isMaximizing());
125  EXPECT_TRUE(objective.isMinimizing());
126 }
127 
f2c::pp::DubinsCurves
Dubins' curves planner.
Definition: dubins_curves.h:17
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
dubins_curves_cc.h
reeds_shepp_curves.h
types.h
f2c::pp::DubinsCurvesCC::createSimpleTurn
F2CPath createSimpleTurn(const F2CRobot &robot, double dist_start_pos, double start_angle, double end_angle) override
Create a turn.
Definition: dubins_curves_cc.cpp:14
f2c::obj::CompleteTurnPathObj::setTurnPlanner
void setTurnPlanner(const T &turner)
Definition: complete_turn_path_obj.h:73
path_length.h
f2c::pp::DubinsCurvesCC
Dubins' curves planner with continuous curves.
Definition: dubins_curves_cc.h:17
f2c::types::Swath
Definition: Swath.h:23
complete_turn_path_obj.h
f2c::pp::ReedsSheppCurves
Reeds-Shepp's curves planner.
Definition: reeds_shepp_curves.h:17
2_objective_functions.swaths1
swaths1
Definition: 2_objective_functions.py:37
2_objective_functions.robot
robot
Definition: 2_objective_functions.py:76
f2c::pp::ReedsSheppCurvesHC
Reeds-Shepp's curves planner with continuous curves.
Definition: reeds_shepp_curves_hc.h:17
6_path_planning.dubins
dubins
Definition: 6_path_planning.py:30
TEST
TEST(fields2cover_obj_complete_turn_path_obj, computeCost_cost)
Definition: complete_turn_path_obj_test.cpp:17
2_objective_functions.swath1
swath1
Definition: 2_objective_functions.py:30
reeds_shepp_curves_hc.h
f2c::obj::BaseObjective< RPObjective >::isMaximizing
virtual bool isMaximizing() const
Return true if the objective is to maximize the cost function.
Definition: base_objective.h:52
visualizer.h
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::types::Point
Definition: Point.h:21
f2c::obj::CompleteTurnPathObj
Class to compute the cost of turning from one point to another.
Definition: complete_turn_path_obj.h:26
f2c::types::Robot
Definition: Robot.h:25
f2c::types::Path::length
double length(void) const
Definition: Path.cpp:205
f2c::pp::ReedsSheppCurvesHC::createSimpleTurn
F2CPath createSimpleTurn(const F2CRobot &robot, double dist_start_pos, double start_angle, double end_angle) override
Create a turn.
Definition: reeds_shepp_curves_hc.cpp:13
dubins_curves.h
f2c::obj::CompleteTurnPathObj::computeCost
double computeCost(const F2CPoint &p1, double ang1, const F2CPoint &p2, double ang2) override
Definition: complete_turn_path_obj.h:79
f2c::types::Swaths
Definition: Swaths.h:20
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
2_objective_functions.swath2
swath2
Definition: 2_objective_functions.py:32
6_path_planning.reeds_shepp
reeds_shepp
Definition: 6_path_planning.py:53
f2c::obj::BaseObjective< RPObjective >::isMinimizing
virtual bool isMinimizing() const
Return true if the objective is to minimize the cost function.
Definition: base_objective.h:50


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