Skip to content

Commit 6c7a1fa

Browse files
committed
added tests for sim! function
1 parent 5889e5e commit 6c7a1fa

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ using ControlSystemsBase
55
using Documenter
66
using LinearAlgebra
77
using JuMP, OSQP, Ipopt
8+
using RecipesBase
89
using Test
910

1011

1112
@testset "ModelPredictiveControl.jl" begin
1213
include("test_sim_model.jl")
1314
include("test_state_estim.jl")
1415
include("test_predictive_control.jl")
16+
include("test_plot_sim.jl")
1517

1618
DocMeta.setdocmeta!(
1719
ModelPredictiveControl,

test/test_plot_sim.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Ts = 4.0
2+
sys = [ tf(1.90,[18.0,1]) tf(1.90,[18.0,1]) tf(1.90,[18.0,1]);
3+
tf(-0.74,[8.0,1]) tf(0.74,[8.0,1]) tf(-0.74,[8.0,1]) ]
4+
5+
@testset "SimModel quick simulation" begin
6+
model = LinModel(sys, Ts, i_d=[3])
7+
res = sim!(model, 15)
8+
@test isa(res.obj, LinModel)
9+
@test length(res.T_data) == 15
10+
@test res.U_data[:, 1] model.uop .+ 1
11+
@test res.D_data[:, 1] model.dop
12+
@test res.X_data[:, 1] zeros(model.nx)
13+
end
14+
15+
@testset "StateEstimator quick simulation" begin
16+
estim = SteadyKalmanFilter(LinModel(sys, Ts, i_d=[3]))
17+
res = sim!(estim, 15)
18+
@test isa(res.obj, SteadyKalmanFilter)
19+
@test length(res.T_data) == 15
20+
@test res.U_data[:, 1] estim.model.uop .+ 1
21+
@test res.Ud_data[:, 1] estim.model.uop .+ 1
22+
@test res.D_data[:, 1] estim.model.dop
23+
@test res.X_data[:, 1] zeros(estim.model.nx)
24+
@test res.X̂_data[:, 1] zeros(estim.nx̂)
25+
end
26+
27+
@testset "PredictiveController quick simulation" begin
28+
mpc = LinMPC(LinModel(sys, Ts, i_d=[3]))
29+
res = sim!(mpc, 15)
30+
@test isa(res.obj, LinMPC)
31+
@test length(res.T_data) == 15
32+
@test res.Ry_data[:, 1] mpc.estim.model.yop .+ 1
33+
@test res.Ud_data res.U_data
34+
@test res.D_data[:, 1] mpc.estim.model.dop
35+
@test res.X_data[:, 1] zeros(mpc.estim.model.nx)
36+
@test res.X̂_data[:, 1] zeros(mpc.estim.nx̂)
37+
end

0 commit comments

Comments
 (0)