-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.py
208 lines (176 loc) · 12 KB
/
Factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from Formation import *
from FormationNote import *
from Formation3D import *
class Factory:
@staticmethod
def factoryFormation(inputString, num_robots, side=0, velX=0, velY=0, free_formation_saves=None, last_free_formation_name=None ):
# Displacement
if inputString == SquareFormationDisplacementSingleIntegrator:
return SquareFormationDisplacementSingleIntegrator(side)
elif inputString == SquareFormationDisplacementDoubleIntegrator:
return SquareFormationDisplacementDoubleIntegrator(side, desVelX=velX, desVelY=velY)
elif inputString == SquareFormationDisplacementUnicycle:
return SquareFormationDisplacementUnicycle(side)
elif inputString == LinearHorizontalFormationDisplacementSingleIntegrator:
return LinearHorizontalFormationDisplacementSingleIntegrator(side, num_robots)
elif inputString == LinearHorizontalFormationDisplacementDoubleIntegrator:
return LinearHorizontalFormationDisplacementDoubleIntegrator(side, num_robots, desVelX=velX, desVelY=velY)
elif inputString == LinearHorizontalFormationDisplacementUnicycle:
return LinearHorizontalFormationDisplacementUnicycle(side, num_robots)
elif inputString == FreeFormationDisplacementSingleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDisplacementSingleIntegrator(points, lines)
elif inputString == FreeFormationDisplacementDoubleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDisplacementDoubleIntegrator(points, lines, desVelX=velX, desVelY=velY)
elif inputString == FreeFormationDisplacementUnicycle:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDisplacementUnicycle(points, lines)
# Distance
elif inputString == SquareFormationDistanceSingleIntegrator:
return SquareFormationDistanceSingleIntegrator(side)
elif inputString == SquareFormationDistanceDoubleIntegrator:
return SquareFormationDistanceDoubleIntegrator(side)
elif inputString == SquareFormationDistanceUnicycle:
return SquareFormationDistanceUnicycle(side)
elif inputString == LinearHorizontalFormationDistanceSingleIntegrator:
return LinearHorizontalFormationDistanceSingleIntegrator(side, num_robots)
elif inputString == LinearHorizontalFormationDistanceDoubleIntegrator:
return LinearHorizontalFormationDistanceDoubleIntegrator(side, num_robots)
elif inputString == LinearHorizontalFormationDistanceUnicycle:
return LinearHorizontalFormationDistanceUnicycle(side, num_robots)
elif inputString == FreeFormationDistanceSingleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDistanceSingleIntegrator(points, lines)
elif inputString == FreeFormationDistanceDoubleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDistanceDoubleIntegrator(points, lines)
elif inputString == FreeFormationDistanceUnicycle:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDistanceUnicycle(points, lines)
else:
raise NotImplementedError
@staticmethod
def factoryFormation3D(inputString, num_robots, side=0, velX=0, velY=0, velZ=0,free_formation_saves=None, last_free_formation_name=None ):
# Displacement
if inputString == SquareFormationDisplacementSingleIntegrator:
return SquareFormationDisplacementSingleIntegrator3D(side)
elif inputString == SquareFormationDisplacementDoubleIntegrator:
return SquareFormationDisplacementDoubleIntegrator3D(side, desVelX=velX, desVelY=velY, desVelZ=velZ)
elif inputString == LinearHorizontalFormationDisplacementSingleIntegrator:
return LinearHorizontalFormationDisplacementSingleIntegrator3D(side, num_robots)
elif inputString == LinearHorizontalFormationDisplacementDoubleIntegrator:
return LinearHorizontalFormationDisplacementDoubleIntegrator3D(side, num_robots, desVelX=velX, desVelY=velY, desVelZ=velZ)
elif inputString == FreeFormationDisplacementSingleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDisplacementSingleIntegrator3D(points, lines)
elif inputString == FreeFormationDisplacementDoubleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDisplacementDoubleIntegrator3D(points, lines, desVelX=velX, desVelY=velY, desVelZ=velZ)
elif inputString == CubeFormationDisplacementSingleIntegrator3D:
return CubeFormationDisplacementSingleIntegrator3D(side)
elif inputString == CubeFormationDisplacementDoubleIntegrator3D:
return CubeFormationDisplacementDoubleIntegrator3D(side)
# Distance
elif inputString == SquareFormationDistanceSingleIntegrator:
return SquareFormationDistanceSingleIntegrator3D(side)
elif inputString == SquareFormationDistanceDoubleIntegrator:
return SquareFormationDistanceDoubleIntegrator3D(side)
elif inputString == LinearHorizontalFormationDistanceSingleIntegrator:
return LinearHorizontalFormationDistanceSingleIntegrator3D(side, num_robots)
elif inputString == LinearHorizontalFormationDistanceDoubleIntegrator:
return LinearHorizontalFormationDistanceDoubleIntegrator3D(side, num_robots)
elif inputString == CubeFormationDistanceSingleIntegrator3D:
return CubeFormationDistanceSingleIntegrator3D(side)
elif inputString == CubeFormationDistanceDoubleIntegrator3D:
return CubeFormationDistanceDoubleIntegrator3D(side)
elif inputString == FreeFormationDistanceSingleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDistanceSingleIntegrator3D(points, lines)
elif inputString == FreeFormationDistanceDoubleIntegrator:
points = free_formation_saves[last_free_formation_name]["points"] # free formation parameter
lines = free_formation_saves[last_free_formation_name]["lines"] # free formation parameter
return FreeFormationDistanceDoubleIntegrator3D(points, lines)
else:
raise NotImplementedError
def make_formation_from_robot_and_note(formation_note, robot_type, lato, num_robots, free_formation_saves=None, last_free_formation_name=None, vel_x=0, vel_y=0):
formation_type = make_formation_type(formation_note, robot_type)
formation = Factory.factoryFormation(inputString=formation_type, side=lato, num_robots=num_robots,
free_formation_saves=free_formation_saves,
last_free_formation_name=last_free_formation_name, velX=vel_x, velY=vel_y)
return formation
def make_formation_from_robot_and_note_3D(formation_note, robot_type, lato, num_robots, free_formation_saves=None, last_free_formation_name=None, vel_x=0, vel_y=0, vel_z=0):
formation_type = make_formation_type(formation_note, robot_type)
formation = Factory.factoryFormation3D(inputString=formation_type, side=lato, num_robots=num_robots,
free_formation_saves=free_formation_saves,
last_free_formation_name=last_free_formation_name, velX=vel_x, velY=vel_y, velZ=vel_z)
return formation
def make_formation_type(formation_note, robot_type):
formation_type = None
if formation_note == LinearNote:
formation_type = make_formation_from_robot_linear(robot_type)
elif formation_note == SquareNote:
formation_type = make_formation_from_robot_square(robot_type)
elif formation_note == FreeNote:
formation_type = make_formation_from_robot_free(robot_type)
elif formation_note == CubeNote:
formation_type = make_formation_from_robot_cube(robot_type)
return formation_type
def make_formation_from_robot_linear(robot_type):
if robot_type == RobotDisplacementSingleIntegrator:
return LinearHorizontalFormationDisplacementSingleIntegrator
elif robot_type == RobotDisplacementDoubleIntegrator:
return LinearHorizontalFormationDisplacementDoubleIntegrator
elif robot_type == RobotDisplacementUnicycle:
return LinearHorizontalFormationDisplacementUnicycle
elif robot_type == RobotDistanceSingleIntegrator:
return LinearHorizontalFormationDistanceSingleIntegrator
elif robot_type == RobotDistanceDoubleIntegrator:
return LinearHorizontalFormationDistanceDoubleIntegrator
elif robot_type == RobotDistanceUnicycle:
return LinearHorizontalFormationDistanceUnicycle
def make_formation_from_robot_square(robot_type):
if robot_type == RobotDisplacementSingleIntegrator:
a = SquareFormationDisplacementSingleIntegrator(4)
return SquareFormationDisplacementSingleIntegrator
elif robot_type == RobotDisplacementDoubleIntegrator:
return SquareFormationDisplacementDoubleIntegrator
elif robot_type == RobotDisplacementUnicycle:
return SquareFormationDisplacementUnicycle
elif robot_type == RobotDistanceSingleIntegrator:
return SquareFormationDistanceSingleIntegrator
elif robot_type == RobotDistanceDoubleIntegrator:
return SquareFormationDistanceDoubleIntegrator
elif robot_type == RobotDistanceUnicycle:
return SquareFormationDistanceUnicycle
def make_formation_from_robot_free(robot_type):
if robot_type == RobotDisplacementSingleIntegrator:
return FreeFormationDisplacementSingleIntegrator
elif robot_type == RobotDisplacementDoubleIntegrator:
return FreeFormationDisplacementDoubleIntegrator
elif robot_type == RobotDisplacementUnicycle:
return FreeFormationDisplacementUnicycle
elif robot_type == RobotDistanceSingleIntegrator:
return FreeFormationDistanceSingleIntegrator
elif robot_type == RobotDistanceDoubleIntegrator:
return FreeFormationDistanceDoubleIntegrator
elif robot_type == RobotDistanceUnicycle:
return FreeFormationDistanceUnicycle
def make_formation_from_robot_cube(robot_type):
if robot_type == RobotDisplacementSingleIntegrator:
return CubeFormationDisplacementSingleIntegrator3D
elif robot_type == RobotDisplacementDoubleIntegrator:
return CubeFormationDisplacementDoubleIntegrator3D
elif robot_type == RobotDistanceSingleIntegrator:
return CubeFormationDistanceSingleIntegrator3D
elif robot_type == RobotDistanceDoubleIntegrator:
return CubeFormationDistanceDoubleIntegrator3D