Skip to content

Commit 63b4387

Browse files
committed
test: adapt tests to new cov field
1 parent 336d032 commit 63b4387

File tree

8 files changed

+161
-125
lines changed

8 files changed

+161
-125
lines changed

src/ModelPredictiveControl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ include("plot_sim.jl")
5454
@compile_workload begin
5555
# all calls in this block will be precompiled, regardless of whether
5656
# they belong to your package or not (on Julia 1.8 and higher)
57-
# include("precompile.jl")
57+
include("precompile.jl")
5858
end
5959
end
6060

src/estimator/construct.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,33 @@ struct KalmanCovariances{
6464
= Hermitian(R̂, :L)
6565
# the following variables are only for the moving horizon estimator:
6666
invP̄, invQ̂, invR̂ = copy(P̂_0), copy(Q̂), copy(R̂)
67-
inv!(invP̄)
68-
inv!(invQ̂)
69-
inv!(invR̂)
67+
try
68+
inv!(invP̄)
69+
catch err
70+
if err isa PosDefException
71+
error("P̂_0 is not positive definite")
72+
else
73+
rethrow()
74+
end
75+
end
76+
try
77+
inv!(invQ̂)
78+
catch err
79+
if err isa PosDefException
80+
error("Q̂ is not positive definite")
81+
else
82+
rethrow()
83+
end
84+
end
85+
try
86+
inv!(invR̂)
87+
catch err
88+
if err isa PosDefException
89+
error("R̂ is not positive definite")
90+
else
91+
rethrow()
92+
end
93+
end
7094
invQ̂_He = repeatdiag(invQ̂, He)
7195
invR̂_He = repeatdiag(invR̂, He)
7296
invQ̂_He = Hermitian(invQ̂_He, :L)
@@ -80,7 +104,7 @@ function KalmanCovariances(
80104
model::SimModel{NT}, i_ym, nint_u, nint_ym, Q̂, R̂, P̂_0=nothing, He=1
81105
) where {NT<:Real}
82106
validate_kfcov(model, i_ym, nint_u, nint_ym, Q̂, R̂, P̂_0)
83-
return KalmanCovariances{NT}(model, i_ym, nint_u, nint_ym, NT.(Q̂), NT.(R̂), P̂_0, He)
107+
return KalmanCovariances{NT}(model, i_ym, nint_u, nint_ym, NT.(Q̂), NT.(R̂), NT.(P̂_0), He)
84108
end
85109

86110
"""

src/estimator/internal_model.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ function init_internalmodel(As, Bs, Cs, Ds)
225225
end
226226

227227
"Throw an error if P̂ != nothing."
228-
function setstate_cov!(estim::InternalModel, P̂)
229-
== nothing || error("InternalModel does not compute an estimation covariance matrix P̂.")
228+
function setstate_cov!(::InternalModel, P̂)
229+
isnothing(P̂) || error("InternalModel does not compute an estimation covariance matrix P̂.")
230230
return nothing
231231
end
232232

src/estimator/kalman.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ function setmodel_estimator!(estim::SteadyKalmanFilter, model, _ , _ , _ , Q̂,
214214
return nothing
215215
end
216216

217+
"Throw an error if P̂ != nothing."
218+
function setstate_cov!(::SteadyKalmanFilter, P̂)
219+
isnothing(P̂) || error("SteadyKalmanFilter does not compute an estimation covariance matrix P̂.")
220+
return nothing
221+
end
222+
217223
@doc raw"""
218224
correct_estimate!(estim::SteadyKalmanFilter, y0m, d0)
219225

src/estimator/luenberger.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function update_estimate!(estim::Luenberger, y0m, d0, u0)
135135
end
136136

137137
"Throw an error if P̂ != nothing."
138-
function setstate_cov!(estim::Luenberger, P̂)
139-
== nothing || error("Luenberger does not compute an estimation covariance matrix P̂.")
138+
function setstate_cov!(::Luenberger, P̂)
139+
isnothing(P̂) || error("Luenberger does not compute an estimation covariance matrix P̂.")
140140
return nothing
141141
end
142142

src/estimator/manual.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,10 @@ end
147147
148148
Do nothing for [`ManualEstimator`](@ref).
149149
"""
150-
update_estimate!(estim::ManualEstimator, y0m, d0, u0) = nothing
150+
update_estimate!(::ManualEstimator, y0m, d0, u0) = nothing
151+
152+
"Throw an error if P̂ != nothing."
153+
function setstate_cov!(::ManualEstimator, P̂)
154+
isnothing(P̂) || error("ManualEstimator does not compute an estimation covariance matrix P̂.")
155+
return nothing
156+
end

src/estimator/mhe/execute.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ end
686686
con_nonlinprog!(g, ::MovingHorizonEstimator, ::LinModel, _ , _ , _ ) = g
687687

688688
"Throw an error if P̂ != nothing."
689-
function setstate_cov!(estim::MovingHorizonEstimator, P̂)
690-
== nothing || error("MovingHorizonEstimator does not compute an estimation covariance matrix P̂.")
689+
function setstate_cov!(::MovingHorizonEstimator, P̂)
690+
isnothing(P̂) || error("MovingHorizonEstimator does not compute an estimation covariance matrix P̂.")
691691
return nothing
692692
end
693693

0 commit comments

Comments
 (0)