-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpredictive_control.jl
More file actions
59 lines (49 loc) · 2.05 KB
/
Copy pathpredictive_control.jl
File metadata and controls
59 lines (49 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@doc raw"""
Abstract supertype of all predictive controllers.
---
(mpc::PredictiveController)(ry, d=[]; kwargs...) -> u
Functor allowing callable `PredictiveController` object as an alias for [`moveinput!`](@ref).
# Examples
```jldoctest
julia> mpc = LinMPC(LinModel(tf(5, [2, 1]), 3), Nwt=[0], Hp=1000, Hc=1, direct=false);
julia> u = mpc([5]); round.(u, digits=3)
1-element Vector{Float64}:
1.0
```
"""
abstract type PredictiveController{NT<:Real} end
include("controller/transcription.jl")
include("controller/construct.jl")
include("controller/execute.jl")
include("controller/explicitmpc.jl")
include("controller/linmpc.jl")
include("controller/nonlinmpc.jl")
function Base.show(io::IO, mpc::PredictiveController)
estim, model = mpc.estim, mpc.estim.model
Hp, Hc, nϵ = mpc.Hp, mpc.Hc, mpc.nϵ
nu, nd = model.nu, model.nd
nx̂, nym, nyu = estim.nx̂, estim.nym, estim.nyu
other_dims = get_other_dims(estim)
n = maximum(ndigits.((Hp, Hc, nu, nx̂, nym, nyu, nd, other_dims...))) + 1
println(io, "$(nameof(typeof(mpc))) controller with a sample time Ts = $(model.Ts) s:")
println(io, "├ estimator: $(nameof(typeof(mpc.estim)))")
println(io, "├ model: $(nameof(typeof(model)))")
println(io, "├ optimizer: $(JuMP.solver_name(mpc.optim)) ")
println(io, "├ transcription: $(nameof(typeof(mpc.transcription)))")
print_backends(io, mpc)
println(io, "└ dimensions:")
println(io, " ├$(lpad(Hp, n)) prediction steps Hp")
println(io, " ├$(lpad(Hc, n)) control steps Hc")
println(io, " ├$(lpad(nϵ, n)) slack variable ϵ (control constraints)")
print_estim_dim(io, mpc.estim, n)
end
"No differentiation backends to print for a `PredictiveController` by default."
print_backends(::IO, ::PredictiveController) = nothing
"Functor allowing callable `PredictiveController` object as an alias for `moveinput!`."
function (mpc::PredictiveController)(
ry::AbstractVector = mpc.estim.model.yop,
d ::AbstractVector = mpc.estim.buffer.empty;
kwargs...
)
return moveinput!(mpc, ry, d; kwargs...)
end