Skip to content

Commit 964a095

Browse files
committed
added: mpc weight modification tests
1 parent b54915c commit 964a095

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

docs/src/public/generic_func.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ initstate!
3737
setstate!
3838
```
3939

40-
## Set Plant Model
40+
## Set Model and Weights
4141

4242
```@docs
4343
setmodel!

src/estimator/execute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Set `model` and covariance matrices of `estim` [`StateEstimator`](@ref).
246246
247247
Allows model adaptation of estimators based on [`LinModel`](@ref) at runtime. Modification
248248
of [`NonLinModel`](@ref) is not supported. New covariance matrices can be specified with the
249-
keyword arguments (see [`SteadyKalmanFilter`](ref) documentation for the nomenclature). Not
249+
keyword arguments (see [`SteadyKalmanFilter`](@ref) documentation for the nomenclature). Not
250250
supported by [`Luenberger`](@ref) and [`SteadyKalmanFilter`](@ref), use the time-varying
251251
[`KalmanFilter`](@ref) instead. The [`MovingHorizonEstimator`](@ref) model is kept constant
252252
over the estimation horizon ``H_e``. The matrix dimensions and sample time must stay the

test/test_predictive_control.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ end
286286
r = [40]
287287
u = moveinput!(mpc, r)
288288
@test u [13] atol=1e-2
289+
setmodel!(mpc, M_Hp=diagm(1:1000), Ñ_Hc=diagm([0.1;1e6]), L_Hp=diagm(1.1:1000.1))
290+
@test mpc.M_Hp diagm(1:1000)
291+
@test mpc.Ñ_Hc diagm([0.1;1e6])
292+
@test mpc.L_Hp diagm(1.1:1000.1)
289293
end
290294

291295
@testset "ExplicitMPC construction" begin
@@ -413,6 +417,10 @@ end
413417
r = [40]
414418
u = moveinput!(mpc, r)
415419
@test u [13] atol=1e-2
420+
setmodel!(mpc, M_Hp=diagm(1:1000), Ñ_Hc=[0.1], L_Hp=diagm(1.1:1000.1))
421+
@test mpc.M_Hp diagm(1:1000)
422+
@test mpc.Ñ_Hc [0.1]
423+
@test mpc.L_Hp diagm(1.1:1000.1)
416424
end
417425

418426
@testset "NonLinMPC construction" begin
@@ -712,5 +720,18 @@ end
712720
r = [40]
713721
u = moveinput!(mpc, r)
714722
@test u [13] atol=1e-2
723+
setmodel!(mpc, M_Hp=diagm(1:1000), Ñ_Hc=diagm([0.1;1e6]), L_Hp=diagm(1.1:1000.1))
724+
@test mpc.M_Hp diagm(1:1000)
725+
@test mpc.Ñ_Hc diagm([0.1;1e6])
726+
@test mpc.L_Hp diagm(1.1:1000.1)
727+
f(x,u,d) = estim.model.A*x + estim.model.Bu*u + estim.model.Bd*d
728+
h(x,d) = estim.model.C*x + estim.model.Du*d
729+
nonlinmodel = NonLinModel(f, h, 10.0, 1, 1, 1)
730+
nmpc = NonLinMPC(nonlinmodel, Hp=1000, Hc=1)
731+
setmodel!(nmpc, M_Hp=diagm(1:1000), Ñ_Hc=diagm([0.1;1e6]), L_Hp=diagm(1.1:1000.1))
732+
@test nmpc.M_Hp diagm(1:1000)
733+
@test nmpc.Ñ_Hc diagm([0.1;1e6])
734+
@test nmpc.L_Hp diagm(1.1:1000.1)
735+
@test_throws ErrorException setmodel!(nmpc, deepcopy(nonlinmodel))
715736
end
716737

test/test_state_estim.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ end
546546
setmodel!(ukf2, Q̂=[1e-3], R̂=[1e-6])
547547
@test ukf2. [1e-3]
548548
@test ukf2. [1e-6]
549+
@test_throws ErrorException setmodel!(ukf2, deepcopy(nonlinmodel))
549550
end
550551

551552
@testset "ExtendedKalmanFilter construction" begin
@@ -668,6 +669,7 @@ end
668669
setmodel!(ekf2, Q̂=[1e-3], R̂=[1e-6])
669670
@test ekf2. [1e-3]
670671
@test ekf2. [1e-6]
672+
@test_throws ErrorException setmodel!(ekf2, deepcopy(nonlinmodel))
671673
end
672674

673675
@testset "MovingHorizonEstimator construction" begin
@@ -1055,4 +1057,5 @@ end
10551057
setmodel!(mhe2, Q̂=[1e-3], R̂=[1e-6])
10561058
@test mhe2. [1e-3]
10571059
@test mhe2. [1e-6]
1060+
@test_throws ErrorException setmodel!(mhe2, deepcopy(nonlinmodel))
10581061
end

0 commit comments

Comments
 (0)