-
Notifications
You must be signed in to change notification settings - Fork 0
/
classic.py
75 lines (72 loc) · 2.09 KB
/
classic.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
import gym
#import pybullet as p
import gym_iOTA
import numpy as np
import time
from clustering import cluster
from planning import *
from experimental import ParamPoly2D
import matplotlib.pyplot as plt
env = gym.make('iOTA-v0',
render=True,
no_of_modules=10,
no_of_clusters=4,
arena=(3,3),
low_control=False,
)
observation = env.reset()
i = 0
poly = ParamPoly2D(2,10)
#print(poly.root_coor)
setpoints = np.zeros((env.no_of_modules, 3))
for j in range(env.no_of_modules):
setpoints[j,:] = [*poly.sample_near(observation[j,:]),0.01]
#print(observation, setpoints)
paths = planning(observation, setpoints, (0,0,0), observation, 5)
print("planning done")
smooth_path = []
progress = []
ds = 0.05
for path in paths:
print(path)
sp = Spline2D(*path)
s = np.arange(0, sp.s[-1], ds)
rx, ry = [], []
for i_s in s:
ix, iy = sp.calc_position(i_s)
rx.append(ix)
ry.append(iy)
smooth_path.append(list(zip(rx,ry)))
progress.append(0)
plt.subplots(1)
plt.plot(*path, "xb", label="input")
plt.plot(rx, ry, "-r", label="spline")
plt.grid(True)
plt.axis("equal")
plt.xlabel("x[m]")
plt.ylabel("y[m]")
plt.legend()
plt.show()
print("spline done")
while i>=0:
print(i)
action = np.ones((env.no_of_modules, 3))
for j in range(env.no_of_modules):
if progress[j]!=-1:
if progress[j]==(len(smooth_path[j])-1):
progress[j] = -1
else:
progress[j] +=1
action[j,:] = [*smooth_path[j][progress[j]], 0.01]
dock = np.zeros(
(env.no_of_modules,
env.no_of_modules))
observation, reward, done, info = env.step(action, dock)
## Try pooling the control
if i%20==0:
for j in range(env.no_of_modules):
setpoints[j,:] = [*poly.sample_near(observation[j,:2]),0.01]
cluster(observation, [iota.base_id for iota in env.iotas], env.no_of_clusters, debug=True, pClient=env.pClient )
# time.sleep(0.1)
i+=1
env.close()