Skip to content

Commit e7b47ce

Browse files
committed
NonLinMPC with LinModel uses SteadyKalmanFilter by default
1 parent d5e8465 commit e7b47ce

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

docs/src/public/predictive_control.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Pages = ["predictive_control.md"]
66

77
All the predictive controllers in this module rely on a state estimator to compute the
88
predictions. The default [`LinMPC`](@ref) estimator is a [`SteadyKalmanFilter`](@ref), and
9-
[`NonLinMPC`](@ref), an [`UnscentedKalmanFilter`](@ref). For simpler and more classical
10-
designs, an [`InternalModel`](@ref) structure is also available, that assumes by default
11-
that the current model mismatch estimation is constant in the future (same approach than
12-
dynamic matrix control, DMC).
9+
[`NonLinMPC`](@ref) with nonlinear models, an [`UnscentedKalmanFilter`](@ref). For simpler
10+
and more classical designs, an [`InternalModel`](@ref) structure is also available, that
11+
assumes by default that the current model mismatch estimation is constant in the future
12+
(same approach than dynamic matrix control, DMC).
1313

1414
!!! info
1515
The nomenclature uses hats for the predictions (or estimations, for the state

example/juMPC.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ test_mpc(linModel4, mpc)
151151

152152
test_mpc(linModel4, nmpc)
153153
@time u_data, y_data, r_data, d_data = test_mpc(linModel4, nmpc)
154+
@profview test_mpc(linModel4, nmpc)
154155

155156
test_mpc(nonLinModel2, nmpc2)
156157
@time u_data, y_data, r_data, d_data = test_mpc(nonLinModel2, nmpc2)

src/controller/nonlinmpc.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ since ``H_c ≤ H_p`` implies that ``\mathbf{u}(k+H_p) = \mathbf{u}(k+H_p-1)``.
105105
!!! tip
106106
Replace any of the 3 arguments with `_` if not needed (see `JE` default value below).
107107
108-
This method uses the default state estimator, an [`UnscentedKalmanFilter`](@ref) with
109-
default arguments.
108+
This method uses the default state estimator :
109+
110+
- if `model` is a [`LinModel`](@ref), a [`SteadyKalmanFilter`](@ref) with default arguments;
111+
- else, an [`UnscentedKalmanFilter`](@ref) with default arguments.
110112
111113
!!! warning
112114
See Extended Help if you get an error like `MethodError: no method matching
@@ -152,6 +154,7 @@ and `h` functions must be compatible with this feature. See [Automatic different
152154
for common mistakes when writing these functions.
153155
"""
154156
NonLinMPC(model::SimModel; kwargs...) = NonLinMPC(UnscentedKalmanFilter(model); kwargs...)
157+
NonLinMPC(model::LinModel; kwargs...) = NonLinMPC(SteadyKalmanFilter(model); kwargs...)
155158

156159

157160
"""

test/test_predictive_control.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ end
7676
@test mpc1.estim. [1,2,3,4]
7777
end
7878

79-
8079
@testset "NonLinMPC construction" begin
8180
linmodel1 = LinModel(sys,Ts,i_d=[3])
81+
nmpc0 = NonLinMPC(linmodel1, Hp=15)
82+
@test isa(nmpc0.estim, SteadyKalmanFilter)
8283
f(x,u,d) = linmodel1.A*x + linmodel1.Bu*u + linmodel1.Bd*d
8384
h(x,d) = linmodel1.C*x + linmodel1.Du*d
8485
nonlinmodel = NonLinModel(f, h, Ts, 2, 4, 2, 1)

0 commit comments

Comments
 (0)