Skip to content

Commit 80b710d

Browse files
committed
added : tests for plot recipes
1 parent 999aa11 commit 80b710d

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

src/plot_sim.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ sim_getu!(mpc::PredictiveController, ry, d, ym) = moveinput!(mpc, ry, d; ym)
280280
t, res.D_data[i, :]
281281
end
282282
end
283+
subplot_base += nd
283284
end
284285
# --- plant states x ---
285286
if plotx

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using ControlSystemsBase
55
using Documenter
66
using LinearAlgebra
77
using JuMP, OSQP, Ipopt
8-
using RecipesBase
8+
using Plots
99
using Test
1010

1111

test/test_plot_sim.jl

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ sys = [ tf(1.90,[18.0,1]) tf(1.90,[18.0,1]) tf(1.90,[18.0,1]);
1212
@test res.X_data[:, 1] zeros(model.nx)
1313
end
1414

15+
@testset "SimModel Plots" begin
16+
model = LinModel(sys, Ts, i_d=[3])
17+
res = sim!(model, 15, [1, 3], [-10])
18+
p = plot(res, plotx=true)
19+
@test p[1][1][:x] res.T_data
20+
@test p[1][1][:y] res.Y_data[1, :]
21+
@test p[2][1][:y] res.Y_data[2, :]
22+
@test p[3][1][:y][1:2:end] res.U_data[1, :]
23+
@test p[4][1][:y][1:2:end] res.U_data[2, :]
24+
@test p[5][1][:y] res.D_data[1, :]
25+
@test p[6][1][:y] res.X_data[1, :]
26+
@test p[7][1][:y] res.X_data[2, :]
27+
@test p[8][1][:y] res.X_data[3, :]
28+
@test p[9][1][:y] res.X_data[4, :]
29+
end
30+
1531
@testset "StateEstimator quick simulation" begin
1632
estim = SteadyKalmanFilter(LinModel(sys, Ts, i_d=[3]))
1733
res = sim!(estim, 15)
@@ -24,6 +40,37 @@ end
2440
@test res.X̂_data[:, 1] zeros(estim.nx̂)
2541
end
2642

43+
@testset "StateEstimator Plots" begin
44+
estim = SteadyKalmanFilter(LinModel(sys, Ts, i_d=[3]))
45+
res = sim!(estim, 15, [1, 3], [-10])
46+
p1 = plot(res, plotx=true)
47+
@test p1[1][1][:x] res.T_data
48+
@test p1[end-3][1][:y] res.X_data[1,:]
49+
@test p1[end-2][1][:y] res.X_data[2,:]
50+
@test p1[end-1][1][:y] res.X_data[3,:]
51+
@test p1[end-0][1][:y] res.X_data[4,:]
52+
p2 = plot(res, plotx̂=true)
53+
@test p2[1][1][:x] res.T_data
54+
@test p2[end-5][1][:y] res.X̂_data[1,:]
55+
@test p2[end-4][1][:y] res.X̂_data[2,:]
56+
@test p2[end-3][1][:y] res.X̂_data[3,:]
57+
@test p2[end-2][1][:y] res.X̂_data[4,:]
58+
@test p2[end-1][1][:y] res.X̂_data[5,:]
59+
@test p2[end-0][1][:y] res.X̂_data[6,:]
60+
p3 = plot(res, plotxwithx̂=true)
61+
@test p3[1][1][:x] res.T_data
62+
@test p3[end-5][1][:y] res.X_data[1,:]
63+
@test p3[end-5][2][:y] res.X̂_data[1,:]
64+
@test p3[end-4][1][:y] res.X_data[2,:]
65+
@test p3[end-4][2][:y] res.X̂_data[2,:]
66+
@test p3[end-3][1][:y] res.X_data[3,:]
67+
@test p3[end-3][2][:y] res.X̂_data[3,:]
68+
@test p3[end-2][1][:y] res.X_data[4,:]
69+
@test p3[end-2][2][:y] res.X̂_data[4,:]
70+
@test p3[end-1][1][:y] res.X̂_data[5,:]
71+
@test p3[end-0][1][:y] res.X̂_data[6,:]
72+
end
73+
2774
@testset "PredictiveController quick simulation" begin
2875
mpc = LinMPC(LinModel(sys, Ts, i_d=[3]))
2976
res = sim!(mpc, 15)
@@ -34,4 +81,41 @@ end
3481
@test res.D_data[:, 1] mpc.estim.model.dop
3582
@test res.X_data[:, 1] zeros(mpc.estim.model.nx)
3683
@test res.X̂_data[:, 1] zeros(mpc.estim.nx̂)
84+
end
85+
86+
@testset "PredictiveController Plots" begin
87+
mpc = LinMPC(LinModel(sys, Ts, i_d=[3]), Lwt=[0.01, 0.01])
88+
res = sim!(mpc, 15)
89+
p1 = plot(res, plotŷ=true)
90+
@test p1[1][1][:x] res.T_data
91+
@test p1[1][1][:y] res.Y_data[1,:]
92+
@test p1[1][2][:y] res.Ŷ_data[1,:]
93+
@test p1[2][1][:y] res.Y_data[2,:]
94+
@test p1[2][2][:y] res.Ŷ_data[2,:]
95+
p2 = plot(res, plotx=true)
96+
@test p2[1][1][:x] res.T_data
97+
@test p2[end-3][1][:y] res.X_data[1,:]
98+
@test p2[end-2][1][:y] res.X_data[2,:]
99+
@test p2[end-1][1][:y] res.X_data[3,:]
100+
@test p2[end-0][1][:y] res.X_data[4,:]
101+
p3 = plot(res, plotx̂=true)
102+
@test p3[1][1][:x] res.T_data
103+
@test p3[end-5][1][:y] res.X̂_data[1,:]
104+
@test p3[end-4][1][:y] res.X̂_data[2,:]
105+
@test p3[end-3][1][:y] res.X̂_data[3,:]
106+
@test p3[end-2][1][:y] res.X̂_data[4,:]
107+
@test p3[end-1][1][:y] res.X̂_data[5,:]
108+
@test p3[end-0][1][:y] res.X̂_data[6,:]
109+
p4 = plot(res, plotxwithx̂=true)
110+
@test p4[1][1][:x] res.T_data
111+
@test p4[end-5][1][:y] res.X_data[1,:]
112+
@test p4[end-5][2][:y] res.X̂_data[1,:]
113+
@test p4[end-4][1][:y] res.X_data[2,:]
114+
@test p4[end-4][2][:y] res.X̂_data[2,:]
115+
@test p4[end-3][1][:y] res.X_data[3,:]
116+
@test p4[end-3][2][:y] res.X̂_data[3,:]
117+
@test p4[end-2][1][:y] res.X_data[4,:]
118+
@test p4[end-2][2][:y] res.X̂_data[4,:]
119+
@test p4[end-1][1][:y] res.X̂_data[5,:]
120+
@test p4[end-0][1][:y] res.X̂_data[6,:]
37121
end

0 commit comments

Comments
 (0)