Skip to content

Commit 336d032

Browse files
committed
debug: adding .cov where needed
1 parent 9860b06 commit 336d032

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/controller/execute.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,12 @@ prediction horizon ``H_p``.
535535
```jldoctest
536536
julia> mpc = LinMPC(KalmanFilter(LinModel(ss(0.1, 0.5, 1, 0, 4.0)), σR=[√25]), Hp=1, Hc=1);
537537
538-
julia> mpc.estim.model.A[1], mpc.estim.R̂[1], mpc.weights.M_Hp[1], mpc.weights.Ñ_Hc[1]
538+
julia> mpc.estim.model.A[1], mpc.estim.cov.R̂[1], mpc.weights.M_Hp[1], mpc.weights.Ñ_Hc[1]
539539
(0.1, 25.0, 1.0, 0.1)
540540
541541
julia> setmodel!(mpc, LinModel(ss(0.42, 0.5, 1, 0, 4.0)); R̂=[9], M_Hp=[10], Nwt=[0.666]);
542542
543-
julia> mpc.estim.model.A[1], mpc.estim.R̂[1], mpc.weights.M_Hp[1], mpc.weights.Ñ_Hc[1]
543+
julia> mpc.estim.model.A[1], mpc.estim.cov.R̂[1], mpc.weights.M_Hp[1], mpc.weights.Ñ_Hc[1]
544544
(0.42, 9.0, 10.0, 0.666)
545545
```
546546
"""

src/estimator/execute.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ removes the operating points with [`remove_op!`](@ref) and call [`init_estimate!
112112
bumpless manual to automatic transfer. See [`init_estimate!`](@ref) for details.
113113
- Else, `estim.x̂0` is left unchanged. Use [`setstate!`](@ref) to manually modify it.
114114
115-
If applicable, it also sets the error covariance `estim.P̂` to `estim.P̂_0`.
115+
If applicable, it also sets the error covariance `estim.cov.P̂` to `estim.cov.P̂_0`.
116116
117117
# Examples
118118
```jldoctest
@@ -327,7 +327,7 @@ end
327327
"""
328328
setstate!(estim::StateEstimator, x̂[, P̂]) -> estim
329329
330-
Set `estim.x̂0` to `x̂ - estim.x̂op` from the argument `x̂`, and `estim.P̂` to `P̂` if applicable.
330+
Set `estim.x̂0` to `x̂ - estim.x̂op` from the argument `x̂`, and `estim.cov.P̂` to `P̂` if applicable.
331331
332332
The covariance error estimate `P̂` can be set only if `estim` is a [`StateEstimator`](@ref)
333333
that computes it.
@@ -339,11 +339,11 @@ function setstate!(estim::StateEstimator, x̂, P̂=nothing)
339339
return estim
340340
end
341341

342-
"Set the covariance error estimate `estim.P̂` to `P̂`."
342+
"Set the covariance error estimate `estim.cov.P̂` to `P̂`."
343343
function setstate_cov!(estim::StateEstimator, P̂)
344344
if !isnothing(P̂)
345345
size(P̂) == (estim.nx̂, estim.nx̂) || error("P̂ size must be $((estim.nx̂, estim.nx̂))")
346-
estim.P̂ .= to_hermitian(P̂)
346+
estim.cov.P̂ .= to_hermitian(P̂)
347347
end
348348
return nothing
349349
end
@@ -449,7 +449,7 @@ function setmodel_estimator!(estim::StateEstimator, model, _ , _ , _ , Q̂, R̂)
449449
estim.f̂op .= f̂op
450450
estim.x̂0 .-= estim.x̂op # convert x̂ to x̂0 with the new operating point
451451
# --- update covariance matrices ---
452-
!isnothing(Q̂) && (estim.Q̂ .= to_hermitian(Q̂))
453-
!isnothing(R̂) && (estim.R̂ .= to_hermitian(R̂))
452+
!isnothing(Q̂) && (estim.cov.Q̂ .= to_hermitian(Q̂))
453+
!isnothing(R̂) && (estim.cov.R̂ .= to_hermitian(R̂))
454454
return nothing
455455
end

src/estimator/kalman.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ end
443443
@doc raw"""
444444
correct_estimate!(estim::KalmanFilter, y0m, d0)
445445
446-
Correct `estim.x̂0` and `estim.P̂` using the time-varying [`KalmanFilter`](@ref).
446+
Correct `estim.x̂0` and `estim.cov.P̂` using the time-varying [`KalmanFilter`](@ref).
447447
448448
It computes the corrected state estimate ``\mathbf{x̂}_{k}(k)`` estimation covariance
449449
``\mathbf{P̂}_{k}(k)``.
@@ -456,7 +456,7 @@ end
456456
@doc raw"""
457457
update_estimate!(estim::KalmanFilter, y0m, d0, u0)
458458
459-
Update [`KalmanFilter`](@ref) state `estim.x̂0` and estimation error covariance `estim.P̂`.
459+
Update [`KalmanFilter`](@ref) state `estim.x̂0` and estimation error covariance `estim.cov.P̂`.
460460
461461
It implements the classical time-varying Kalman Filter based on the process model described
462462
in [`SteadyKalmanFilter`](@ref). If `estim.direct == false`, it first corrects the estimate
@@ -790,7 +790,7 @@ end
790790
@doc raw"""
791791
update_estimate!(estim::UnscentedKalmanFilter, y0m, d0, u0)
792792
793-
Update [`UnscentedKalmanFilter`](@ref) state `estim.x̂0` and covariance estimate `estim.P̂`.
793+
Update [`UnscentedKalmanFilter`](@ref) state `estim.x̂0` and covariance estimate `estim.cov.P̂`.
794794
795795
It implements the unscented Kalman Filter based on the generalized unscented transform[^3].
796796
See [`init_ukf`](@ref) for the definition of the constants ``\mathbf{m̂, Ŝ}`` and ``γ``. The
@@ -1107,7 +1107,7 @@ end
11071107
@doc raw"""
11081108
update_estimate!(estim::ExtendedKalmanFilter, y0m, d0, u0)
11091109
1110-
Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂0` and covariance `estim.P̂`.
1110+
Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂0` and covariance `estim.cov.P̂`.
11111111
11121112
The equations are similar to [`update_estimate!(::KalmanFilter)`](@ref) but with the
11131113
substitutions ``\mathbf{Ĉ^m = Ĥ^m}(k)`` and ``\mathbf{Â = F̂}(k)``, the Jacobians of the
@@ -1158,7 +1158,7 @@ function update_estimate!(estim::ExtendedKalmanFilter{NT}, y0m, d0, u0) where NT
11581158
return predict_estimate_kf!(estim, u0, d0, estim.F̂)
11591159
end
11601160

1161-
"Set `estim.P̂` to `estim.P̂_0` for the time-varying Kalman Filters."
1161+
"Set `estim.cov.P̂` to `estim.cov.P̂_0` for the time-varying Kalman Filters."
11621162
function init_estimate_cov!(
11631163
estim::Union{KalmanFilter, UnscentedKalmanFilter, ExtendedKalmanFilter}, _ , _ , _
11641164
)

src/estimator/mhe/execute.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function init_estimate_cov!(estim::MovingHorizonEstimator, _ , d0, u0)
1616
estim.D0[1:estim.model.nd] .= d0
1717
end
1818
estim.lastu0 .= u0
19-
# estim.P̂_0 is in fact P̂(-1|-1) is estim.direct==false, else P̂(-1|0)
19+
# estim.cov.P̂_0 is in fact P̂(-1|-1) is estim.direct==false, else P̂(-1|0)
2020
invert_cov!(estim, estim.cov.P̂_0)
2121
estim.P̂arr_old .= estim.cov.P̂_0
2222
estim.x̂0arr_old .= 0
@@ -793,16 +793,16 @@ function setmodel_estimator!(
793793
estim.x̂0arr_old .-= x̂op
794794
# --- covariance matrices ---
795795
if !isnothing(Q̂)
796-
estim.Q̂ .= to_hermitian(Q̂)
796+
estim.cov.Q̂ .= to_hermitian(Q̂)
797797
invQ̂ = Hermitian(estim.buffer.Q̂, :L)
798-
invQ̂ .= estim.
798+
invQ̂ .= estim.cov.
799799
inv!(invQ̂)
800800
estim.invQ̂_He .= Hermitian(repeatdiag(invQ̂, He), :L)
801801
end
802802
if !isnothing(R̂)
803-
estim.R̂ .= to_hermitian(R̂)
803+
estim.cov.R̂ .= to_hermitian(R̂)
804804
invR̂ = Hermitian(estim.buffer.R̂, :L)
805-
invR̂ .= estim.
805+
invR̂ .= estim.cov.
806806
inv!(invR̂)
807807
estim.invR̂_He .= Hermitian(repeatdiag(invR̂, He), :L)
808808
end

test/3_test_predictive_control.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ end
215215
@test initstate!(mpc1, [10, 50], [50, 30+1]) [zeros(3); [1]]
216216
setstate!(mpc1, [1,2,3,4], diagm(.1:.1:.4))
217217
@test mpc1.estim.x̂0 [1,2,3,4]
218-
@test mpc1.estim. diagm(.1:.1:.4)
219-
setstate!(mpc1, [0,0,0,0], mpc1.estim.P̂_0)
218+
@test mpc1.estim.cov. diagm(.1:.1:.4)
219+
setstate!(mpc1, [0,0,0,0], mpc1.estim.cov.P̂_0)
220220
preparestate!(mpc1, [50, 30])
221221
updatestate!(mpc1, mpc1.estim.model.uop, [50, 30])
222222
@test mpc1.estim.x̂0 [0,0,0,0]

0 commit comments

Comments
 (0)