599599
600600@doc raw """
601601 init_defectmat(
602- model::LinModel, estim, transcription::MultipleShooting, Hp, Hc, nb
602+ model::LinModel, estim::StateEstimator , transcription::MultipleShooting, Hp, Hc, nb
603603 ) -> ES, GS, JS, KS, VS, BS
604604
605605Init the matrices for computing the defects over the predicted states.
709709
710710@doc raw """
711711 init_defectmat(
712- model::SimModel, estim ::StateEstimator, transcription::CollocationMethod , Hp, Hc, _
713- )
712+ model::SimModel, ::StateEstimator, ::TranscriptionMethod , Hp, Hc, _
713+ ) -> ES, GS, JS, KS, VS, BS
714714
715715Init the matrices for computing the defects of the stochastic states only.
716716
@@ -751,7 +751,7 @@ The matrices ``\mathbf{E_S}`` and ``\mathbf{K_S}`` are defined in the Extended H
751751 - else ``\m athbf{E_S} = [\b egin{smallmatrix} \m athbf{E_{S}^{Δu}} & \m athbf{E_{S}^{x̂}} \e nd{smallmatrix}]``
752752"""
753753function init_defectmat (
754- model:: SimModel , estim:: StateEstimator{NT} , transcription:: CollocationMethod , Hp, Hc, _
754+ model:: SimModel , estim:: StateEstimator{NT} , transcription:: TranscriptionMethod , Hp, Hc, _
755755) where {NT<: Real }
756756 nu, nx, nd, nx̂, nxs = model. nu, model. nx, model. nd, estim. nx̂, estim. nxs
757757 nZ = get_nZ (estim, transcription, Hp, Hc)
@@ -780,13 +780,13 @@ end
780780
781781"""
782782 init_defectmat(
783- model::SimModel, estim::InternalModel{NT}, transcription::CollocationMethod , Hp, Hc, _
783+ model::SimModel, estim::InternalModel, ::TranscriptionMethod , Hp, Hc, _
784784 ) -> ES, GS, JS, KS, VS, BS
785785
786786Return empty matrices for [`InternalModel`](@ref) (state vector is not augmented).
787787"""
788788function init_defectmat (
789- model:: SimModel , estim:: InternalModel{NT} , transcription:: CollocationMethod , Hp, Hc, _
789+ model:: SimModel , estim:: InternalModel{NT} , transcription:: TranscriptionMethod , Hp, Hc, _
790790) where {NT<: Real }
791791 nx̂, nu, nd = estim. nx̂, model. nu, model. nd
792792 nZ = get_nZ (estim, transcription, Hp, Hc)
@@ -801,13 +801,13 @@ end
801801
802802"""
803803 init_defectmat(
804- model::SimModel, estim, transcription ::TranscriptionMethod, Hp, Hc, nb
804+ model::SimModel, estim::StateEstimator, ::TranscriptionMethod, Hp, Hc, nb
805805 ) -> ES, GS, JS, KS, VS, BS
806806
807- Return empty matrices for all other cases (N/A).
807+ Return empty matrices for [`SingleShooting`](@ref) transcription (N/A).
808808"""
809809function init_defectmat (
810- model:: SimModel , estim:: StateEstimator{NT} , transcription:: TranscriptionMethod , Hp, Hc, _
810+ model:: SimModel , estim:: StateEstimator{NT} , transcription:: SingleShooting , Hp, Hc, _
811811) where {NT<: Real }
812812 nx̂, nu, nd = estim. nx̂, model. nu, model. nd
813813 nZ = get_nZ (estim, transcription, Hp, Hc)
@@ -1042,8 +1042,15 @@ function linconstrainteq!(
10421042 return nothing
10431043end
10441044
1045+ """
1046+ linconstrainteq!(
1047+ mpc::PredictiveController, ::SimModel, ::StateEstimator, ::TranscriptionMethod
1048+ )
1049+
1050+ Do the same for [`SimModel`](@ref), but using simpler equations (stochastic defects only).
1051+ """
10451052function linconstrainteq! (
1046- mpc:: PredictiveController , :: SimModel , :: StateEstimator , :: CollocationMethod
1053+ mpc:: PredictiveController , :: SimModel , :: StateEstimator , :: TranscriptionMethod
10471054)
10481055 FS = mpc. con. FS
10491056 # the only non-zeros matrices are ES and KS:
@@ -1053,8 +1060,10 @@ function linconstrainteq!(
10531060 JuMP. set_normalized_rhs (linconeq, mpc. con. beq)
10541061 return nothing
10551062end
1063+ " Do nothing for [`InternalModel`](@ref) (state is not augmented)."
10561064linconstrainteq! (:: PredictiveController , :: SimModel , :: InternalModel , :: TranscriptionMethod ) = nothing
1057- linconstrainteq! (:: PredictiveController , :: SimModel , :: StateEstimator , :: TranscriptionMethod ) = nothing
1065+ " Do nothing for [`SingleShooting`](@ref) (N/A)."
1066+ linconstrainteq! (:: PredictiveController , :: SimModel , :: StateEstimator , :: SingleShooting ) = nothing
10581067
10591068@doc raw """
10601069 set_warmstart!(mpc::PredictiveController, ::SingleShooting, Z̃var) -> Z̃s
@@ -1414,7 +1423,8 @@ function con_nonlinprogeq!(
14141423 nΔU, nX̂ = nu* Hc, nx̂* Hp
14151424 f_threads = transcription. f_threads
14161425 D̂0 = mpc. D̂0
1417- X̂0_Z̃ = @views Z̃[(nΔU+ 1 ): (nΔU+ nX̂)]
1426+ X̂0_Z̃ = @views Z̃[(nΔU+ 1 ): (nΔU+ nX̂)]
1427+ disturbedinput! (Û0, mpc, mpc. estim, U0, X̂0_Z̃)
14181428 @threadsif f_threads for j= 1 : Hp
14191429 if j < 2
14201430 x̂0_Z̃ = @views mpc. estim. x̂0[1 : nx̂]
@@ -1423,13 +1433,18 @@ function con_nonlinprogeq!(
14231433 x̂0_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 2 )): (nx̂* (j- 1 ))]
14241434 d̂0 = @views D̂0[(1 + nd* (j- 2 )): (nd* (j- 1 ))]
14251435 end
1426- u0 = @views U0[(1 + nu* (j- 1 )): (nu* j)]
14271436 û0 = @views Û0[(1 + nu* (j- 1 )): (nu* j)]
14281437 k = @views K[(1 + nk* (j- 1 )): (nk* j)]
14291438 x̂0next = @views X̂0[(1 + nx̂* (j- 1 )): (nx̂* j)]
14301439 x̂0next_Z̃ = @views X̂0_Z̃[(1 + nx̂* (j- 1 )): (nx̂* j)]
14311440 ŝnext = @views geq[(1 + nx̂* (j- 1 )): (nx̂* j)]
14321441 f̂! (x̂0next, û0, k, mpc. estim, model, x̂0_Z̃, u0, d̂0)
1442+
1443+ @views xdnext = x̂0next[1 : model. nx], x̂0next[model. nx+ 1 : end ]
1444+
1445+ f! (xdnext, k, model, xd, û0, d0, model. p)
1446+
1447+
14331448 ŝnext .= @. x̂0next - x̂0next_Z̃
14341449 end
14351450 return geq
0 commit comments