-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_dynamic_simulation.py
57 lines (43 loc) · 1.45 KB
/
main_dynamic_simulation.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
from functions import aerodynamic_forces_moments
from functions import calculate_state_differentials
from functions import plot_states_and_inputs
from aircraft_params import *
# set some simulations parameters
d_t = 1 # time step
t_end = 10 # duration
# set initial states
pos_0 = [0.0, 0.0, 0.0]
vel_0 = 8.0
alpha_0 = 0
beta_0 = 0
orient_0 = [0.0, 0.0, 0.0]
bodyrates_0 = [0.0, 0.0, 0.0]
x_0 = [pos_0[0], pos_0[1], pos_0[2], vel_0, alpha_0, beta_0, orient_0[0], orient_0[1], orient_0[2],
bodyrates_0[0], bodyrates_0[1], bodyrates_0[2]]
u_0 = [-5, -5, 10000, 10000]
# u_elevon_vec = [0, 0, ]
# start simulation
x = x_0
u = u_0
t = 0
t_vec = [0] # initialize array to store time stamps
x_array = np.array([x_0]) # initialize array to store states
u_array = np.array([u_0]) # initialize array to store inputs
while t < t_end:
# calculate forces and moments with current states and control inputs
current_aero_forces_moments = aerodynamic_forces_moments(x, u)
# calculate states derivatives
d_x = calculate_state_differentials(current_aero_forces_moments, x)
# update input vector
u = u_0
# update states
for j in range(len(x)):
x[j] += d_x[j] * d_t
t += d_t
t_vec.append(t)
# print(x_array.shape)
# print("x: " + str(x_array.shape))
x_array = np.vstack((x_array, x))
u_array = np.vstack((u_array, u))
print("states after simulation: " + str(x))
# plot_states_and_inputs(t_vec, x_array, u_array)