We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4722ec8 + a8b8c9b commit ae86dbeCopy full SHA for ae86dbe
Project.toml
@@ -1,7 +1,7 @@
1
name = "ModelPredictiveControl"
2
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
3
authors = ["Francis Gagnon"]
4
-version = "1.5.1"
+version = "1.5.2"
5
6
[deps]
7
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
src/controller/execute.jl
@@ -208,7 +208,7 @@ function initpred!(mpc::PredictiveController, model::LinModel, d, D̂, R̂y, R̂
208
F .+= mpc.B # F = F + B
209
mul!(F, mpc.K, mpc.estim.x̂0, 1, 1) # F = F + K*x̂0
210
mul!(F, mpc.V, mpc.estim.lastu0, 1, 1) # F = F + V*lastu0
211
- if model.nd ≠ 0
+ if model.nd > 0
212
mul!(F, mpc.G, mpc.d0, 1, 1) # F = F + G*d0
213
mul!(F, mpc.J, mpc.D̂0, 1, 1) # F = F + J*D̂0
214
end
@@ -256,7 +256,7 @@ is an [`InternalModel`](@ref). The function returns `mpc.F`.
256
function initpred_common!(mpc::PredictiveController, model::SimModel, d, D̂, R̂y, R̂u)
257
mul!(mpc.Tu_lastu0, mpc.Tu, mpc.estim.lastu0)
258
mpc.ŷ .= evaloutput(mpc.estim, d)
259
260
mpc.d0 .= d .- model.dop
261
mpc.D̂0 .= D̂ .- mpc.Dop
262
mpc.D̂e[1:model.nd] .= d
src/controller/transcription.jl
@@ -302,7 +302,7 @@ function init_predmat(
302
G = Matrix{NT}(undef, Hp*ny, nd)
303
jx̂ = Matrix{NT}(undef, nx̂, Hp*nd)
304
J = repeatdiag(D̂d, Hp)
305
- if nd ≠ 0
+ if nd > 0
306
for j=1:Hp
307
iRow = (1:ny) .+ ny*(j-1)
308
G[iRow,:] = Ĉ*getpower(Âpow, j-1)*B̂d
@@ -853,7 +853,7 @@ function linconstraint!(mpc::PredictiveController, model::LinModel, ::Transcript
853
fx̂ .= mpc.con.bx̂
854
mul!(fx̂, mpc.con.kx̂, mpc.estim.x̂0, 1, 1)
855
mul!(fx̂, mpc.con.vx̂, mpc.estim.lastu0, 1, 1)
856
857
mul!(fx̂, mpc.con.gx̂, mpc.d0, 1, 1)
858
mul!(fx̂, mpc.con.jx̂, mpc.D̂0, 1, 1)
859
@@ -939,7 +939,7 @@ function linconstrainteq!(mpc::PredictiveController, model::LinModel, ::Multiple
939
Fŝ .= mpc.con.Bŝ
940
mul!(Fŝ, mpc.con.Kŝ, mpc.estim.x̂0, 1, 1)
941
mul!(Fŝ, mpc.con.Vŝ, mpc.estim.lastu0, 1, 1)
942
943
mul!(Fŝ, mpc.con.Gŝ, mpc.d0, 1, 1)
944
mul!(Fŝ, mpc.con.Jŝ, mpc.D̂0, 1, 1)
945
src/estimator/mhe/execute.jl
@@ -191,7 +191,7 @@ function add_data_windows!(estim::MovingHorizonEstimator, y0m, d0, u0=estim.last
191
if ismoving
192
estim.Y0m[1:end-nym] .= @views estim.Y0m[nym+1:end]
193
estim.Y0m[end-nym+1:end] .= y0m
194
195
estim.D0[1:end-nd] .= @views estim.D0[nd+1:end]
196
estim.D0[end-nd+1:end] .= d0
197
@@ -204,7 +204,7 @@ function add_data_windows!(estim::MovingHorizonEstimator, y0m, d0, u0=estim.last
204
estim.Nk .= estim.He
205
else
206
estim.Y0m[(1 + nym*(Nk-1)):(nym*Nk)] .= y0m
207
# D0 include 1 additional measured disturbance if direct==true (p==0):
estim.D0[(1 + nd*(Nk-p)):(nd*Nk+1-p)] .= d0
@@ -252,7 +252,7 @@ function initpred!(estim::MovingHorizonEstimator, model::LinModel)
252
# --- update F and fx̄ vectors for MHE predictions ---
253
F .= estim.Y0m .+ estim.B
254
mul!(F, estim.G, estim.U0, 1, 1)
255
mul!(F, estim.J, estim.D0, 1, 1)
estim.fx̄ .= estim.x̂0arr_old
@@ -290,7 +290,7 @@ function linconstraint!(estim::MovingHorizonEstimator, model::LinModel)
290
Fx̂ = estim.con.Fx̂
291
Fx̂ .= estim.con.Bx̂
292
mul!(Fx̂, estim.con.Gx̂, estim.U0, 1, 1)
293
294
mul!(Fx̂, estim.con.Jx̂, estim.D0, 1, 1)
295
296
X̂0min, X̂0max = trunc_bounds(estim, estim.con.X̂0min, estim.con.X̂0max, estim.nx̂)
src/model/linearization.jl
@@ -39,9 +39,11 @@ function get_linearization_func(NT, solver_f!, solver_h!, nu, nx, ny, nd, p, sol
39
# all the arguments before `backend` are mutated in this function
40
jacobian!(f_x!, xnext, A, A_prep, backend, x, cache_k, cst_u, cst_d)
41
jacobian!(f_u!, xnext, Bu, Bu_prep, backend, u, cache_k, cst_x, cst_d)
42
- jacobian!(f_d!, xnext, Bd, Bd_prep, backend, d, cache_k, cst_x, cst_u)
43
jacobian!(h_x!, y, C, C_prep, backend, x, cst_d)
44
- jacobian!(h_d!, y, Dd, Dd_prep, backend, d, cst_x)
+ jacobian!(f_d!, xnext, Bd, Bd_prep, backend, d, cache_k, cst_x, cst_u)
45
+ jacobian!(h_d!, y, Dd, Dd_prep, backend, d, cst_x)
46
+ end
47
return nothing
48
49
return linfunc!
src/plot_sim.jl
@@ -379,10 +379,10 @@ plot_recipe(::Nothing, ::SimResult{<:Real, <:SimModel}) = nothing
379
nx = length(indices_x)
380
381
layout_mat = Matrix{Tuple{Int64, Int64}}(undef, 1, 0)
382
- ny ≠ 0 && (layout_mat = [layout_mat (ny, 1)])
383
- nu ≠ 0 && (layout_mat = [layout_mat (nu, 1)])
384
- nd ≠ 0 && (layout_mat = [layout_mat (nd, 1)])
385
- nx ≠ 0 && (layout_mat = [layout_mat (nx, 1)])
+ ny > 0 && (layout_mat = [layout_mat (ny, 1)])
+ nu > 0 && (layout_mat = [layout_mat (nu, 1)])
+ nd > 0 && (layout_mat = [layout_mat (nd, 1)])
+ nx > 0 && (layout_mat = [layout_mat (nx, 1)])
386
layout := layout_mat
387
388
# --- outputs y ---
test/1_test_sim_model.jl
@@ -365,13 +365,18 @@ end
365
366
@test all(isapprox.(Ynl, Yl, atol=1e-6))
367
368
- function f2!(xnext, x, u, d, _)
+ f2!(xnext, x, u, _, _) = (xnext .= x .+ u)
369
+ h2!(y, x, _, _) = (y .= x)
370
+ nonlinmodel4 = NonLinModel(f2!,h2!,Ts,1,1,1,0,solver=nothing,jacobian=AutoFiniteDiff())
371
+ @test_nowarn linearize(nonlinmodel4, x=[1], u=[2])
372
+
373
+ function f3!(xnext, x, u, d, _)
374
xnext .= x.*u .+ x.*d
375
- function h2!(y, x, d, _)
376
+ function h3!(y, x, d, _)
377
y .= x.*d
378
- nonlinmodel4 = NonLinModel(f2!, h2!, Ts, 1, 1, 1, 1, solver=nothing)
+ nonlinmodel4 = NonLinModel(f3!, h3!, Ts, 1, 1, 1, 1, solver=nothing)
linmodel4 = linearize(nonlinmodel4; x, u, d)
linearize!(linmodel4, nonlinmodel4)
#@test @allocations(linearize!(linmodel4, nonlinmodel4)) == 0
0 commit comments