Skip to content

Commit f9c5202

Browse files
committed
added: validate model and transcription combo
1 parent 55e4aa9 commit f9c5202

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/controller/explicitmpc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct ExplicitMPC{
5050
R̂y, R̂u, Tu_lastu0 = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
5151
lastu0 = zeros(NT, nu)
5252
transcription = SingleShooting() # explicit MPC only supports SingleShooting
53+
validate_transcription(model, transcription)
5354
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
5455
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
5556
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)

src/controller/linmpc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct LinMPC{
6363
# dummy vals (updated just before optimization):
6464
R̂y, R̂u, Tu_lastu0 = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
6565
lastu0 = zeros(NT, nu)
66+
validate_transcription(model, transcription)
6667
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
6768
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
6869
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct NonLinMPC{
8686
# dummy vals (updated just before optimization):
8787
R̂y, R̂u, Tu_lastu0 = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
8888
lastu0 = zeros(NT, nu)
89+
validate_transcription(model, transcription)
8990
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
9091
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc, nb)
9192
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(

src/controller/transcription.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ a similar algorithm complexity.
100100
struct TrapezoidalCollocation <: CollocationMethod end
101101

102102

103+
function validate_transcription(::LinModel, ::CollocationMethod)
104+
throw(ArgumentError("Collocation methods are not supported for LinModel."))
105+
return nothing
106+
end
107+
function validate_transcription(::NonLinModel{<:Real, <:EmptySolver}, ::CollocationMethod)
108+
throw(ArgumentError("Collocation methods require continuous-time NonLinModel."))
109+
return nothing
110+
end
111+
validate_transcription(::SimModel, ::TranscriptionMethod) = nothing
112+
103113
@doc raw"""
104114
init_ZtoΔU(estim::StateEstimator, transcription::TranscriptionMethod, Hp, Hc) -> PΔu
105115
@@ -206,7 +216,9 @@ function init_ZtoU(
206216
return Pu, Tu
207217
end
208218

209-
init_PUmat( _ , ::SingleShooting, _ , _ , PuDagger) = PuDagger
219+
function init_PUmat(_,::SingleShooting,_,_,PuDagger::AbstractMatrix{NT}) where NT<:Real
220+
return PuDagger
221+
end
210222
function init_PUmat(
211223
estim, ::TranscriptionMethod, Hp, _ , PuDagger::AbstractMatrix{NT}
212224
) where NT<:Real

0 commit comments

Comments
 (0)