-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimulate.jl
More file actions
38 lines (37 loc) · 1.04 KB
/
Copy pathsimulate.jl
File metadata and controls
38 lines (37 loc) · 1.04 KB
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
# DESCRIPTION
# Simulates open-loop dynamics using a dynamic inverse controller.
#
# INPUT
# - acfun: name of system dynamics function
# - finp: name of control input function
# - Tsim: total simulation time
# - dt: time step
# - x0: initial state vector
# - xdot0: initial state derivative vector
# - u0: initial control vector
#
# OUTPUT
# - state: state vector history
# - time: time vector history
#
# ------------------------------------------------------------------------------
function simulate(acfun,finp,Tsim,dt,x0,xdot0,u0)
# set up simulation
# vector of times
time=collect(0:dt:Tsim)
# initialize state time history
state=zeros(NSTATES,length(time))
dstate=zeros(NSTATES,length(time))
# set initial condition
state[:,1]=x0
dstate[:,1]=xdot0
# simulate open-loop system
for i=1:length(time)-1
# integrate
sol=rk4(H60!,finp,time[i],dt,dstate[:,i],state[:,i],u0)
state[:,i+1]=sol[1]
dstate[:,i+1]=sol[2]
end
#
return state, time
end