Skip to content

Commit e4fdb4b

Browse files
committed
debug: Function fields replaced by F and H types in LinModel
1 parent cfa2136 commit e4fdb4b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

example/juMPC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ setconstraint!(mpc, ŷmin=[-Inf,-Inf], ŷmax=[55, 35])
9595
setconstraint!(mpc, Δumin=[-Inf,-Inf],Δumax=[+Inf,+Inf])
9696

9797
function test_mpc(model, mpc)
98-
N = 20000
98+
N = 2000
9999
u_data = zeros(2,N)
100100
y_data = zeros(2,N)
101101
r_data = zeros(2,N)

src/predictive_control.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,13 @@ julia> u = moveinput!(mpc, [5]); round.(u, digits=3)
668668
```
669669
"""
670670
function moveinput!(
671-
mpc::PredictiveController,
671+
mpc::C,
672672
ry::Vector{<:Real},
673673
d ::Vector{<:Real} = Float64[];
674674
R̂y::Vector{<:Real} = repeat(ry, mpc.Hp),
675675
::Vector{<:Real} = repeat(d, mpc.Hp),
676676
ym::Union{Vector{<:Real}, Nothing} = nothing
677-
)
677+
) where{C<:PredictiveController}
678678
lastu = mpc.info.u
679679
x̂d, x̂s = split_state(mpc.estim)
680680
ŷs, Ŷs = predict_stoch(mpc, mpc.estim, x̂s, d, ym)

src/sim_model.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ struct LinModel{F<:Function, H<:Function} <: SimModel
2727
Bd ::Matrix{Float64}
2828
Dd ::Matrix{Float64}
2929
x::Vector{Float64}
30-
f::Function
31-
h::Function
30+
f::F
31+
h::H
3232
Ts::Float64
3333
nu::Int
3434
nx::Int
@@ -158,18 +158,15 @@ function LinModel(
158158
A = sys_dis.A
159159
Bu = sys_dis.B[:,1:nu]
160160
Bd = sys_dis.B[:,nu+1:end]
161-
C = sys_dis.C;
161+
C = sys_dis.C
162162
Dd = sys_dis.D[:,nu+1:end]
163163
# the `let` block captures and fixes A, Bu, Bd, C, Dd values (faster computations):
164-
f = let A=A, Bu=Bu, Bd=Bd
165-
(x, u, d) -> A*x + Bu*u + Bd*d
166-
end
167-
h = let C=C, Dd=Dd
168-
(x, d) -> C*x + Dd*d
169-
end
164+
f(x, u, d) = A*x + Bu*u + Bd*d
165+
h(x, d) = C*x + Dd*d
170166
return LinModel_ssfunc(A, Bu, C, Bd, Dd, f, h, Ts, nu, nx, ny, nd)
171167
end
172168

169+
173170
@doc raw"""
174171
LinModel(sys::TransferFunction[, Ts]; i_u=1:size(sys,2), i_d=Int[])
175172

0 commit comments

Comments
 (0)