-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraj.py
168 lines (138 loc) · 7.12 KB
/
traj.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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def input_feasibility(b, i, f, e, Abnd):
n = 1
for B in range(4, b + 1):
c1 = (2*(B+1)*(B-1) + B*(3*(B+1)*(B-1))**(0.5)) / ((B+1)*(B+2))
c2 = (2*(B+1)*(B-1) - B*(3*(B+1)*(B-1))**(0.5)) / ((B+1)*(B+2))
fa1 = abs(B*(c1**(1-(2/B)))*(f[1]-i[1])*(B-1-c1*(B+1)) / (Abnd*(1+c1)**3))
fa2 = abs(B*(c2**(1-(2/B)))*(f[1]-i[1])*(B-1-c2*(B+1)) / (Abnd*(1+c2)**3))
Cup = (f[0] - i[0]) * (e / (abs(i[1] - f[1]) - e))**(1/B)
Clo = max(fa1, fa2)
if Clo < Cup:
n += 1
Sdyn = np.zeros((n, 3))
n = 0
for B in range(4, b + 1):
c1 = (2*(B+1)*(B-1) + B*(3*(B+1)*(B-1))**(0.5)) / ((B+1)*(B+2))
c2 = (2*(B+1)*(B-1) - B*(3*(B+1)*(B-1))**(0.5)) / ((B+1)*(B+2))
fa1 = abs(B*(c1**(1-(2/B)))*(f[1]-i[1])*(B-1-c1*(B+1)) / (Abnd*(1+c1)**3))
fa2 = abs(B*(c2**(1-(2/B)))*(f[1]-i[1])*(B-1-c2*(B+1)) / (Abnd*(1+c2)**3))
Cup = (f[0] - i[0]) * (e / (abs(i[1] - f[1]) - e))**(1/B)
Clo = max(fa1, fa2)
if Clo < Cup:
Sdyn[n, 0] = B
Sdyn[n, 1] = Clo
Sdyn[n, 2] = Cup
n += 1
return Sdyn
def window_check(i, f, W, R, Sdyni, Sdynj, Sdynk, u, v, w):
c_step = 0.1
g, h = 1, 1
for p in range(Sdyni.shape[0]):
for Cx in np.arange(Sdyni[p, 1], Sdyni[p, 2], c_step):
for q in range(Sdynj.shape[0]):
for r in range(Sdynk.shape[0]):
x = ((W[3, u] + R - i[u]) / (f[u] - W[3, u] - R))**(1 / Sdyni[p, 0])
y = ((W[0, u] - R - i[u]) / (f[u] - W[0, u] + R))**(1 / Sdyni[p, 0])
Cylo = Cx * x * ((f[v] - W[2, v] + R) / (W[2, v] - R - i[v]))**(1 / Sdynj[q, 0])
Cyup = Cx * y * ((W[1, v] + R - i[v]) / (f[v] - W[1, v] - R))**(1 / Sdynj[q, 0])
Czlo = Cx * x * ((f[w] - W[2, w] + R) / (W[2, w] - R - i[w]))**(1 / Sdynk[r, 0])
Czup = Cx * y * ((W[1, w] + R - i[w]) / (f[w] - W[1, w] - R))**(1 / Sdynk[r, 0])
if (Cylo < Cyup) and (Czlo < Czup):
Cylo_fes = max(Cylo, Sdynj[q, 1])
Cyup_fes = min(Cyup, Sdynj[q, 2])
Czlo_fes = max(Czlo, Sdynk[r, 1])
Czup_fes = min(Czup, Sdynk[r, 2])
if (Cylo_fes < Cyup_fes) and (Czlo_fes < Czup_fes):
g += 1
Si_fes = np.zeros((g, 8))
g = 0
for p in range(Sdyni.shape[0]):
for Cx in np.arange(Sdyni[p, 1], Sdyni[p, 2], c_step):
for q in range(Sdynj.shape[0]):
for r in range(Sdynk.shape[0]):
x = ((W[3, u] + R - i[u]) / (f[u] - W[3, u] - R))**(1 / Sdyni[p, 0])
y = ((W[0, u] - R - i[u]) / (f[u] - W[0, u] + R))**(1 / Sdyni[p, 0])
Cylo = Cx * x * ((f[v] - W[2, v] + R) / (W[2, v] - R - i[v]))**(1 / Sdynj[q, 0])
Cyup = Cx * y * ((W[1, v] + R - i[v]) / (f[v] - W[1, v] - R))**(1 / Sdynj[q, 0])
Czlo = Cx * x * ((f[w] - W[2, w] + R) / (W[2, w] - R - i[w]))**(1 / Sdynk[r, 0])
Czup = Cx * y * ((W[1, w] + R - i[w]) / (f[w] - W[1, w] - R))**(1 / Sdynk[r, 0])
if (Cylo < Cyup) and (Czlo < Czup):
Cylo_fes = max(Cylo, Sdynj[q, 1])
Cyup_fes = min(Cyup, Sdynj[q, 2])
Czlo_fes = max(Czlo, Sdynk[r, 1])
Czup_fes = min(Czup, Sdynk[r, 2])
if (Cylo_fes < Cyup_fes) and (Czlo_fes < Czup_fes):
Si_fes[g, 0] = Sdyni[p, 0]
Si_fes[g, 1] = Cx
Si_fes[g, 2] = Sdynj[q, 0]
Si_fes[g, 3] = Cylo_fes
Si_fes[g, 4] = Sdynk[r, 0]
Si_fes[g, 5] = Czlo_fes
Si_fes[g, 6] = Czup_fes
g += 1
h = 0
for m in range(Si_fes.shape[0]):
for Cy in np.arange(Si_fes[m, 3], Si_fes[m, 4], c_step):
for Cz in np.arange(Si_fes[m, 5], Si_fes[m, 6], c_step):
h += 1
Si = np.zeros((h, 6))
h = 0
for m in range(Si_fes.shape[0]):
for Cy in np.arange(Si_fes[m, 3], Si_fes[m, 4], c_step):
for Cz in np.arange(Si_fes[m, 5], Si_fes[m, 6], c_step):
Si[h, 0] = Si_fes[m, 0]
Si[h, 1] = Si_fes[m, 1]
Si[h, 2] = Si_fes[m, 2]
Si[h, 3] = Cy
Si[h, 4] = Si_fes[m, 4]
Si[h, 5] = Cz
h += 1
return Si
def compile_set(i, f, W, ti, tf, e, Abnd, b, R):
Sxdyn = input_feasibility(b, [ti, i[0]], [tf, f[0]], e, Abnd)
Sydyn = input_feasibility(b, [ti, i[1]], [tf, f[1]], e, Abnd)
Szdyn = input_feasibility(b, [ti, i[2]], [tf, f[2]], e, Abnd)
Sx = window_check(i, f, W, R, Sxdyn, Sydyn, Szdyn, 0, 1, 2)
Sy = window_check(i, f, W, R, Sydyn, Szdyn, Sxdyn, 1, 2, 0)
Sz = window_check(i, f, W, R, Szdyn, Sxdyn, Sydyn, 2, 0, 1)
S = np.concatenate((Sx, Sy, Sz), axis=0)
return S
def create_graph(i, f, tf, S, W):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(i[0], i[1], i[2], 'x', label='Initial Position')
ax.plot(f[0], f[1], f[2], 'X', label='Final Position')
t_ = np.linspace(1, tf, num=200)
for n in range(S.shape[0]):
traj = np.zeros((len(t_), 3))
for tidx, t in enumerate(t_):
traj[tidx, 0] = f[0] + (i[0] - f[0]) / (1 + (t / S[n, 1])**S[n, 0])
traj[tidx, 1] = f[1] + (i[1] - f[1]) / (1 + (t / S[n, 3])**S[n, 2])
traj[tidx, 2] = f[2] + (i[2] - f[2]) / (1 + (t / S[n, 5])**S[n, 4])
ax.plot(traj[:, 0], traj[:, 1], traj[:, 2], color='g', linewidth=1)
W_ = np.concatenate((W, W[0:1]), axis=0)
ax.plot(W_[:, 0], W_[:, 1], W_[:, 2], color='r', linewidth=3)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Drone Trajectory Simulation')
ax.legend()
plt.show()
if __name__ == "__main__":
i = np.array(eval(input('Enter initial position (e.g., [x, y, z]): ')))
f = np.array(eval(input('Enter final position (e.g., [x, y, z]): ')))
e = float(input('Enter tolerance for final position: '))
tf = float(input('Enter time to reach destination: '))
Abnd = float(input('Enter the acceleration bound of drone: '))
b = int(input('Enter upper bound for value taken by parameter B: '))
W1 = np.array(eval(input('Enter first corner of Window (e.g., [x, y, z]): ')))
W2 = np.array(eval(input('Enter second corner of Window (e.g., [x, y, z]): ')))
W3 = np.array(eval(input('Enter third corner of Window (e.g., [x, y, z]): ')))
W4 = np.array(eval(input('Enter fourth corner of Window (e.g., [x, y, z]): ')))
R = float(input('Enter the influence radius of drone: '))
W = np.array([W1, W2, W3, W4])
S = compile_set(i, f, W, 0, tf, e, Abnd, b, R)
create_graph(i, f, tf, S, W)