質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,11 +80,11 @@
|
|
80
80
|
|
81
81
|
print("進みます")
|
82
82
|
|
83
|
-
#ポテンシャル法により経路を連続描写により書いている
|
83
|
+
#ポテンシャル法により経路を連続描写により書いている
|
84
|
-
|
84
|
+
|
85
|
-
# <10になるまで点をループで描写
|
85
|
+
# <10になるまで点をループで描写
|
86
|
-
|
86
|
+
|
87
|
-
while Position.calculate_distance(agent.position, goal.position) > 10:
|
87
|
+
while Position.calculate_distance(agent.position, goal.position) > 10:
|
88
88
|
|
89
89
|
possible_moves = agent.get_possible_moves()
|
90
90
|
|
@@ -296,6 +296,10 @@
|
|
296
296
|
|
297
297
|
cv2.destroyAllWindows()
|
298
298
|
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
299
303
|
|
300
304
|
|
301
305
|
def main():
|
1
追加で編集しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,20 @@
|
|
18
18
|
|
19
19
|
```python3.8
|
20
20
|
|
21
|
+
class Potential:
|
22
|
+
|
23
|
+
def __init__(self):
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
#初期スピード設定
|
28
|
+
|
29
|
+
self.speed = 100
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
21
35
|
def potential(self):
|
22
36
|
|
23
37
|
# Defining world dimensions
|
@@ -110,50 +124,200 @@
|
|
110
124
|
|
111
125
|
cv2.imshow('Output', image)
|
112
126
|
|
113
|
-
|
127
|
+
key = cv2.waitKey(self.speed)
|
128
|
+
|
129
|
+
#print(self.speed)
|
130
|
+
|
131
|
+
if key & 0xFF == ord('s'):
|
132
|
+
|
133
|
+
self.speed -= 100
|
134
|
+
|
135
|
+
if self.speed <= 0:
|
136
|
+
|
137
|
+
self.speed += 100
|
138
|
+
|
139
|
+
print("これ以上速くなりません")
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
if key & 0xFF == ord('d'):
|
144
|
+
|
145
|
+
self.speed += 100
|
146
|
+
|
147
|
+
if self.speed >= 2100:
|
148
|
+
|
149
|
+
self.speed -= 100
|
150
|
+
|
151
|
+
print("これ以上遅くなりません")
|
152
|
+
|
153
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
154
|
+
|
155
|
+
navi += 1
|
156
|
+
|
157
|
+
if navi == 1:
|
158
|
+
|
159
|
+
print("右に曲がります")
|
160
|
+
|
161
|
+
print("進みます")
|
162
|
+
|
163
|
+
goal = Goal(Position(40,180), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if navi == 2:
|
170
|
+
|
171
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
172
|
+
|
173
|
+
print("左に曲がります")
|
174
|
+
|
175
|
+
print("進みます")
|
176
|
+
|
177
|
+
goal = Goal(Position(40,620), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
if navi ==3:
|
184
|
+
|
185
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
186
|
+
|
187
|
+
print("左に曲がります")
|
188
|
+
|
189
|
+
print("進みます")
|
190
|
+
|
191
|
+
goal = Goal(Position(320,620), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
if navi ==4:
|
198
|
+
|
199
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
200
|
+
|
201
|
+
print("斜め右に曲がります")
|
202
|
+
|
203
|
+
print("進みます")
|
204
|
+
|
205
|
+
goal = Goal(Position(370,680), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
if navi ==5:
|
212
|
+
|
213
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
214
|
+
|
215
|
+
print("左に曲がります")
|
216
|
+
|
217
|
+
print("進みます")
|
218
|
+
|
219
|
+
goal = Goal(Position(490,680), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
if navi ==6:
|
226
|
+
|
227
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
228
|
+
|
229
|
+
print("左に曲がります")
|
230
|
+
|
231
|
+
print("進みます")
|
232
|
+
|
233
|
+
goal = Goal(Position(490,580), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
if navi == 7:
|
240
|
+
|
241
|
+
if Position.calculate_distance(agent.position, goal.position)<10:
|
242
|
+
|
243
|
+
print("到着しました")
|
244
|
+
|
245
|
+
cv2.waitKey(0)
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
if key & 0xFF == ord('q'):
|
252
|
+
|
253
|
+
sys.exit()
|
254
|
+
|
255
|
+
# Hold on last frame
|
256
|
+
|
257
|
+
cv2.waitKey(0)
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
def video(self):
|
262
|
+
|
263
|
+
cap = cv2.VideoCapture('experiment.mp4')
|
264
|
+
|
265
|
+
if (cap.isOpened()== False):
|
266
|
+
|
267
|
+
print("ビデオファイルを開くとエラーが発生しました")
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
while(cap.isOpened()):
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
ret, frame = cap.read()
|
276
|
+
|
277
|
+
if ret == True:
|
278
|
+
|
279
|
+
cv2.imshow("Video",frame)
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if cv2.waitKey(25) & 0xFF == ord('q'):
|
284
|
+
|
285
|
+
break
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
else:
|
290
|
+
|
291
|
+
break
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
cap.release()
|
296
|
+
|
297
|
+
cv2.destroyAllWindows()
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
def main():
|
302
|
+
|
303
|
+
pt = Potential()
|
304
|
+
|
305
|
+
th1 = threading.Thread(target=pt.potential)
|
306
|
+
|
307
|
+
th2 = threading.Thread(target=pt.video)
|
308
|
+
|
309
|
+
th1.start()
|
310
|
+
|
311
|
+
th2.start()
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
if __name__ == '__main__':
|
318
|
+
|
319
|
+
main()
|
114
320
|
|
115
321
|
|
116
322
|
|
117
323
|
```
|
118
|
-
|
119
|
-
```
|
120
|
-
|
121
|
-
def video(self):
|
122
|
-
|
123
|
-
cap = cv2.VideoCapture('experiment.mp4')
|
124
|
-
|
125
|
-
if (cap.isOpened()== False):
|
126
|
-
|
127
|
-
print("ビデオファイルを開くとエラーが発生しました")
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
while(cap.isOpened()):
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
ret, frame = cap.read()
|
136
|
-
|
137
|
-
if ret == True:
|
138
|
-
|
139
|
-
cv2.imshow("Video",frame)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
if cv2.waitKey(25) & 0xFF == ord('q'):
|
144
|
-
|
145
|
-
break
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
else:
|
150
|
-
|
151
|
-
break
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
cap.release()
|
156
|
-
|
157
|
-
cv2.destroyAllWindows()
|
158
|
-
|
159
|
-
```
|