Skip to content

Commit 3fd7c01

Browse files
refactor: update to MTKv10
1 parent 758ea1f commit 3fd7c01

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
1717
[compat]
1818
ControlSystemsBase = "1.0.1"
1919
DataInterpolations = "3, 4, 5, 6, 7"
20-
ModelingToolkit = "9.61"
20+
ModelingToolkit = "10"
2121
ModelingToolkitStandardLibrary = "2"
2222
MonteCarloMeasurements = "1.1"
2323
RobustAndOptimalControl = "0.4.14"

src/ControlSystemsMTK.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using ModelingToolkit, ControlSystemsBase
2020
using ControlSystemsBase: ssdata, AbstractStateSpace, Continuous, nstates, noutputs, ninputs
2121
# using ControlSystemIdentification
2222
using RobustAndOptimalControl, MonteCarloMeasurements
23-
import ModelingToolkit: ODESystem, FnType, Symbolics
23+
import ModelingToolkit: System as ODESystem, FnType, Symbolics
2424
using ModelingToolkit: unknowns, observed, isdifferential
2525
using Symbolics
2626
using Symbolics: jacobian, solve_for

src/ode_system.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const AP = Union{Symbol, AnalysisPoint}
33
import ModelingToolkitStandardLibrary.Blocks as Blocks
44
conn = ModelingToolkit.connect
55
t = Blocks.t
6-
ModelingToolkit.ODESystem(sys::LTISystem; kwargs...) = ODESystem(ss(sys); kwargs...)
6+
ModelingToolkit.System(sys::LTISystem; kwargs...) = System(ss(sys); kwargs...)
77

88
"""
9-
ModelingToolkit.ODESystem(sys::AbstractStateSpace; name::Symbol, x0 = zeros(sys.nx), x_names, u_names, y_names)
9+
ModelingToolkit.System(sys::AbstractStateSpace; name::Symbol, x0 = zeros(sys.nx), x_names, u_names, y_names)
1010
1111
Create an ODESystem from `sys::StateSpace`.
1212
@@ -19,7 +19,7 @@ The arguments below are automatically set if the system is a `NamedStateSpace`.
1919
- `u_names`: A vector of symbols with input names.
2020
- `y_names`: A vector of symbols with output names.
2121
"""
22-
function ModelingToolkit.ODESystem(
22+
function ModelingToolkit.System(
2323
sys::AbstractStateSpace;
2424
name::Symbol,
2525
x0 = zeros(sys.nx),
@@ -39,7 +39,7 @@ function ModelingToolkit.ODESystem(
3939
[uc[i].u ~ input.u[i] for i in 1:length(uc)];
4040
[yc[i].u ~ output.u[i] for i in 1:length(yc)];
4141
]
42-
extend(ODESystem(eqs, t; name, systems), ssblock)
42+
extend(System(eqs, t; name, systems), ssblock)
4343
end
4444

4545
"""
@@ -58,7 +58,7 @@ function sconnect(
5858
input::Union{Function, Num},
5959
sys::T;
6060
name = Symbol("$(sys.name) with input"),
61-
) where {T<:ModelingToolkit.AbstractTimeDependentSystem}
61+
) where {T<:ModelingToolkit.AbstractSystem}
6262
@named output = Blocks.RealOutput()
6363
T(
6464
[
@@ -80,7 +80,7 @@ function sconnect(
8080
sys1::T,
8181
sys2::T;
8282
name = Symbol("$(sys1.name)*$(sys2.name)"),
83-
) where {T<:ModelingToolkit.AbstractTimeDependentSystem}
83+
) where {T<:ModelingToolkit.AbstractSystem}
8484
@named output = Blocks.RealOutput() # TODO: missing size
8585
@named input = Blocks.RealInput() # TODO: missing size
8686
T(
@@ -106,7 +106,7 @@ The system `G` will be a new system with `input` and `output` connectors.
106106
function ControlSystemsBase.feedback(
107107
loopgain::T;
108108
name = Symbol("feedback $(loopgain.name)"),
109-
) where {T<:ModelingToolkit.AbstractTimeDependentSystem}
109+
) where {T<:ModelingToolkit.AbstractSystem}
110110
add = Blocks.Add(k1 = 1, k2 = -1, name = :feedback)
111111
@named input = Blocks.RealInput()
112112
@named output = Blocks.RealOutput()
@@ -123,7 +123,7 @@ function ControlSystemsBase.feedback(
123123
)
124124
end
125125

126-
function Base.:(*)(s1::T, s2::T) where {T<:ModelingToolkit.AbstractTimeDependentSystem}
126+
function Base.:(*)(s1::T, s2::T) where {T<:ModelingToolkit.AbstractSystem}
127127
name = Symbol(string(s1.name) * "_" * string(s2.name))
128128
@named input = Blocks.RealInput()
129129
@named output = Blocks.RealOutput()
@@ -144,7 +144,7 @@ numeric(x::Num) = x.val
144144

145145

146146
function ControlSystemsBase.ss(
147-
sys::ModelingToolkit.AbstractTimeDependentSystem,
147+
sys::ModelingToolkit.AbstractSystem,
148148
inputs,
149149
outputs;
150150
kwargs...
@@ -166,7 +166,7 @@ If `descriptor = false`, the system is instead converted to a statespace realiza
166166
See also [`ModelingToolkit.linearize`](@ref) which is the lower-level function called internally. The functions [`get_named_sensitivity`](@ref), [`get_named_comp_sensitivity`](@ref), [`get_named_looptransfer`](@ref) similarily provide convenient ways to compute sensitivity functions while retaining signal names in the same way as `named_ss`. The corresponding lower-level functions `get_sensitivity`, `get_comp_sensitivity` and `get_looptransfer` are available in ModelingToolkitStandardLibrary.Blocks and are documented in [MTKstdlib: Linear analysis](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/linear_analysis/).
167167
"""
168168
function RobustAndOptimalControl.named_ss(
169-
sys::ModelingToolkit.AbstractTimeDependentSystem,
169+
sys::ModelingToolkit.AbstractSystem,
170170
inputs,
171171
outputs;
172172
descriptor = true,
@@ -177,7 +177,7 @@ function RobustAndOptimalControl.named_ss(
177177
outputs = vcat(outputs)
178178

179179
inputs = map(inputs) do inp
180-
if inp isa ODESystem
180+
if inp isa System
181181
@variables u(t)
182182
if u Set(unknowns(inp))
183183
inp.u
@@ -191,7 +191,7 @@ function RobustAndOptimalControl.named_ss(
191191
nu = length(inputs)
192192

193193
outputs = map(outputs) do out
194-
if out isa ODESystem
194+
if out isa System
195195
@variables u(t)
196196
if u Set(unknowns(out))
197197
out.u
@@ -286,14 +286,14 @@ get_named_looptransfer
286286

287287
function named_sensitivity_function(
288288
fun,
289-
sys::ModelingToolkit.AbstractTimeDependentSystem,
289+
sys::ModelingToolkit.AbstractSystem,
290290
inputs, args...;
291291
kwargs...,
292292
)
293293

294294
inputs = vcat(inputs)
295295
inputs = map(inputs) do inp
296-
if inp isa ODESystem
296+
if inp isa System
297297
@variables u(t)
298298
if u Set(unknowns(inp))
299299
inp.u
@@ -362,7 +362,7 @@ The second problem above, the ordering of the states, can be worked around using
362362
- `ssys`: Output of [`linearize`](@ref).
363363
- `costs`: A vector of pairs
364364
"""
365-
function build_quadratic_cost_matrix(matrices::NamedTuple, ssys::ODESystem, costs::AbstractVector{<:Pair})
365+
function build_quadratic_cost_matrix(matrices::NamedTuple, ssys::System, costs::AbstractVector{<:Pair})
366366
x = ModelingToolkit.unknowns(ssys)
367367
y = ModelingToolkit.outputs(ssys)
368368
# y = getproperty.(ModelingToolkit.observed(ssys), :lhs)
@@ -397,7 +397,7 @@ The second problem above, the ordering of the states, can be worked around using
397397
- `inputs`: A vector of variables that are to be considered controlled inputs for the LQR controller.
398398
- `costs`: A vector of pairs.
399399
"""
400-
function build_quadratic_cost_matrix(sys::ODESystem, inputs::AbstractVector, costs::AbstractVector{<:Pair}; kwargs...)
400+
function build_quadratic_cost_matrix(sys::System, inputs::AbstractVector, costs::AbstractVector{<:Pair}; kwargs...)
401401
matrices, ssys = ModelingToolkit.linearize(sys, inputs, first.(costs); kwargs...)
402402
x = ModelingToolkit.unknowns(ssys)
403403
y = ModelingToolkit.outputs(ssys)
@@ -699,7 +699,7 @@ function GainScheduledStateSpace(systems, vt; interpolator, x = zeros(systems[1]
699699
for i in 1:nx];
700700
collect(output.u .~ C * x .+ D * (input.u .- u0) .+ y0)
701701
]
702-
compose(ODESystem(eqs, t, name = name), [input, output, scheduling_input])
702+
compose(System(eqs, t, name = name), [input, output, scheduling_input])
703703
end
704704

705705
"LPVStateSpace is equivalent to GainScheduledStateSpace, see the docs for GainScheduledStateSpace."

test/test_ODESystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ P0 = tf(1.0, [1, 1]) |> ss
1212
C0 = pid(1, 1) * tf(1, [0.01, 1]) |> ss
1313

1414
@named P = ODESystem(P0)
15-
@test P isa ODESystem
15+
@test P isa System
1616
# @test length(ModelingToolkit.outputs(P)) == P0.ny
1717
# @test length(ModelingToolkit.inputs(P)) == P0.nu
1818
# @named nonlinear_P = sconnect(x->sign(x)*sqrt(abs(x)), P) # apply input-nonlinearity
@@ -167,7 +167,7 @@ x0 = Pair[
167167
]
168168
p = Pair[]
169169

170-
prob = ODEProblem(simplified_sys, x0, (0.0, 20.0), p, jac = true)
170+
prob = ODEProblem(simplified_sys, x0, (0.0, 20.0), jac = true)
171171
sol = solve(prob, Rodas5(), saveat = 0:0.01:20)
172172
if isinteractive()
173173
@show sol.retcode

0 commit comments

Comments
 (0)