@@ -229,7 +229,7 @@ struct MovingHorizonEstimator{
229229 P̂arr_old = copy (cov. P̂_0)
230230 Nk = [0 ]
231231 prepared = [false ]
232- test_custom_function_mhe (NT, model, i_ym, He, gc!, nc, x̂op , p, direct)
232+ test_custom_function_mhe (NT, model, i_ym, He, gc!, nc, nx̂ , p, direct)
233233 # force computation of derivatives for the first NLP iteration:
234234 force∇J, force∇g, force∇geq = [true ], [true ], [true ]
235235 buffer = StateEstimatorBuffer {NT} (
@@ -753,31 +753,38 @@ function get_mutating_gc_mhe(NT, gc)
753753end
754754
755755"""
756- test_custom_function_mhe(NT, model::SimModel, i_ym, He, gc!, nc, x̂op , p, direct) -> nothing
756+ test_custom_function_mhe(NT, model::SimModel, i_ym, He, gc!, nc, nx̂ , p, direct) -> nothing
757757
758758Test the custom functions `gc!` at the operating points.
759759
760760This function is called at the end of `MovingHorizonEstimator` construction. It warns the
761- user if the custom constraint `gc!` function crashes at `model` operating points. It
762- will also verify the custom function work with the growing windows, and with the `NaN`
763- values at the boundaries (see [`MovingHorizonEstimator`](@ref) Extended Help for details on
764- the data windows). It should ease troubleshooting of simple bugs e.g.: the user forgets to
765- set the `nc` argument.
761+ user if the custom constraint `gc!` function crashes at `model` initial guesses and
762+ operating points. It will also verify the custom function work with the growing windows, and
763+ with the `NaN` values at the boundaries (see [`MovingHorizonEstimator`](@ref) Extended Help
764+ for details on the data windows). It should ease troubleshooting of simple bugs e.g.: the
765+ user forgets to set the `nc` argument.
766766"""
767- function test_custom_function_mhe (NT, model:: SimModel , i_ym, He, gc!, nc, x̂op, p, direct)
768- nx̂, nŵ, nym = length (x̂op), length (x̂op), length (i_ym)
769- nu, nd = model. nu, model. nd
767+ function test_custom_function_mhe (NT, model:: SimModel , i_ym, He, gc!, nc, nx̂, p, direct)
768+ nŵ, nym = nx̂, length (i_ym)
769+ nu, nd, na = model. nu, model. nd, get_na (model)
770+ x̂s_0 = zeros (NT, nx̂)
771+ x̂s_0[1 : model. nx] .= model. xs_0
772+ âs_0 = get_as_0 (model)
770773 uop, dop, yop = model. uop, model. dop, model. yop
771774 yopm = yop[i_ym]
772- X̂e_He, V̂e_He, Ŵe_He = repeat (x̂op, He+ 1 ), zeros (NT, (He+ 1 )* nym), zeros (NT, (He+ 1 )* nŵ)
773- Ue_He, Yem_He, De_He = repeat (uop, He+ 1 ), repeat (yopm, He+ 1 ), repeat (dop, He+ 1 )
775+ X̂e_He, Âe_He = repeat (x̂s_0, He+ 1 ), repeat (âs_0, He+ 1 )
776+ V̂e_He, Ŵe_He = zeros (NT, (He+ 1 )* nym), zeros (NT, (He+ 1 )* nŵ)
777+ Ue_He, Yem_He, De_He = repeat (uop, He+ 1 ), repeat (yopm, He+ 1 ), repeat (dop, He+ 1 )
774778 x̄ = zeros (NT, nx̂)
775779 P̄ = Hermitian (Matrix {NT} (I, nx̂, nx̂), :L )
776780 ε = zero (NT)
777781 gc = Vector {NT} (undef, nc)
778782 try
779783 for i in 2 : He+ 1
780- X̂e, V̂e, Ŵe = X̂e_He[1 : (i* nx̂)], V̂e_He[1 : (i* nym)], Ŵe_He[1 : (i* nŵ)]
784+ a = X̂e_He[1 : (i* nx̂)]
785+ b = Âe_He[1 : (i* na)]
786+ X̂e, Âe = X̂e_He[1 : (i* nx̂)], Âe_He[1 : (i* na)]
787+ V̂e, Ŵe = V̂e_He[1 : (i* nym)], Ŵe_He[1 : (i* nŵ)]
781788 Ue, Yem, De = Ue_He[1 : (i* nu)], Yem_He[1 : (i* nym)], De_He[1 : (i* nd)]
782789 if direct
783790 V̂e[1 : nym] .= NaN
@@ -788,14 +795,14 @@ function test_custom_function_mhe(NT, model::SimModel, i_ym, He, gc!, nc, x̂op,
788795 end
789796 Ŵe[end - nŵ+ 1 : end ] .= NaN
790797 Ue[end - nu+ 1 : end ] .= NaN
791- gc! (gc, X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ε)
798+ gc! (gc, X̂e, Âe, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, p, ε)
792799 all (isfinite, gc) || error (" the gc function returned non-finite values: gc = $gc " )
793800 end
794801 catch err
795802 @warn (
796803 """
797- Calling the gc function with X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, ε arguments
798- fixed at x̂op= $x̂op , uop=$uop , yop=$yop , dop=$dop ,
804+ Calling the gc function with X̂e, Âe, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, ε arguments
805+ fixed at xs_0= $xs_0 , as_0= $âs_0 , uop=$uop , yop=$yop , dop=$dop ,
799806 P̄=I, x̄=0, p=$p , ϵ=0 failed with the following stacktrace.
800807 Did you forget to set the keyword argument p or nc?
801808 Did you handle the growing data windows with the NaN values at the boundaries?
0 commit comments