Skip to content

Commit 524fa28

Browse files
authored
Merge pull request #210 from JuliaControl/doc_correction
new `ManualEstimator` tests and minor doc corrections
2 parents 44a5589 + 408701b commit 524fa28

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

src/controller/explicitmpc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ The controller minimizes the following objective function at each discrete time
105105
See [`LinMPC`](@ref) for the variable definitions. This controller does not support
106106
constraints but the computational costs are extremely low (array division), therefore
107107
suitable for applications that require small sample times. The keyword arguments are
108-
identical to [`LinMPC`](@ref), except for `Cwt` and `optim` which are not supported. This
109-
controller uses a [`SingleShooting`](@ref) transcription method.
108+
identical to [`LinMPC`](@ref), except for `Cwt`, `transcription` and `optim`, which are not
109+
supported. This controller uses a [`SingleShooting`](@ref) transcription method.
110110
111111
This method uses the default state estimator, a [`SteadyKalmanFilter`](@ref) with default
112112
arguments. This controller is allocation-free.

src/estimator/internal_model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ unmeasured ``\mathbf{y^u}``. `model` evaluates the deterministic predictions
7070
``\mathbf{ŷ_d}``, and `stoch_ym`, the stochastic predictions of the measured outputs
7171
``\mathbf{ŷ_s^m}`` (the unmeasured ones being ``\mathbf{ŷ_s^u=0}``). The predicted outputs
7272
sum both values : ``\mathbf{ŷ = ŷ_d + ŷ_s}``. See the Extended Help for more details. This
73-
estimator is allocation-free is `model` simulations do not allocate.
73+
estimator is allocation-free if `model` simulations do not allocate.
7474
7575
!!! warning
7676
`InternalModel` estimator does not work if `model` is integrating or unstable. The

test/3_test_predictive_control.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ end
180180
@test ym r atol=1e-2
181181
end
182182

183+
@testitem "LinMPC and ManualEstimator v.s. default" setup=[SetupMPCtests] begin
184+
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
185+
linmodel = setop!(LinModel(tf(5, [2, 1]), 3.0), yop=[10])
186+
r = [15]
187+
outdist = [5]
188+
U_man, U_def = let linmodel=linmodel, r=r, outdist=outdist
189+
mpc_man = LinMPC(ManualEstimator(linmodel))
190+
skf = SteadyKalmanFilter(linmodel)
191+
mpc_def = LinMPC(linmodel)
192+
linmodel.x0 .= 0
193+
U_man, U_def = zeros(1, 25), zeros(1, 25)
194+
for i=1:25
195+
ym = linmodel() - outdist
196+
= preparestate!(skf, ym)
197+
setstate!(mpc_man, x̂)
198+
preparestate!(mpc_def, ym)
199+
u_man = moveinput!(mpc_man, r)
200+
u_def = moveinput!(mpc_def, r)
201+
U_man[:, i], U_def[:, i] = u_man, u_def
202+
updatestate!(skf, u_man, ym)
203+
updatestate!(mpc_def, u_def, ym)
204+
updatestate!(linmodel, u_man)
205+
end
206+
U_man, U_def
207+
end
208+
@test U_man U_def atol=1e-9
209+
end
210+
183211
@testitem "LinMPC other methods" setup=[SetupMPCtests] begin
184212
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
185213
linmodel1 = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])
@@ -852,6 +880,37 @@ end
852880
@test ym r atol=1e-2
853881
end
854882

883+
@testitem "NonLinMPC and ManualEstimator v.s. default" setup=[SetupMPCtests] begin
884+
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
885+
linmodel = LinModel(tf(5, [2, 1]), 3.0)
886+
f(x,u,_,p) = p.A*x + p.Bu*u
887+
h(x,_,p) = p.C*x
888+
model = setop!(NonLinModel(f, h, 3.0, 1, 1, 1; solver=nothing, p=linmodel), yop=[10])
889+
r = [15]
890+
outdist = [5]
891+
U_man, U_def = let model=model, r=r, outdist=outdist
892+
nmpc_man = NonLinMPC(ManualEstimator(model), Hp=10)
893+
ukf = UnscentedKalmanFilter(model)
894+
nmpc_def = NonLinMPC(model, Hp=10)
895+
model.x0 .= 0
896+
U_man, U_def = zeros(1, 25), zeros(1, 25)
897+
for i=1:25
898+
ym = model() - outdist
899+
= preparestate!(ukf, ym)
900+
setstate!(nmpc_man, x̂)
901+
preparestate!(nmpc_def, ym)
902+
u_man = moveinput!(nmpc_man, r)
903+
u_def = moveinput!(nmpc_def, r)
904+
U_man[:, i], U_def[:, i] = u_man, u_def
905+
updatestate!(ukf, u_man, ym)
906+
updatestate!(nmpc_def, u_def, ym)
907+
updatestate!(model, u_man)
908+
end
909+
U_man, U_def
910+
end
911+
@test U_man U_def atol=1e-9
912+
end
913+
855914
@testitem "NonLinMPC other methods" setup=[SetupMPCtests] begin
856915
using .SetupMPCtests, ControlSystemsBase, LinearAlgebra
857916
linmodel = setop!(LinModel(sys,Ts,i_u=[1,2]), uop=[10,50], yop=[50,30])

0 commit comments

Comments
 (0)