Skip to content

Commit 50363db

Browse files
committed
replace d=Float64[] with empty calls
1 parent ad84df7 commit 50363db

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

src/controller/explicitmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ExplicitMPC{S<:StateEstimator} <: PredictiveController
4242
L_Hp = Diagonal{Float64}(repeat(Lwt, Hp))
4343
C = Cwt
4444
# manipulated input setpoint predictions are constant over Hp :
45-
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = Float64[]
45+
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = empty(estim.x̂)
4646
R̂y = zeros(ny* Hp) # dummy R̂y (updated just before optimization)
4747
S_Hp, T_Hp, S_Hc, T_Hc = init_ΔUtoU(nu, Hp, Hc)
4848
E, F, G, J, K, Q = init_predmat(estim, model, Hp, Hc)

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct LinMPC{S<:StateEstimator} <: PredictiveController
4242
L_Hp = Diagonal{Float64}(repeat(Lwt, Hp))
4343
C = Cwt
4444
# manipulated input setpoint predictions are constant over Hp :
45-
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = Float64[]
45+
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = empty(estim.x̂)
4646
R̂y = zeros(ny* Hp) # dummy R̂y (updated just before optimization)
4747
S_Hp, T_Hp, S_Hc, T_Hc = init_ΔUtoU(nu, Hp, Hc)
4848
E, F, G, J, K, Q = init_predmat(estim, model, Hp, Hc)

src/controller/nonlinmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct NonLinMPC{S<:StateEstimator, JEfunc<:Function} <: PredictiveController
4646
L_Hp = Diagonal(convert(Vector{Float64}, repeat(Lwt, Hp)))
4747
C = Cwt
4848
# manipulated input setpoint predictions are constant over Hp :
49-
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = Float64[]
49+
R̂u = ~iszero(Lwt) ? repeat(ru, Hp) : R̂u = empty(estim.x̂)
5050
R̂y = zeros(ny* Hp) # dummy R̂y (updated just before optimization)
5151
S_Hp, T_Hp, S_Hc, T_Hc = init_ΔUtoU(nu, Hp, Hc)
5252
E, F, G, J, K, Q = init_predmat(estim, model, Hp, Hc)

src/estimator/internal_model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function init_internalmodel(As, Bs, Cs, Ds)
187187
end
188188

189189
@doc raw"""
190-
update_estimate!(estim::InternalModel, u, ym, d=Float64[]) -> x̂d
190+
update_estimate!(estim::InternalModel, u, ym, d=empty(estim.x̂)) -> x̂d
191191
192192
Update `estim.x̂` \ `x̂d` \ `x̂s` with current inputs `u`, measured outputs `ym` and dist. `d`.
193193
@@ -201,7 +201,7 @@ The [`InternalModel`](@ref) updates the deterministic `x̂d` and stochastic `x̂
201201
This estimator does not augment the state vector, thus ``\mathbf{x̂ = x̂_d}``. See
202202
[`init_internalmodel`](@ref) for details.
203203
"""
204-
function update_estimate!(estim::InternalModel, u, ym, d=Float64[])
204+
function update_estimate!(estim::InternalModel, u, ym, d=empty(estim.x̂))
205205
model = estim.model
206206
x̂d, x̂s = estim.x̂d, estim.x̂s
207207
# -------------- deterministic model ---------------------
@@ -232,5 +232,5 @@ function print_estim_dim(io::IO, estim::InternalModel, n)
232232
print(io, "$(lpad(nd, n)) measured disturbances d")
233233
end
234234

235-
(estim::InternalModel)(ym, d=Float64[]) = evaloutput(estim::InternalModel, ym, d)
235+
(estim::InternalModel)(ym, d=empty(estim.x̂)) = evaloutput(estim::InternalModel, ym, d)
236236

src/estimator/kalman.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ The [`SteadyKalmanFilter`](@ref) updates it with the precomputed Kalman gain ``\
172172
+ \mathbf{K̂}[\mathbf{y^m}(k) - \mathbf{Ĉ^m x̂}_{k-1}(k) - \mathbf{D̂_d^m d}(k)]
173173
```
174174
"""
175-
function update_estimate!(estim::SteadyKalmanFilter, u, ym, d=Float64[])
175+
function update_estimate!(estim::SteadyKalmanFilter, u, ym, d=empty(estim.x̂))
176176
Â, B̂u, B̂d, Ĉm, D̂dm = estim.Â, estim.B̂u, estim.B̂d, estim.Ĉm, estim.D̂dm
177177
x̂, K̂ = estim.x̂, estim.
178178
x̂[:] =*+ B̂u*u + B̂d*d +*(ym - Ĉm*- D̂dm*d)
@@ -688,7 +688,7 @@ This syntax allows nonzero off-diagonal elements in ``\mathbf{P̂}_{-1}(0), \mat
688688
ExtendedKalmanFilter{M}(model::M, i_ym, nint_u, nint_ym, P̂0, Q̂, R̂) where {M<:SimModel}
689689

690690
@doc raw"""
691-
update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=Float64[])
691+
update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=empty(estim.x̂))
692692
693693
Update [`ExtendedKalmanFilter`](@ref) state `estim.x̂` and covariance `estim.P̂`.
694694
@@ -717,7 +717,7 @@ automatically computes the Jacobians:
717717
```
718718
The matrix ``\mathbf{Ĥ^m}`` is the rows of ``\mathbf{Ĥ}`` that are measured outputs.
719719
"""
720-
function update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=Float64[])
720+
function update_estimate!(estim::ExtendedKalmanFilter, u, ym, d=empty(estim.x̂))
721721
= ForwardDiff.jacobian(x̂ -> (estim, x̂, u, d), estim.x̂)
722722
= ForwardDiff.jacobian(x̂ -> (estim, x̂, d), estim.x̂)
723723
Ĥm = Ĥ[estim.i_ym, :]

src/estimator/luenberger.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ end
9494

9595

9696
"""
97-
update_estimate!(estim::Luenberger, u, ym, d=Float64[])
97+
update_estimate!(estim::Luenberger, u, ym, d=empty(estim.x̂))
9898
9999
Same than [`update_estimate!(::SteadyKalmanFilter)`](@ref) but using [`Luenberger`](@ref).
100100
"""
101-
function update_estimate!(estim::Luenberger, u, ym, d=Float64[])
101+
function update_estimate!(estim::Luenberger, u, ym, d=empty(estim.x̂))
102102
Â, B̂u, B̂d, Ĉm, D̂dm = estim.Â, estim.B̂u, estim.B̂d, estim.Ĉm, estim.D̂dm
103103
x̂, K̂ = estim.x̂, estim.
104104
x̂[:] =*+ B̂u*u + B̂d*d +*(ym - Ĉm*- D̂dm*d)

src/predictive_control.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Abstract supertype of all predictive controllers.
33
44
---
55
6-
(mpc::PredictiveController)(ry, d=Float64[]; kwargs...)
6+
(mpc::PredictiveController)(ry, d=[]; kwargs...)
77
88
Functor allowing callable `PredictiveController` object as an alias for [`moveinput!`](@ref).
99
@@ -50,7 +50,7 @@ struct ControllerConstraint
5050
end
5151

5252
@doc raw"""
53-
setconstraint!(mpc::PredictiveController; <keyword arguments>)
53+
setconstraint!(mpc::PredictiveController; <keyword arguments>) -> mpc
5454
5555
Set the constraint parameters of `mpc` predictive controller.
5656
@@ -241,7 +241,7 @@ setnonlincon!(::PredictiveController, ::SimModel) = nothing
241241
moveinput!(
242242
mpc::PredictiveController,
243243
ry = mpc.estim.model.yop,
244-
d = Float64[];
244+
d = [];
245245
R̂y = repeat(ry, mpc.Hp),
246246
D̂ = repeat(d, mpc.Hp),
247247
ym = nothing
@@ -277,7 +277,7 @@ julia> ry = [5]; u = moveinput!(mpc, ry); round.(u, digits=3)
277277
function moveinput!(
278278
mpc::PredictiveController,
279279
ry::Vector = mpc.estim.model.yop,
280-
d ::Vector = Float64[];
280+
d ::Vector = empty(mpc.estim.x̂);
281281
R̂y::Vector = repeat(ry, mpc.Hp),
282282
::Vector = repeat(d, mpc.Hp),
283283
ym::Union{Vector, Nothing} = nothing
@@ -357,22 +357,22 @@ Set the estimate at `mpc.estim.x̂`.
357357
setstate!(mpc::PredictiveController, x̂) = (setstate!(mpc.estim, x̂); return mpc)
358358

359359
@doc raw"""
360-
initstate!(mpc::PredictiveController, u, ym, d=Float64[])
360+
initstate!(mpc::PredictiveController, u, ym, d=[]) -> x̂
361361
362362
Init the states of `mpc.estim` [`StateEstimator`](@ref) and warm start `mpc.ΔŨ` at zero.
363363
"""
364-
function initstate!(mpc::PredictiveController, u, ym, d=Float64[])
364+
function initstate!(mpc::PredictiveController, u, ym, d=empty(mpc.estim.x̂))
365365
mpc.ΔŨ .= 0
366366
return initstate!(mpc.estim, u, ym, d)
367367
end
368368

369369

370370
"""
371-
updatestate!(mpc::PredictiveController, u, ym, d=Float64[]) -> x̂
371+
updatestate!(mpc::PredictiveController, u, ym, d=[]) -> x̂
372372
373373
Call [`updatestate!`](@ref) on `mpc.estim` [`StateEstimator`](@ref).
374374
"""
375-
updatestate!(mpc::PredictiveController, u, ym, d=Float64[]) = updatestate!(mpc.estim,u,ym,d)
375+
updatestate!(mpc::PredictiveController, u, ym, d=empty(mpc.estim.x̂)) = updatestate!(mpc.estim,u,ym,d)
376376
updatestate!(::PredictiveController, _ ) = throw(ArgumentError("missing measured outputs ym"))
377377

378378
function validate_setpointdist(mpc::PredictiveController, ry, d, R̂y, D̂)
@@ -1051,7 +1051,7 @@ end
10511051
"Functor allowing callable `PredictiveController` object as an alias for `moveinput!`."
10521052
function (mpc::PredictiveController)(
10531053
ry::Vector = mpc.estim.model.yop,
1054-
d ::Vector = Float64[];
1054+
d ::Vector = empty(mpc.estim.x̂);
10551055
kwargs...
10561056
)
10571057
return moveinput!(mpc, ry, d; kwargs...)

src/sim_model.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Abstract supertype of [`LinModel`](@ref) and [`NonLinModel`](@ref) types.
55
66
---
77
8-
(model::SimModel)(d=Float64[])
8+
(model::SimModel)(d=[]) -> y
99
1010
Functor allowing callable `SimModel` object as an alias for [`evaloutput`](@ref).
1111
@@ -21,7 +21,7 @@ julia> y = model()
2121
abstract type SimModel end
2222

2323
@doc raw"""
24-
setop!(model::SimModel; uop=nothing, yop=nothing, dop=nothing)
24+
setop!(model::SimModel; uop=nothing, yop=nothing, dop=nothing) -> model
2525
2626
Set `model` inputs `uop`, outputs `yop` and measured disturbances `dop` operating points.
2727
@@ -99,7 +99,7 @@ function Base.show(io::IO, model::SimModel)
9999
end
100100

101101
@doc raw"""
102-
initstate!(model::SimModel, u, d=Float64[]) -> x
102+
initstate!(model::SimModel, u, d=[]) -> x
103103
104104
Init `model.x` with manipulated inputs `u` and measured disturbances `d` steady-state.
105105
@@ -121,13 +121,13 @@ true
121121
```
122122
123123
"""
124-
function initstate!(model::SimModel, u, d=Float64[])
124+
function initstate!(model::SimModel, u, d=empty(model.x))
125125
steadystate!(model, u, d)
126126
return model.x
127127
end
128128

129129
"""
130-
updatestate!(model::SimModel, u, d=Float64[]) -> x
130+
updatestate!(model::SimModel, u, d=[]) -> x
131131
132132
Update `model.x` states with current inputs `u` and measured disturbances `d`.
133133
@@ -140,13 +140,13 @@ julia> x = updatestate!(model, [1])
140140
1.0
141141
```
142142
"""
143-
function updatestate!(model::SimModel, u, d=Float64[])
143+
function updatestate!(model::SimModel, u, d=empty(model.x))
144144
model.x[:] = f(model, model.x, u - model.uop, d - model.dop)
145145
return model.x
146146
end
147147

148148
"""
149-
evaloutput(model::SimModel, d=Float64[]) -> y
149+
evaloutput(model::SimModel, d=[]) -> y
150150
151151
Evaluate `SimModel` outputs `y` from `model.x` states and measured disturbances `d`.
152152
@@ -161,10 +161,10 @@ julia> y = evaloutput(model)
161161
20.0
162162
```
163163
"""
164-
evaloutput(model::SimModel, d=Float64[]) = h(model, model.x, d - model.dop) + model.yop
164+
evaloutput(model::SimModel, d=empty(model.x)) = h(model, model.x, d - model.dop) + model.yop
165165

166166
"Functor allowing callable `SimModel` object as an alias for `evaloutput`."
167-
(model::SimModel)(d=Float64[]) = evaloutput(model::SimModel, d)
167+
(model::SimModel)(d=empty(model.x)) = evaloutput(model::SimModel, d)
168168

169169
include("model/linmodel.jl")
170170
include("model/nonlinmodel.jl")

src/state_estim.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Abstract supertype of all state estimators.
33
44
---
55
6-
(estim::StateEstimator)(d=Float64[])
6+
(estim::StateEstimator)(d=[]) -> ŷ
77
88
Functor allowing callable `StateEstimator` object as an alias for [`evaloutput`](@ref).
99
@@ -213,7 +213,7 @@ end
213213

214214

215215
@doc raw"""
216-
default_nint(model::LinModel, i_ym=1:model.ny, nint_u=0)
216+
default_nint(model::LinModel, i_ym=1:model.ny, nint_u=0) -> nint_ym
217217
218218
Get default integrator quantity per measured outputs `nint_ym` for [`LinModel`](@ref).
219219
@@ -288,7 +288,7 @@ end
288288

289289

290290
@doc raw"""
291-
initstate!(estim::StateEstimator, u, ym, d=Float64[]) -> x̂
291+
initstate!(estim::StateEstimator, u, ym, d=[]) -> x̂
292292
293293
Init `estim.x̂` states from current inputs `u`, measured outputs `ym` and disturbances `d`.
294294
@@ -321,7 +321,7 @@ true
321321
```
322322
323323
"""
324-
function initstate!(estim::StateEstimator, u, ym, d=Float64[])
324+
function initstate!(estim::StateEstimator, u, ym, d=empty(estim.x̂))
325325
# --- init state estimate ----
326326
u0, d0, ym0 = remove_op!(estim, u, d, ym)
327327
init_estimate!(estim, estim.model, u0, ym0, d0)
@@ -362,7 +362,7 @@ end
362362
init_estimate!(::StateEstimator, ::SimModel, _ , _ , _ ) = nothing
363363

364364
@doc raw"""
365-
evaloutput(estim::StateEstimator, d=Float64[]) -> ŷ
365+
evaloutput(estim::StateEstimator, d=[]) -> ŷ
366366
367367
Evaluate `StateEstimator` outputs `ŷ` from `estim.x̂` states and disturbances `d`.
368368
@@ -377,16 +377,16 @@ julia> ŷ = evaloutput(kf)
377377
20.0
378378
```
379379
"""
380-
function evaloutput(estim::StateEstimator, d=Float64[])
380+
function evaloutput(estim::StateEstimator, d=empty(estim.x̂))
381381
return (estim, estim.x̂, d - estim.model.dop) + estim.model.yop
382382
end
383383

384384
"Functor allowing callable `StateEstimator` object as an alias for `evaloutput`."
385-
(estim::StateEstimator)(d=Float64[]) = evaloutput(estim, d)
385+
(estim::StateEstimator)(d=empty(estim.x̂)) = evaloutput(estim, d)
386386

387387

388388
@doc raw"""
389-
updatestate!(estim::StateEstimator, u, ym, d=Float64[]) -> x̂
389+
updatestate!(estim::StateEstimator, u, ym, d=[]) -> x̂
390390
391391
Update `estim.x̂` estimate with current inputs `u`, measured outputs `ym` and dist. `d`.
392392
@@ -403,7 +403,7 @@ julia> x̂ = updatestate!(kf, [1], [0]) # x̂[2] is the integrator state (nint_y
403403
0.0
404404
```
405405
"""
406-
function updatestate!(estim::StateEstimator, u, ym, d=Float64[])
406+
function updatestate!(estim::StateEstimator, u, ym, d=empty(estim.x̂))
407407
u0, d0, ym0 = remove_op!(estim, u, d, ym)
408408
update_estimate!(estim, u0, ym0, d0)
409409
return estim.

0 commit comments

Comments
 (0)