@@ -51,7 +51,7 @@ struct MovingHorizonEstimator{
5151 JM<: JuMP.GenericModel ,
5252 GB<: AbstractADType ,
5353 JB<: AbstractADType ,
54- CE<: StateEstimator ,
54+ CE<: KalmanEstimator ,
5555} <: StateEstimator{NT}
5656 model:: SM
5757 cov :: KC
@@ -121,7 +121,7 @@ struct MovingHorizonEstimator{
121121 JM<: JuMP.GenericModel ,
122122 GB<: AbstractADType ,
123123 JB<: AbstractADType ,
124- CE<: StateEstimator {NT}
124+ CE<: KalmanEstimator {NT}
125125 }
126126 nu, ny, nd, nk = model. nu, model. ny, model. nd, model. nk
127127 He < 1 && throw (ArgumentError (" Estimation horizon He should be ≥ 1" ))
@@ -436,6 +436,7 @@ function MovingHorizonEstimator(
436436) where {NT<: Real , SM<: SimModel{NT} , JM<: JuMP.GenericModel , CE<: StateEstimator{NT} }
437437 P̂_0, Q̂, R̂ = to_mat (P̂_0), to_mat (Q̂), to_mat (R̂)
438438 cov = KalmanCovariances (model, i_ym, nint_u, nint_ym, Q̂, R̂, P̂_0, He)
439+ validate_covestim (cov, covestim)
439440 return MovingHorizonEstimator {NT} (
440441 model,
441442 He, i_ym, nint_u, nint_ym, cov, Cwt,
@@ -444,13 +445,26 @@ function MovingHorizonEstimator(
444445 )
445446end
446447
448+
447449function default_covestim_mhe (model:: LinModel , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct)
448450 return KalmanFilter (model, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct)
449451end
450452function default_covestim_mhe (model:: SimModel , i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct)
451453 return UnscentedKalmanFilter (model, i_ym, nint_u, nint_ym, P̂_0, Q̂, R̂; direct)
452454end
453455
456+ " Validate covestim type and dimensions."
457+ function validate_covestim (cov:: KalmanCovariances , covestim:: KalmanEstimator )
458+ if size (cov. P̂) != size (covestim. cov. P̂)
459+ throw (ArgumentError (" estimation covariance covestim.cov.P̂ size does not match the MHE" ))
460+ end
461+ return nothing
462+ end
463+ function validate_covestim (:: KalmanCovariances , :: StateEstimator )
464+ error ( " covestim argument must be a SteadyKalmanFilter, KalmanFilter, " *
465+ " ExtendedKalmanFilter or UnscentedKalmanFilter" )
466+ end
467+
454468@doc raw """
455469 setconstraint!(estim::MovingHorizonEstimator; <keyword arguments>) -> estim
456470
0 commit comments