9 import fields2cover
as f2c
11 def near(a, b, error = 1e-7):
12 assert abs(a - b) < error
15 line1 = f2c.LineString(f2c.VectorPoint(
16 [f2c.Point(0.0, 1.0), f2c.Point(1.0, 1.0), f2c.Point(1.0, 4.0)]));
17 swath1 = f2c.Swath(line1);
19 path1.appendSwath(swath1, 2.0);
20 near(path1.getState(0).point.getX(), 0.0);
21 near(path1.getState(0).point.getY(), 1.0);
22 near(path1.getState(0).velocity, 2.0);
23 near(path1.getState(0).len, 1.0);
24 near(path1.getState(0).type, f2c.PathSectionType_SWATH);
25 near(path1.getState(1).point.getX(), 1.0);
26 near(path1.getState(1).point.getY(), 1.0);
27 near(path1.getState(1).velocity, 2.0);
28 near(path1.getState(1).len, 3.0);
29 near(path1.getState(1).type, f2c.PathSectionType_SWATH);
30 near(path1.getTaskTime(), 2.0);
33 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint([f2c.Point(0.0, 1.0), f2c.Point(1.0, 1.0), f2c.Point(1.0, 4.0)])));
34 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint([f2c.Point(1.0, 4.0), f2c.Point(1.0, 0.0), f2c.Point(0.0, 0.0)])));
38 path1.appendSwath(swath1, 2.0);
39 path2.appendSwath(swath2, 1.0);
41 near(path1.getState(0).point.getX(), 0.0);
42 near(path1.getState(0).point.getY(), 1.0);
43 near(path1.getState(0).velocity, 2.0);
44 near(path1.getState(0).len, 1.0);
45 near(path1.getState(0).type, f2c.PathSectionType_SWATH);
46 near(path1.getState(1).point.getX(), 1.0);
47 near(path1.getState(1).point.getY(), 1.0);
48 near(path1.getState(1).velocity, 2.0);
49 near(path1.getState(1).len, 3.0);
50 near(path1.getState(1).type, f2c.PathSectionType_SWATH);
51 near(path1.getState(2).point.getX(), 1.0);
52 near(path1.getState(2).point.getY(), 4.0);
53 near(path1.getState(2).velocity, 1.0);
54 near(path1.getState(2).len, 4.0);
55 near(path1.getState(2).type, f2c.PathSectionType_SWATH);
56 near(path1.getState(3).point.getX(), 1.0);
57 near(path1.getState(3).point.getY(), 0.0);
58 near(path1.getState(3).velocity, 1.0);
59 near(path1.getState(3).len, 1.0);
60 near(path1.getState(3).type, f2c.PathSectionType_SWATH);
61 near(path1.getTaskTime(), 7.0);
62 near(path1.size(), 4);
68 near(path1.size(), 0);
69 near(path1.getTaskTime(), 0.0, 1e-6);
71 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
72 [f2c.Point(0.0, 0.0), f2c.Point(0.0, 1.0), f2c.Point(2.0, 1.0)])));
73 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
74 [f2c.Point(3.0, 1.0), f2c.Point(3.0, 4.0), f2c.Point(1.0, 4.0)])));
76 path1.appendSwath(swath1, 2.0);
77 path2.appendSwath(swath2, 1.0);
80 near(path1.length(), 8);
81 near(path1.getTaskTime(), 6.5, 1e-6);
82 for s
in path1.getStates():
83 near(s.dir, f2c.PathDirection_FORWARD);
87 assert (path1.length() > 8.0);
88 assert (path1.length() < 2.0 * 8.0);
89 near(path1.size(), 200);
90 near(path1.getTaskTime(), 6.5, 1e-6);
91 for s
in path1.getStates():
92 near(s.dir, f2c.PathDirection_FORWARD);
93 near(s.type, f2c.PathSectionType_SWATH);
95 assert (path1.length() > 8.0);
96 assert (path1.length() < 2.0 * 8.0);
97 near(path1.size(), 10);
98 near(path1.getTaskTime(), 6.5, 0.1);
99 for s
in path1.getStates():
100 near(s.dir, f2c.PathDirection_FORWARD);
101 near(s.type, f2c.PathSectionType_SWATH);
103 assert (path1.length() > 8.0);
104 assert (path1.length() < 2.0 * 8.0);
106 assert (path1.length() > 8.0);
107 assert (path1.length() < 2.0 * 8.0);
109 assert (path1.length() > 8.0);
110 assert (path1.length() < 2.0 * 8.0);
111 assert (path1.size() < 100);
113 for s
in path1.getStates():
114 near(s.dir, f2c.PathDirection_FORWARD);
115 near(s.type, f2c.PathSectionType_SWATH);
118 line1 = f2c.LineString();
119 line2 = f2c.LineString();
120 line1.addPoint( 0.0, 1.0);
121 line1.addPoint( 1.0, 1.0);
122 line1.addPoint( 1.0, 4.0);
123 line2.addPoint( 1.0, 4.0);
124 line2.addPoint( 1.0, 0.0);
125 line2.addPoint( 0.0, 0.0);
126 swath1 = f2c.Swath(line1);
127 swath2 = f2c.Swath(line2);
131 path1.appendSwath(swath1, 2.0);
132 near(path1.length(), 4.0);
133 path2.appendSwath(swath2, 1.0);
135 near(path1.length(), 9.0);
137 near(path1.length(), 5.0);
142 state = f2c.PathState();
143 state.point = f2c.Point(3.124, -4.5, 3);
145 state.velocity = -2.5;
147 state.dir = f2c.PathDirection_FORWARD;
148 state.type = f2c.PathSectionType_SWATH;
149 path.addState(state);
151 state = f2c.PathState();
152 state.point = f2c.Point(-2.3, 5);
154 state.velocity = 4.5;
156 state.dir = f2c.PathDirection_BACKWARD;
157 state.type = f2c.PathSectionType_SWATH;
158 path.addState(state);
160 assert (path.serializePath() ==
"3.124 -4.5 3 -0.5 -2.5 2 1 1\n-2.3 5 0 0.1 4.5 6 -1 1\n");
161 path.saveToFile(
"/tmp/test_path");
162 path_read = f2c.Path();
163 path_read.loadFile(
"/tmp/test_path");
164 assert (path.serializePath() == path_read.serializePath());
168 robot = f2c.Robot(2.0, 6.0)
169 const_hl = f2c.HG_Const_gen()
170 field = rand.generateRandField(1e5, 5)
171 cells = field.getField()
172 no_hl = const_hl.generateHeadlands(cells, 3.0 * robot.getCovWidth())
173 bf = f2c.SG_BruteForce()
174 swaths = bf.generateSwaths(math.pi, robot.getCovWidth(), no_hl.getGeometry(0))
175 snake_sorter = f2c.RP_Snake()
176 swaths = snake_sorter.genSortedSwaths(swaths)
178 robot.setMinTurningRadius(2)
179 robot.setMaxDiffCurv(0.1)
180 path_planner = f2c.PP_PathPlanning()
181 dubins = f2c.PP_DubinsCurvesCC()
182 path = path_planner.planPath(robot, swaths, dubins);
185 points = [path[i].point
for i
in range(n)]