Skip to content

Commit f36f790

Browse files
committed
Removed some Union{} in fields
1 parent 3088e83 commit f36f790

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

example/juMPC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function test_mpc(model, mpc)
129129
return u_data, y_data, r_data, d_data
130130
end
131131

132-
u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
132+
@time u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
133133
#profview u_data, y_data, r_data, d_data = test_mpc(linModel4, mpc)
134134
#=
135135
using PlotThemes, Plots

src/estimator/internal_model.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ struct InternalModel{M<:SimModel} <: StateEstimator
33
::Vector{Float64}
44
x̂d::Vector{Float64}
55
x̂s::Vector{Float64}
6-
i_ym::IntRangeOrVector
6+
i_ym::Vector{Int}
77
nx̂::Int
88
nym::Int
99
nyu::Int
@@ -36,6 +36,7 @@ struct InternalModel{M<:SimModel} <: StateEstimator
3636
nx̂ = model.nx
3737
nxs = size(As,1)
3838
Âs, B̂s = init_internalmodel(As, Bs, Cs, Ds)
39+
i_ym = collect(i_ym)
3940
x̂d == copy(model.x) # x̂ and x̂d are same object (updating x̂d will update x̂)
4041
x̂s = zeros(nxs)
4142
return new(model, x̂, x̂d, x̂s, i_ym, nx̂, nym, nyu, nxs, As, Bs, Cs, Ds, Âs, B̂s)

src/estimator/kalman.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct SteadyKalmanFilter <: StateEstimator
22
model::LinModel
33
::Vector{Float64}
4-
i_ym::IntRangeOrVector
4+
i_ym::Vector{Int}
55
nx̂::Int
66
nym::Int
77
nyu::Int
@@ -39,6 +39,7 @@ struct SteadyKalmanFilter <: StateEstimator
3939
"parameter or use the time-varying KalmanFilter.")
4040
end
4141
end
42+
i_ym = collect(i_ym)
4243
= Hermitian(Q̂, :L)
4344
= Hermitian(R̂, :L)
4445
= [copy(model.x); zeros(nxs)]
@@ -172,7 +173,7 @@ struct KalmanFilter <: StateEstimator
172173
model::LinModel
173174
::Vector{Float64}
174175
::Hermitian{Float64, Matrix{Float64}}
175-
i_ym::IntRangeOrVector
176+
i_ym::Vector{Int}
176177
nx̂::Int
177178
nym::Int
178179
nyu::Int
@@ -201,6 +202,7 @@ struct KalmanFilter <: StateEstimator
201202
As, _ , Cs, _ = stoch_ym2y(model, i_ym, Asm, [], Csm, [])
202203
f̂, ĥ, Â, B̂u, Ĉ, B̂d, D̂d = augment_model(model, As, Cs)
203204
Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] # measured outputs ym only
205+
i_ym = collect(i_ym)
204206
= [copy(model.x); zeros(nxs)]
205207
P̂0 = Hermitian(P̂0, :L)
206208
= Hermitian(Q̂, :L)
@@ -324,7 +326,7 @@ struct UnscentedKalmanFilter{M<:SimModel} <: StateEstimator
324326
model::M
325327
::Vector{Float64}
326328
::Hermitian{Float64, Matrix{Float64}}
327-
i_ym::IntRangeOrVector
329+
i_ym::Vector{Int}
328330
nx̂::Int
329331
nym::Int
330332
nyu::Int
@@ -352,6 +354,7 @@ struct UnscentedKalmanFilter{M<:SimModel} <: StateEstimator
352354
As, _ , Cs, _ = stoch_ym2y(model, i_ym, Asm, [], Csm, [])
353355
f̂, ĥ = augment_model(model, As, Cs)
354356
nσ, γ, m̂, Ŝ = init_ukf(nx̂, α, β, κ)
357+
i_ym = collect(i_ym)
355358
= [copy(model.x); zeros(nxs)]
356359
P̂0 = Hermitian(P̂0, :L)
357360
= Hermitian(Q̂, :L)

src/estimator/luenberger.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct Luenberger <: StateEstimator
22
model::LinModel
33
::Vector{Float64}
4-
i_ym::IntRangeOrVector
4+
i_ym::Vector{Int}
55
nx̂::Int
66
nym::Int
77
nyu::Int
@@ -29,6 +29,7 @@ struct Luenberger <: StateEstimator
2929
f̂, ĥ, Â, B̂u, Ĉ, B̂d, D̂d = augment_model(model, As, Cs)
3030
Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] # measured outputs ym only
3131
K = L
32+
i_ym = collect(i_ym)
3233
= [copy(model.x); zeros(nxs)]
3334
return new(
3435
model,

src/predictive_control.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract type PredictiveController end
2121

2222
mutable struct OptimInfo
2323
ΔŨ::Vector{Float64}
24-
ϵ ::Union{Nothing, Float64}
24+
ϵ ::Float64
2525
J ::Float64
2626
u ::Vector{Float64}
2727
U ::Vector{Float64}
@@ -117,7 +117,7 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
117117
b = b[i_nonInf]
118118
@constraint(optim, constraint_lin, A*ΔŨ .≤ b)
119119
ΔŨ0 = zeros(nvar)
120-
ϵ = isinf(C) ? nothing : 0.0 # C = Inf means hard constraints only
120+
ϵ = isinf(C) ? NaN : 0.0 # C = Inf means hard constraints only
121121
u, U = copy(model.uop), repeat(model.uop, Hp)
122122
ŷ, Ŷ = copy(model.yop), repeat(model.yop, Hp)
123123
ŷs, Ŷs = zeros(ny), zeros(ny*Hp)
@@ -347,7 +347,7 @@ struct NonLinMPC{S<:StateEstimator} <: PredictiveController
347347
#b = b[i_nonInf]
348348
#@constraint(optim, constraint_lin, A*ΔŨ .≤ b)
349349
ΔŨ0 = zeros(nvar)
350-
ϵ = isinf(C) ? nothing : 0.0 # C = Inf means hard constraints only
350+
ϵ = isinf(C) ? NaN : 0.0 # C = Inf means hard constraints only
351351
u, U = copy(model.uop), repeat(model.uop, Hp)
352352
ŷ, Ŷ = copy(model.yop), repeat(model.yop, Hp)
353353
ŷs, Ŷs = zeros(ny), zeros(ny*Hp)
@@ -841,7 +841,7 @@ Write `mpc.info` with the [`LinMPC`](@ref) optimization results.
841841
"""
842842
function write_info!(mpc::LinMPC, ΔŨ, J, ŷs, Ŷs, lastu, F, ym, d)
843843
mpc.info.ΔŨ = ΔŨ
844-
mpc.info.ϵ = isinf(mpc.C) ? nothing : ΔŨ[end]
844+
mpc.info.ϵ = isinf(mpc.C) ? NaN : ΔŨ[end]
845845
mpc.info.J = J
846846
mpc.info.U = mpc.S̃_Hp*ΔŨ + mpc.T_Hp*lastu
847847
mpc.info.u = mpc.info.U[1:mpc.estim.model.nu]

0 commit comments

Comments
 (0)