Skip to content

Commit d65a404

Browse files
committed
doc NonLinMPC construction exemples
1 parent 4d9d4ab commit d65a404

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

src/ModelPredictiveControl.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module ModelPredictiveControl
22

33
using LinearAlgebra
44
using ControlSystemsBase
5-
using JuMP, OSQP, Ipopt
5+
using JuMP
6+
import OSQP, Ipopt
67

78
export SimModel, LinModel, NonLinModel, setop!, setstate!, updatestate!, evaloutput
89
export StateEstimator, InternalModel

src/estimator/kalman.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ unmeasured ones, for ``\mathbf{ĥ^u}``).
393393
394394
# Examples
395395
```jldoctest
396-
julia> model = NonLinModel((x,u,_)->-x+u, (x,_)->2x, 10, 1, 1, 1);
396+
julia> model = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10, 1, 1, 1);
397397
398398
julia> estim = UnscentedKalmanFilter(model, σR=[1], nint_ym=[2], σP0_int=[1, 1])
399399
UnscentedKalmanFilter{NonLinModel} estimator with a sample time Ts = 10.0 s and:

src/predictive_control.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ arguments.
201201
julia> model = LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 4);
202202
203203
julia> mpc = LinMPC(model, Mwt=[0, 1], Nwt=[0.5], Hp=30, Hc=1)
204-
LinMPC{SteadyKalmanFilter} controller with a sample time Ts = 4.0 s and:
204+
LinMPC controller with a sample time Ts = 4.0 s, SteadyKalmanFilter estimator and:
205205
1 manipulated inputs u
206206
4 states x̂
207207
2 measured outputs ym
@@ -229,7 +229,7 @@ Use custom state estimator `estim` to construct `LinMPC`.
229229
julia> estim = KalmanFilter(LinModel([tf(3, [30, 1]); tf(-2, [5, 1])], 4), i_ym=[2]);
230230
231231
julia> mpc = LinMPC(estim, Mwt=[0, 1], Nwt=[0.5], Hp=30, Hc=1)
232-
LinMPC{KalmanFilter} controller with a sample time Ts = 4.0 s and:
232+
LinMPC controller with a sample time Ts = 4.0 s, KalmanFilter estimator and:
233233
1 manipulated inputs u
234234
3 states x̂
235235
1 measured outputs ym
@@ -413,7 +413,15 @@ default arguments.
413413
414414
# Examples
415415
```jldoctest
416-
julia> a = 1;
416+
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10, 1, 1, 1);
417+
418+
julia> mpc = NonLinMPC(model, Hp=20, Hc=1, Cwt=1e6)
419+
NonLinMPC controller with a sample time Ts = 10.0 s, UnscentedKalmanFilter{NonLinModel} estimator and:
420+
1 manipulated inputs u
421+
2 states x̂
422+
1 measured outputs ym
423+
0 unmeasured outputs yu
424+
0 measured disturbances d
417425
```
418426
419427
# Extended Help
@@ -431,7 +439,17 @@ Use custom state estimator `estim` to construct `NonLinMPC`.
431439
432440
# Examples
433441
```jldoctest
434-
julia> a = 1;
442+
julia> model = NonLinModel((x,u,_)->0.5x+u, (x,_)->2x, 10, 1, 1, 1);
443+
444+
julia> estim = UnscentedKalmanFilter(model, σQ_int=[0.05]);
445+
446+
julia> mpc = NonLinMPC(estim, Hp=20, Hc=1, Cwt=1e6)
447+
NonLinMPC controller with a sample time Ts = 10.0 s, UnscentedKalmanFilter{NonLinModel} estimator and:
448+
1 manipulated inputs u
449+
2 states x̂
450+
1 measured outputs ym
451+
0 unmeasured outputs yu
452+
0 measured disturbances d
435453
```
436454
"""
437455
function NonLinMPC(
@@ -1209,8 +1227,8 @@ repeatdiag(A, n::Int) = kron(I(n), A)
12091227

12101228

12111229
function Base.show(io::IO, mpc::PredictiveController)
1212-
println(io, "$(typeof(mpc)) controller with a sample time "*
1213-
"Ts = $(mpc.estim.model.Ts) s and:")
1230+
println(io, "$(typeof(mpc).name.name) controller with a sample time "*
1231+
"Ts = $(mpc.estim.model.Ts) s, $(typeof(mpc).parameters[1]) estimator and:")
12141232
println(io, " $(mpc.estim.model.nu) manipulated inputs u")
12151233
println(io, " $(mpc.estim.nx̂) states x̂")
12161234
println(io, " $(mpc.estim.nym) measured outputs ym")

src/sim_model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ See also [`LinModel`](@ref).
252252
253253
# Examples
254254
```jldoctest
255-
julia> model = NonLinModel((x,u,_)->-x+u, (x,_)->2x, 10, 1, 1, 1)
255+
julia> model = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10, 1, 1, 1)
256256
Discrete-time nonlinear model with a sample time Ts = 10.0 s and:
257257
1 manipulated inputs u
258258
1 states x

0 commit comments

Comments
 (0)