Skip to content

Commit 88f0240

Browse files
authored
Merge pull request #183 from JuliaControl/simplify_diff_solvers
Changed: `RungeKutta` no longer uses `DiffCache`
2 parents 7d8ccde + 3af2012 commit 88f0240

20 files changed

+338
-265
lines changed

Project.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
33
authors = ["Francis Gagnon"]
4-
version = "1.5.0"
4+
version = "1.5.1"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
@@ -12,7 +12,6 @@ JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
1212
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1414
OSQP = "ab2f91bb-94b4-55e3-9ba0-7f65df51de79"
15-
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
1615
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1716
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
1817
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -29,7 +28,6 @@ JuMP = "1.21"
2928
LinearAlgebra = "1.10"
3029
Logging = "1.10"
3130
OSQP = "0.8"
32-
PreallocationTools = "0.4.14"
3331
PrecompileTools = "1"
3432
ProgressLogging = "0.1"
3533
Random = "1.10"

src/ModelPredictiveControl.jl

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import JuMP
2525
import JuMP: MOIU, MOI, GenericModel, Model, optimizer_with_attributes, register
2626
import JuMP: @variable, @operator, @constraint, @objective
2727

28-
import PreallocationTools: DiffCache, get_tmp # TODO: remove this dep if possible (with Cache of DI.jl)
29-
3028
import OSQP, Ipopt
3129

3230
export SimModel, LinModel, NonLinModel

src/controller/execute.jl

+10-7
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,27 @@ julia> round.(getinfo(mpc)[:Ŷ], digits=3)
113113
```
114114
"""
115115
function getinfo(mpc::PredictiveController{NT}) where NT<:Real
116-
model, transcription = mpc.estim.model, mpc.transcription
117-
nΔŨ = mpc.Hc*model.nu + mpc.
116+
model, buffer, transcription = mpc.estim.model, mpc.buffer, mpc.transcription
117+
nΔŨ, nK = mpc.Hc*model.nu + mpc., mpc.Hp*model.nk
118118
nŶe, nUe = (mpc.Hp+1)*model.ny, (mpc.Hp+1)*model.nu
119119
nX̂0, nÛ0 = mpc.estim.nx̂*mpc.Hp, model.nu*mpc.Hp
120120
= mpc.
121121
info = Dict{Symbol, Any}()
122-
ΔŨ = Vector{NT}(undef, nΔŨ)
123-
x̂0end = similar(mpc.estim.x̂0)
122+
ΔŨ = Vector{NT}(undef, nΔŨ)
123+
x̂0end = similar(mpc.estim.x̂0)
124+
K0 = Vector{NT}(undef, nK)
124125
Ue, Ŷe = Vector{NT}(undef, nUe), Vector{NT}(undef, nŶe)
125126
U0, Ŷ0 = similar(mpc.Uop), similar(mpc.Yop)
126127
Û0, X̂0 = Vector{NT}(undef, nÛ0), Vector{NT}(undef, nX̂0)
127-
U, Ŷ = similar(mpc.Uop), similar(mpc.Yop)
128+
U, Ŷ = buffer.U, buffer.
129+
= buffer.
128130
U0 = getU0!(U0, mpc, Z̃)
129131
ΔŨ = getΔŨ!(ΔŨ, mpc, transcription, Z̃)
130-
Ŷ0, x̂0end = predict!(Ŷ0, x̂0end, X̂0, Û0, mpc, model, transcription, U0, Z̃)
132+
Ŷ0, x̂0end = predict!(Ŷ0, x̂0end, X̂0, Û0, K0, mpc, model, transcription, U0, Z̃)
131133
Ue, Ŷe = extended_vectors!(Ue, Ŷe, mpc, U0, Ŷ0)
132134
U .= U0 .+ mpc.Uop
133135
Ŷ .= Ŷ0 .+ mpc.Yop
136+
D̂ .= mpc.D̂0 + mpc.Dop
134137
J = obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)
135138
Ŷs = similar(mpc.Yop)
136139
predictstoch!(Ŷs, mpc, mpc.estim)
@@ -140,7 +143,7 @@ function getinfo(mpc::PredictiveController{NT}) where NT<:Real
140143
info[:U] = U
141144
info[:u] = info[:U][1:model.nu]
142145
info[:d] = mpc.d0 + model.dop
143-
info[:D̂] = mpc.D̂0 + mpc.Dop
146+
info[:D̂] =
144147
info[:ŷ] = mpc.
145148
info[:Ŷ] =
146149
info[:x̂end] = x̂0end + mpc.estim.x̂op

src/controller/explicitmpc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ optim_objective!(mpc::ExplicitMPC) = lmul!(-1, ldiv!(mpc.Z̃, mpc.H̃_chol, mpc.
195195

196196
"Compute the predictions but not the terminal states if `mpc` is an [`ExplicitMPC`](@ref)."
197197
function predict!(
198-
Ŷ0, x̂0end, _ , _ , mpc::ExplicitMPC, ::LinModel, ::TranscriptionMethod, _ , Z̃
198+
Ŷ0, x̂0end, _ , _ , _ , mpc::ExplicitMPC, ::LinModel, ::TranscriptionMethod, _ , Z̃
199199
)
200200
# in-place operations to reduce allocations :
201201
Ŷ0 .= mul!(Ŷ0, mpc.Ẽ, Z̃) .+ mpc.F

src/controller/nonlinmpc.jl

+28-18
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,17 @@ Inspired from: [User-defined operators with vector outputs](@extref JuMP User-de
578578
function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT<:Real
579579
# ----- common cache for Jfunc, gfuncs, geqfuncs called with floats -------------------
580580
model = mpc.estim.model
581-
nu, ny, nx̂, nϵ, Hp, Hc = model.nu, model.ny, mpc.estim.nx̂, mpc.nϵ, mpc.Hp, mpc.Hc
581+
nu, ny, nx̂, nϵ, nk = model.nu, model.ny, mpc.estim.nx̂, mpc.nϵ, model.nk
582+
Hp, Hc = mpc.Hp, mpc.Hc
582583
ng, nc, neq = length(mpc.con.i_g), mpc.con.nc, mpc.con.neq
583-
nZ̃, nU, nŶ, nX̂ = length(mpc.Z̃), Hp*nu, Hp*ny, Hp*nx̂
584+
nZ̃, nU, nŶ, nX̂, nK = length(mpc.Z̃), Hp*nu, Hp*ny, Hp*nx̂, Hp*nk
584585
nΔŨ, nUe, nŶe = nu*Hc + nϵ, nU + nu, nŶ + ny
585586
strict = Val(true)
586587
myNaN = convert(JNT, NaN) # NaN to force update_simulations! at first call:
587588
::Vector{JNT} = fill(myNaN, nZ̃)
588589
ΔŨ::Vector{JNT} = zeros(JNT, nΔŨ)
589590
x̂0end::Vector{JNT} = zeros(JNT, nx̂)
591+
K0::Vector{JNT} = zeros(JNT, nK)
590592
Ue::Vector{JNT}, Ŷe::Vector{JNT} = zeros(JNT, nUe), zeros(JNT, nŶe)
591593
U0::Vector{JNT}, Ŷ0::Vector{JNT} = zeros(JNT, nU), zeros(JNT, nŶ)
592594
Û0::Vector{JNT}, X̂0::Vector{JNT} = zeros(JNT, nU), zeros(JNT, nX̂)
@@ -596,18 +598,18 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
596598
function Jfunc(Z̃arg::Vararg{T, N}) where {N, T<:Real}
597599
if isdifferent(Z̃arg, Z̃)
598600
Z̃ .= Z̃arg
599-
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
601+
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
600602
end
601603
return obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)::T
602604
end
603-
function Jfunc!(Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
604-
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
605+
function Jfunc!(Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq)
606+
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃)
605607
return obj_nonlinprog!(Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)
606608
end
607609
Z̃_∇J = fill(myNaN, nZ̃)
608610
∇J_context = (
609611
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
610-
Cache(Û0), Cache(X̂0),
612+
Cache(Û0), Cache(K0), Cache(X̂0),
611613
Cache(gc), Cache(g), Cache(geq),
612614
)
613615
∇J_prep = prepare_gradient(Jfunc!, mpc.gradient, Z̃_∇J, ∇J_context...; strict)
@@ -631,19 +633,23 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
631633
gfunc_i = function (Z̃arg::Vararg{T, N}) where {N, T<:Real}
632634
if isdifferent(Z̃arg, Z̃)
633635
Z̃ .= Z̃arg
634-
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
636+
update_predictions!(
637+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃
638+
)
635639
end
636640
return g[i]::T
637641
end
638642
gfuncs[i] = gfunc_i
639643
end
640-
function gfunc!(g, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, geq)
641-
return update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
644+
function gfunc!(g, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, geq)
645+
return update_predictions!(
646+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃
647+
)
642648
end
643649
Z̃_∇g = fill(myNaN, nZ̃)
644650
∇g_context = (
645651
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
646-
Cache(Û0), Cache(X̂0),
652+
Cache(Û0), Cache(K0), Cache(X̂0),
647653
Cache(gc), Cache(geq),
648654
)
649655
# temporarily enable all the inequality constraints for sparsity detection:
@@ -678,19 +684,23 @@ function get_optim_functions(mpc::NonLinMPC, ::JuMP.GenericModel{JNT}) where JNT
678684
geqfunc_i = function (Z̃arg::Vararg{T, N}) where {N, T<:Real}
679685
if isdifferent(Z̃arg, Z̃)
680686
Z̃ .= Z̃arg
681-
update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
687+
update_predictions!(
688+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃
689+
)
682690
end
683691
return geq[i]::T
684692
end
685693
geqfuncs[i] = geqfunc_i
686694
end
687-
function geqfunc!(geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g)
688-
return update_predictions!(ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc, Z̃)
695+
function geqfunc!(geq, Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g)
696+
return update_predictions!(
697+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc, Z̃
698+
)
689699
end
690700
Z̃_∇geq = fill(myNaN, nZ̃)
691701
∇geq_context = (
692702
Cache(ΔŨ), Cache(x̂0end), Cache(Ue), Cache(Ŷe), Cache(U0), Cache(Ŷ0),
693-
Cache(Û0), Cache(X̂0),
703+
Cache(Û0), Cache(K0), Cache(X̂0),
694704
Cache(gc), Cache(g)
695705
)
696706
∇geq_prep = prepare_jacobian(geqfunc!, geq, mpc.jacobian, Z̃_∇geq, ∇geq_context...; strict)
@@ -716,7 +726,7 @@ end
716726

717727
"""
718728
update_predictions!(
719-
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq,
729+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq,
720730
mpc::PredictiveController, Z̃
721731
) -> nothing
722732
@@ -725,17 +735,17 @@ Update in-place all vectors for the predictions of `mpc` controller at decision
725735
The method mutates all the arguments before the `mpc` argument.
726736
"""
727737
function update_predictions!(
728-
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq, mpc::PredictiveController, Z̃
738+
ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K0, X̂0, gc, g, geq, mpc::PredictiveController, Z̃
729739
)
730740
model, transcription = mpc.estim.model, mpc.transcription
731741
U0 = getU0!(U0, mpc, Z̃)
732742
ΔŨ = getΔŨ!(ΔŨ, mpc, transcription, Z̃)
733-
Ŷ0, x̂0end = predict!(Ŷ0, x̂0end, X̂0, Û0, mpc, model, transcription, U0, Z̃)
743+
Ŷ0, x̂0end = predict!(Ŷ0, x̂0end, X̂0, Û0, K0, mpc, model, transcription, U0, Z̃)
734744
Ue, Ŷe = extended_vectors!(Ue, Ŷe, mpc, U0, Ŷ0)
735745
ϵ = getϵ(mpc, Z̃)
736746
gc = con_custom!(gc, mpc, Ue, Ŷe, ϵ)
737747
g = con_nonlinprog!(g, mpc, model, transcription, x̂0end, Ŷ0, gc, ϵ)
738-
geq = con_nonlinprogeq!(geq, X̂0, Û0, mpc, model, transcription, U0, Z̃)
748+
geq = con_nonlinprogeq!(geq, X̂0, Û0, K0, mpc, model, transcription, U0, Z̃)
739749
return nothing
740750
end
741751

src/controller/transcription.jl

+22-16
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ getU0!(U0, mpc::PredictiveController, Z̃) = (mul!(U0, mpc.P̃u, Z̃) .+ mpc.Tu_
10281028

10291029
@doc raw"""
10301030
predict!(
1031-
Ŷ0, x̂0end, _ , _ ,
1031+
Ŷ0, x̂0end, _ , _ , _ ,
10321032
mpc::PredictiveController, model::LinModel, transcription::TranscriptionMethod,
10331033
_ , Z̃
10341034
) -> Ŷ0, x̂0end
@@ -1040,7 +1040,7 @@ the terminal constraints applied on ``\mathbf{x̂}_{k-1}(k+H_p)``. The computati
10401040
identical for any [`TranscriptionMethod`](@ref) if the model is linear.
10411041
"""
10421042
function predict!(
1043-
Ŷ0, x̂0end, _ , _ ,
1043+
Ŷ0, x̂0end, _, _, _,
10441044
mpc::PredictiveController, ::LinModel, ::TranscriptionMethod,
10451045
_ , Z̃
10461046
)
@@ -1052,29 +1052,31 @@ end
10521052

10531053
@doc raw"""
10541054
predict!(
1055-
Ŷ0, x̂0end, X̂0, Û0,
1055+
Ŷ0, x̂0end, X̂0, Û0, K0,
10561056
mpc::PredictiveController, model::NonLinModel, transcription::SingleShooting,
10571057
U0, _
10581058
) -> Ŷ0, x̂0end
10591059
10601060
Compute vectors if `model` is a [`NonLinModel`](@ref) and for [`SingleShooting`](@ref).
10611061
1062-
The method mutates `Ŷ0`, `x̂0end`, `X̂0` and `Û0` arguments.
1062+
The method mutates `Ŷ0`, `x̂0end`, `X̂0`, `Û0` and `K0` arguments.
10631063
"""
10641064
function predict!(
1065-
Ŷ0, x̂0end, X̂0, Û0,
1065+
Ŷ0, x̂0end, X̂0, Û0, K0,
10661066
mpc::PredictiveController, model::NonLinModel, ::SingleShooting,
10671067
U0, _
10681068
)
1069-
nu, nx̂, ny, nd, Hp, Hc = model.nu, mpc.estim.nx̂, model.ny, model.nd, mpc.Hp, mpc.Hc
1069+
nu, nx̂, ny, nd, nk = model.nu, mpc.estim.nx̂, model.ny, model.nd, model.nk
1070+
Hp, Hc = mpc.Hp, mpc.Hc
10701071
D̂0 = mpc.D̂0
10711072
x̂0 = @views mpc.estim.x̂0[1:nx̂]
10721073
d0 = @views mpc.d0[1:nd]
10731074
for j=1:Hp
10741075
u0 = @views U0[(1 + nu*(j-1)):(nu*j)]
10751076
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
1077+
k0 = @views K0[(1 + nk*(j-1)):(nk*j)]
10761078
x̂0next = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
1077-
f̂!(x̂0next, û0, mpc.estim, model, x̂0, u0, d0)
1079+
f̂!(x̂0next, û0, k0, mpc.estim, model, x̂0, u0, d0)
10781080
x̂0next .+= mpc.estim.f̂op .- mpc.estim.x̂op
10791081
x̂0 = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
10801082
d0 = @views D̂0[(1 + nd*(j-1)):(nd*j)]
@@ -1088,7 +1090,7 @@ end
10881090

10891091
@doc raw"""
10901092
predict!(
1091-
Ŷ0, x̂0end, _ , _ ,
1093+
Ŷ0, x̂0end, _ , _ , _ ,
10921094
mpc::PredictiveController, model::NonLinModel, transcription::MultipleShooting,
10931095
U0, Z̃
10941096
) -> Ŷ0, x̂0end
@@ -1098,7 +1100,7 @@ Compute vectors if `model` is a [`NonLinModel`](@ref) and for [`MultipleShooting
10981100
The method mutates `Ŷ0` and `x̂0end` arguments.
10991101
"""
11001102
function predict!(
1101-
Ŷ0, x̂0end, _, _,
1103+
Ŷ0, x̂0end, _, _, _,
11021104
mpc::PredictiveController, model::NonLinModel, ::MultipleShooting,
11031105
U0, Z̃
11041106
)
@@ -1204,17 +1206,20 @@ end
12041206

12051207
"""
12061208
con_nonlinprogeq!(
1207-
geq, X̂0, Û0, mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
1209+
geq, X̂0, Û0, K0
1210+
mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
12081211
)
12091212
12101213
Nonlinear equality constrains for [`NonLinModel`](@ref) and [`MultipleShooting`](@ref).
12111214
1212-
The method mutates the `geq`, `X̂0` and `Û0` vectors in argument.
1215+
The method mutates the `geq`, `X̂0`, `Û0` and `K0` vectors in argument.
12131216
"""
12141217
function con_nonlinprogeq!(
1215-
geq, X̂0, Û0, mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
1218+
geq, X̂0, Û0, K0,
1219+
mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
12161220
)
1217-
nx̂, nu, nd, Hp, Hc = mpc.estim.nx̂, model.nu, model.nd, mpc.Hp, mpc.Hc
1221+
nu, nx̂, ny, nd, nk = model.nu, mpc.estim.nx̂, model.ny, model.nd, model.nk
1222+
Hp, Hc = mpc.Hp, mpc.Hc
12181223
nΔU, nX̂ = nu*Hc, nx̂*Hp
12191224
D̂0 = mpc.D̂0
12201225
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
@@ -1225,7 +1230,8 @@ function con_nonlinprogeq!(
12251230
u0 = @views U0[(1 + nu*(j-1)):(nu*j)]
12261231
û0 = @views Û0[(1 + nu*(j-1)):(nu*j)]
12271232
x̂0next = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
1228-
f̂!(x̂0next, û0, mpc.estim, model, x̂0, u0, d0)
1233+
k0 = @views K0[(1 + nk*(j-1)):(nk*j)]
1234+
f̂!(x̂0next, û0, k0, mpc.estim, model, x̂0, u0, d0)
12291235
x̂0next .+= mpc.estim.f̂op .- mpc.estim.x̂op
12301236
x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂*(j-1)):(nx̂*j)]
12311237
ŝnext = @views geq[(1 + nx̂*(j-1)):(nx̂*j)]
@@ -1235,5 +1241,5 @@ function con_nonlinprogeq!(
12351241
end
12361242
return geq
12371243
end
1238-
con_nonlinprogeq!(geq,_,_,::PredictiveController,::NonLinModel,::SingleShooting, _,_) = geq
1239-
con_nonlinprogeq!(geq,_,_,::PredictiveController,::LinModel,::TranscriptionMethod,_,_) = geq
1244+
con_nonlinprogeq!(geq,_,_,_,::PredictiveController,::NonLinModel,::SingleShooting, _,_)=geq
1245+
con_nonlinprogeq!(geq,_,_,_,::PredictiveController,::LinModel,::TranscriptionMethod,_,_)=geq

src/estimator/construct.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
struct StateEstimatorBuffer{NT<:Real}
22
u ::Vector{NT}
33
::Vector{NT}
4+
k::Vector{NT}
45
::Vector{NT}
56
::Matrix{NT}
67
::Matrix{NT}
@@ -13,17 +14,18 @@ struct StateEstimatorBuffer{NT<:Real}
1314
end
1415

1516
@doc raw"""
16-
StateEstimatorBuffer{NT}(nu::Int, nx̂::Int, nym::Int, ny::Int, nd::Int)
17+
StateEstimatorBuffer{NT}(nu::Int, nx̂::Int, nym::Int, ny::Int, nd::Int, nk::Int=0)
1718
1819
Create a buffer for `StateEstimator` objects for estimated states and measured outputs.
1920
2021
The buffer is used to store intermediate results during estimation without allocating.
2122
"""
2223
function StateEstimatorBuffer{NT}(
23-
nu::Int, nx̂::Int, nym::Int, ny::Int, nd::Int
24+
nu::Int, nx̂::Int, nym::Int, ny::Int, nd::Int, nk::Int=0
2425
) where NT <: Real
2526
u = Vector{NT}(undef, nu)
2627
= Vector{NT}(undef, nu)
28+
k = Vector{NT}(undef, nk)
2729
= Vector{NT}(undef, nx̂)
2830
= Matrix{NT}(undef, nx̂, nx̂)
2931
= Matrix{NT}(undef, nx̂, nx̂)
@@ -33,7 +35,7 @@ function StateEstimatorBuffer{NT}(
3335
= Vector{NT}(undef, ny)
3436
d = Vector{NT}(undef, nd)
3537
empty = Vector{NT}(undef, 0)
36-
return StateEstimatorBuffer{NT}(u, û, x̂, P̂, Q̂, R̂, K̂, ym, ŷ, d, empty)
38+
return StateEstimatorBuffer{NT}(u, û, k, x̂, P̂, Q̂, R̂, K̂, ym, ŷ, d, empty)
3739
end
3840

3941
@doc raw"""

0 commit comments

Comments
 (0)