-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsimulate.jl
34 lines (33 loc) · 913 Bytes
/
simulate.jl
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
# 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
# - u0: initial control vector
#
# OUTPUT
# - state: state vector history
# - time: time vector history
#
# ------------------------------------------------------------------------------
function simulate(acfun,finp,Tsim,dt,x0,u0)
# set up simulation
# vector of times
time=collect(0:dt:Tsim)
# initialize state time history
state=zeros(NSTATES,length(time))
# set initial condition
state[:,1]=x0
# simulate open-loop system
for i=1:length(time)-1
# integrate
sol=rk4(acfun,finp,time[i],dt,state[:,i],u0)
state[:,i+1]=sol
end
#
return state, time
end