5_route_planning.py
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 import math
9 import fields2cover as f2c
10 
11 print("####### Tutorial 5.1 Route planning for all swaths ######");
12 
13 robot_c = f2c.Robot(1.0);
14 cells_c = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
15  f2c.Point(0,0), f2c.Point(60,0),f2c.Point(60,60),f2c.Point(0,60), f2c.Point(0,0)]))));
16 cells_c.addRing(0, f2c.LinearRing(f2c.VectorPoint([
17  f2c.Point(12,12), f2c.Point(12,18),f2c.Point(18,18),f2c.Point(18,12), f2c.Point(12,12)])));
18 cells_c.addRing(0, f2c.LinearRing(f2c.VectorPoint([
19  f2c.Point(36,36), f2c.Point(36,48),f2c.Point(48,48),f2c.Point(48,36), f2c.Point(36, 36)])));
20 
21 const_hl = f2c.HG_Const_gen();
22 mid_hl_c = const_hl.generateHeadlands(cells_c, 1.5 * robot_c.getWidth());
23 no_hl_c = const_hl.generateHeadlands(cells_c, 3.0 * robot_c.getWidth());
24 
25 bf = f2c.SG_BruteForce();
26 swaths_c = bf.generateSwaths(math.pi/2.0, robot_c.getCovWidth(), no_hl_c);
27 
28 route_planner = f2c.RP_RoutePlannerBase();
29 route = route_planner.genRoute(mid_hl_c, swaths_c);
30 
32 f2c.Visualizer.plot(cells_c);
33 f2c.Visualizer.plot(no_hl_c);
34 f2c.Visualizer.xlim(-5,65);
35 f2c.Visualizer.ylim(-5,65);
36 f2c.Visualizer.save("Tutorial_5_0_field.png");
37 
39 f2c.Visualizer.plot(cells_c);
40 f2c.Visualizer.plot(no_hl_c);
41 f2c.Visualizer.plot(route);
42 f2c.Visualizer.xlim(-5,65);
43 f2c.Visualizer.ylim(-5,65);
44 f2c.Visualizer.save("Tutorial_5_0_route.png");
45 
46 
47 print("####### Tutorial 5.2 Known Patterns ######");
48 
49 
50 
51 rand = f2c.Random(42);
52 robot = f2c.Robot(2.0, 6.0);
53 field = rand.generateRandField(1e4, 5);
54 cells = field.getField();
55 const_hl = f2c.HG_Const_gen();
56 no_hl = const_hl.generateHeadlands(cells, 3.0 * robot.getWidth());
57 bf = f2c.SG_BruteForce();
58 swaths = bf.generateSwaths(math.pi, robot.getCovWidth(), no_hl.getGeometry(0));
59 
60 print("####### Tutorial 5.2.1 Boustrophedon ######");
61 boustrophedon_sorter = f2c.RP_Boustrophedon();
62 swaths = boustrophedon_sorter.genSortedSwaths(swaths);
63 
65 f2c.Visualizer.plot(cells);
66 f2c.Visualizer.plot(no_hl);
67 f2c.Visualizer.plot(swaths);
68 f2c.Visualizer.save("Tutorial_5_1_Boustrophedon_1.png");
69 
70 
71 for i in range(1, 4):
73  f2c.Visualizer.plot(cells);
74  f2c.Visualizer.plot(no_hl);
75  f2c.Visualizer.plot(boustrophedon_sorter.genSortedSwaths(swaths, i));
76  f2c.Visualizer.save("Tutorial_5_1_Boustrophedon_" + str(i+1) + ".png");
77 
78 
79 
80 print("####### Tutorial 5.2.2 Snake order ######");
81 snake_sorter = f2c.RP_Snake();
82 swaths = snake_sorter.genSortedSwaths(swaths);
83 
85 f2c.Visualizer.plot(cells);
86 f2c.Visualizer.plot(no_hl);
87 f2c.Visualizer.plot(swaths);
88 f2c.Visualizer.save("Tutorial_5_2_Snake_1.png");
89 
90 for i in range(1, 4):
92  f2c.Visualizer.plot(cells);
93  f2c.Visualizer.plot(no_hl);
94  f2c.Visualizer.plot(snake_sorter.genSortedSwaths(swaths, i));
95  f2c.Visualizer.save("Tutorial_5_2_Snake_" + str(i+1) + ".png");
96 
97 swaths = bf.generateSwaths(math.pi, robot.getCovWidth(), no_hl.getGeometry(0));
98 print("####### Tutorial 5.2.3 Spiral order ######");
99 spiral_sorter = f2c.RP_Spiral(6);
100 swaths = spiral_sorter.genSortedSwaths(swaths);
101 
103 f2c.Visualizer.plot(cells);
104 f2c.Visualizer.plot(no_hl);
105 f2c.Visualizer.plot(swaths);
106 f2c.Visualizer.save("Tutorial_5_3_Spiral_1.png");
107 
108 for i in range(1, 4):
110  f2c.Visualizer.plot(cells);
111  f2c.Visualizer.plot(no_hl);
112  f2c.Visualizer.plot(spiral_sorter.genSortedSwaths(swaths, i));
113  f2c.Visualizer.save("Tutorial_5_3_Spiral_" + str(i+1) + ".png");
114 
115 
f2c::Visualizer::plot
static void plot(double x, double y, const std::vector< double > &color={})
Definition: visualizer.cpp:23
f2c::Visualizer::xlim
static void xlim(double min, double max)
Definition: visualizer.cpp:280
f2c::Random
Definition: random.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::Visualizer::ylim
static void ylim(double min, double max)
Definition: visualizer.cpp:284


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