tutorials
5_route_planning.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
8
#include "
fields2cover.h
"
9
#include <iostream>
10
11
int
main
() {
12
13
std::cout <<
"####### Tutorial 5.1 Route planning for all swaths ######"
<< std::endl;
14
15
F2CRobot
robot_c
(1.0);
16
F2CCells
cells_c
{
17
F2CCell
(
F2CLinearRing
({
18
F2CPoint
(0,0),
F2CPoint
(2,0),
F2CPoint
(2,2),
F2CPoint
(0,2),
F2CPoint
(0,0)
19
}))
20
};
21
cells_c
.addRing(0,
F2CLinearRing
({
22
F2CPoint
(.4,.4),
F2CPoint
(.4,.6),
F2CPoint
(.6,.6),
F2CPoint
(.6,.4),
F2CPoint
(.4,.4)
23
}));
24
cells_c
.addRing(0,
F2CLinearRing
({
25
F2CPoint
(1.2,1.2),
F2CPoint
(1.2,1.6),
F2CPoint
(1.6,1.6),
F2CPoint
(1.6,1.2),
F2CPoint
(1.2, 1.2)
26
}));
27
cells_c
*= 3e1;
28
29
f2c::hg::ConstHL
const_hl
;
30
F2CCells
mid_hl_c
=
const_hl
.generateHeadlands(
cells_c
, 1.5 *
robot_c
.getWidth());
31
F2CCells
no_hl_c
=
const_hl
.generateHeadlands(
cells_c
, 3.0 *
robot_c
.getWidth());
32
33
f2c::sg::BruteForce
bf
;
34
F2CSwathsByCells
swaths_c
=
bf
.generateSwaths(M_PI/2.0,
robot_c
.getCovWidth(),
no_hl_c
);
35
36
f2c::rp::RoutePlannerBase
route_planner
;
37
F2CRoute
route
=
route_planner
.genRoute(
mid_hl_c
,
swaths_c
);
38
39
f2c::Visualizer::figure
();
40
f2c::Visualizer::plot
(
cells_c
);
41
f2c::Visualizer::plot
(
no_hl_c
);
42
f2c::Visualizer::xlim
(-5,65);
43
f2c::Visualizer::ylim
(-5,65);
44
f2c::Visualizer::save
(
"Tutorial_5_0_field.png"
);
45
46
f2c::Visualizer::figure
();
47
f2c::Visualizer::plot
(
cells_c
);
48
f2c::Visualizer::plot
(
no_hl_c
);
49
f2c::Visualizer::plot
(
route
);
50
f2c::Visualizer::xlim
(-5,65);
51
f2c::Visualizer::ylim
(-5,65);
52
f2c::Visualizer::save
(
"Tutorial_5_0_route.png"
);
53
54
55
56
57
std::cout <<
"####### Tutorial 5.2 Known Patterns ######"
<< std::endl;
58
59
60
f2c::Random
rand
(42);
61
F2CRobot
robot
(2.0, 6.0);
62
F2CCells
cells
=
rand
.generateRandField(1e4, 5).getField();
63
F2CCells
no_hl
=
const_hl
.generateHeadlands(
cells
, 3.0 *
robot
.getWidth());
64
F2CSwaths
swaths
=
bf
.generateSwaths(M_PI,
robot
.getCovWidth(),
no_hl
.getGeometry(0));
65
66
std::cout <<
"####### Tutorial 5.2.1 Boustrophedon ######"
<< std::endl;
67
f2c::rp::BoustrophedonOrder
boustrophedon_sorter
;
68
auto
boustrophedon_swaths =
boustrophedon_sorter
.genSortedSwaths(
swaths
);
69
70
f2c::Visualizer::figure
();
71
f2c::Visualizer::plot
(
cells
);
72
f2c::Visualizer::plot
(
no_hl
);
73
f2c::Visualizer::plot
(boustrophedon_swaths);
74
f2c::Visualizer::save
(
"Tutorial_5_1_Boustrophedon_1.png"
);
75
76
77
for
(
int
i = 1; i < 4; ++i) {
78
f2c::Visualizer::figure
();
79
f2c::Visualizer::plot
(
cells
);
80
f2c::Visualizer::plot
(
no_hl
);
81
f2c::Visualizer::plot
(
boustrophedon_sorter
.genSortedSwaths(
swaths
, i));
82
f2c::Visualizer::save
(
"Tutorial_5_1_Boustrophedon_"
+
std::to_string
(i+1) +
".png"
);
83
}
84
85
86
std::cout <<
"####### Tutorial 5.2.2 Snake order ######"
<< std::endl;
87
f2c::rp::SnakeOrder
snake_sorter
;
88
auto
snake_swaths =
snake_sorter
.genSortedSwaths(
swaths
);
89
90
f2c::Visualizer::figure
();
91
f2c::Visualizer::plot
(
cells
);
92
f2c::Visualizer::plot
(
no_hl
);
93
f2c::Visualizer::plot
(snake_swaths);
94
f2c::Visualizer::save
(
"Tutorial_5_2_Snake_1.png"
);
95
96
for
(
int
i = 1; i < 4; ++i) {
97
f2c::Visualizer::figure
();
98
f2c::Visualizer::plot
(
cells
);
99
f2c::Visualizer::plot
(
no_hl
);
100
f2c::Visualizer::plot
(
snake_sorter
.genSortedSwaths(
swaths
, i));
101
f2c::Visualizer::save
(
"Tutorial_5_2_Snake_"
+
std::to_string
(i+1) +
".png"
);
102
}
103
104
swaths
=
bf
.generateSwaths(M_PI,
robot
.getCovWidth(),
no_hl
.getGeometry(0));
105
std::cout <<
"####### Tutorial 5.2.3 Spiral order ######"
<< std::endl;
106
f2c::rp::SpiralOrder
spiral_sorter
(6);
107
auto
spiral_swaths =
spiral_sorter
.genSortedSwaths(
swaths
);
108
109
f2c::Visualizer::figure
();
110
f2c::Visualizer::plot
(
cells
);
111
f2c::Visualizer::plot
(
no_hl
);
112
f2c::Visualizer::plot
(spiral_swaths);
113
f2c::Visualizer::save
(
"Tutorial_5_3_Spiral_1.png"
);
114
115
for
(
int
i = 1; i < 4; ++i) {
116
f2c::Visualizer::figure
();
117
f2c::Visualizer::plot
(
cells
);
118
f2c::Visualizer::plot
(
no_hl
);
119
f2c::Visualizer::plot
(
spiral_sorter
.genSortedSwaths(
swaths
, i));
120
f2c::Visualizer::save
(
"Tutorial_5_3_Spiral_"
+
std::to_string
(i+1) +
".png"
);
121
}
122
123
return
0;
124
}
125
f2c::hg::ConstHL
Class to generate headlands with equal width in each border.
Definition:
constant_headland.h:18
5_route_planning.swaths
swaths
Definition:
5_route_planning.py:58
f2c::rp::SnakeOrder
Definition:
snake_order.h:16
1_basic_types.cells
cells
Definition:
1_basic_types.py:93
5_route_planning.cells_c
cells_c
Definition:
5_route_planning.py:14
f2c::Visualizer::plot
static void plot(double x, double y, const std::vector< double > &color={})
Definition:
visualizer.cpp:23
F2CCell
f2c::types::Cell F2CCell
Definition:
types.h:43
3_headland_generator.rand
rand
Definition:
3_headland_generator.py:11
5_route_planning.robot_c
robot_c
Definition:
5_route_planning.py:13
f2c::Visualizer::xlim
static void xlim(double min, double max)
Definition:
visualizer.cpp:280
2_objective_functions.robot
robot
Definition:
2_objective_functions.py:76
fields2cover.h
5_route_planning.route
route
Definition:
5_route_planning.py:29
3_headland_generator.const_hl
const_hl
Definition:
3_headland_generator.py:17
5_route_planning.route_planner
route_planner
Definition:
5_route_planning.py:28
5_route_planning.mid_hl_c
mid_hl_c
Definition:
5_route_planning.py:22
5_route_planning.boustrophedon_sorter
boustrophedon_sorter
Definition:
5_route_planning.py:61
f2c::rp::BoustrophedonOrder
Definition:
boustrophedon_order.h:16
F2CLinearRing
f2c::types::LinearRing F2CLinearRing
Definition:
types.h:41
f2c::types::Cells
Definition:
Cells.h:21
f2c::types::Route
Definition:
Route.h:23
5_route_planning.swaths_c
swaths_c
Definition:
5_route_planning.py:26
5_route_planning.snake_sorter
snake_sorter
Definition:
5_route_planning.py:81
f2c::types::Robot
Definition:
Robot.h:25
f2c::Random
Definition:
random.h:23
3_headland_generator.no_hl
no_hl
Definition:
3_headland_generator.py:18
f2c::types::SwathsByCells
Definition:
SwathsByCells.h:17
f2c::rp::SpiralOrder
Definition:
spiral_order.h:10
5_route_planning.spiral_sorter
spiral_sorter
Definition:
5_route_planning.py:99
5_route_planning.no_hl_c
no_hl_c
Definition:
5_route_planning.py:23
f2c::rp::RoutePlannerBase
Definition:
route_planner_base.h:23
f2c::Visualizer::figure
static void figure()
Create figure to plot on.
Definition:
visualizer.cpp:254
f2c::Visualizer::save
static void save(const std::string &file)
Definition:
visualizer.cpp:272
f2c::types::Swaths
Definition:
Swaths.h:20
f2c::Visualizer::ylim
static void ylim(double min, double max)
Definition:
visualizer.cpp:284
F2CPoint
f2c::types::Point F2CPoint
Definition:
types.h:38
5_route_planning.bf
bf
Definition:
5_route_planning.py:25
f2c::sg::BruteForce
Definition:
brute_force.h:20
main
int main()
Definition:
5_route_planning.cpp:11
f2c::types::to_string
std::string to_string(double d, const int precision=6)
Definition:
Path.cpp:274
fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31