Skip to content

Commit 311cfa3

Browse files
committed
debug: sometimes allow setmodel! on MPC based on SteadyKalmanFilter and Luenberger
Allow it if and only if the plant model and the covariance matrices do not change. This allow calling `setmodel!` on `mpc` to modify the weights but nothing else.
1 parent dd3a5f2 commit 311cfa3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/estimator/kalman.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,12 @@ function SteadyKalmanFilter(
199199
return SteadyKalmanFilter{NT, SM}(model, i_ym, nint_u, nint_ym, Q̂, R̂; direct)
200200
end
201201

202-
"Throw an error if `setmodel!` is called on a SteadyKalmanFilter"
203-
function setmodel_estimator!(::SteadyKalmanFilter, args...)
204-
error("SteadyKalmanFilter does not support setmodel! (use KalmanFilter instead)")
202+
"Throw an error if `setmodel!` is called on a SteadyKalmanFilter w/o the default values."
203+
function setmodel_estimator!(estim::SteadyKalmanFilter, model, _ , _ , _ , Q̂, R̂)
204+
if estim.model !== model || !isnothing(Q̂) || !isnothing(R̂)
205+
error("SteadyKalmanFilter does not support setmodel! (use KalmanFilter instead)")
206+
end
207+
return nothing
205208
end
206209

207210
@doc raw"""

src/estimator/luenberger.jl

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

138-
"Throw an error if `setmodel!` is called on `Luenberger` observer."
139-
setmodel_estimator!(::Luenberger, args...) = error("Luenberger does not support setmodel!")
138+
"Throw an error if `setmodel!` is called on `Luenberger` observer w/o the default values."
139+
function setmodel!(estim::Luenberger, model, args...)
140+
if estim.model !== model
141+
error("Luenberger does not support setmodel!")
142+
end
143+
return nothing
144+
end

0 commit comments

Comments
 (0)