Skip to content

Commit ee71035

Browse files
authored
bump compat DataInterpolations (#68)
* Update Project.toml * up tests * add IC * up * more up * bump version
1 parent ffbc2a7 commit ee71035

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ControlSystemsMTK"
22
uuid = "687d7614-c7e5-45fc-bfc3-9ee385575c88"
33
authors = ["Fredrik Bagge Carlson"]
4-
version = "2.1.0"
4+
version = "2.2.0"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
@@ -16,7 +16,7 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
1616

1717
[compat]
1818
ControlSystemsBase = "1.0.1"
19-
DataInterpolations = "3, 4"
19+
DataInterpolations = "3, 4, 5, 6"
2020
ModelingToolkit = "9.0"
2121
ModelingToolkitStandardLibrary = "2"
2222
MonteCarloMeasurements = "1.1"

docs/src/batch_linearization.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ eqs = [D(x) ~ v
2626
y.u ~ x]
2727
2828
29-
@named duffing = ODESystem(eqs, t, systems=[y, u])
29+
@named duffing = ODESystem(eqs, t, systems=[y, u], defaults=[u.u => 0])
3030
```
3131

3232
## Batch linearization
@@ -61,7 +61,7 @@ bodeplot(P, w, legend=:bottomright) # Should look similar to the one above
6161
```
6262

6363
## Controller tuning
64-
Let's also do some controller tuning for the linearized models above. The function `batch_tune` is not really required here, but it shows how we might go about building more sophisticated tools for batch tuning. In this example, we will tune a PID controller using the function [`loopshapingPID`](@ref).
64+
Let's also do some controller tuning for the linearized models above. The function `batch_tune` is not really required here, but it shows how we might go about building more sophisticated tools for batch tuning. In this example, we will tune a PID controller using the function [`loopshapingPID`](@ref). Note, this procedure is not limited to tuning a gain-scheduled PID controller, it should work for gain-scheduling of any LTI controller.
6565
```@example BATCHLIN
6666
function batch_tune(f, Ps)
6767
f.(Ps)
@@ -119,7 +119,7 @@ for C in Cs
119119
connect(Ci.output, duffing.u)
120120
]
121121
@named closed_loop = ODESystem(eqs, t, systems=[duffing, Ci, fb, ref, F])
122-
prob = ODEProblem(structural_simplify(closed_loop), [], (0.0, 8.0))
122+
prob = ODEProblem(structural_simplify(closed_loop), [F.xd => 0], (0.0, 8.0))
123123
sol = solve(prob, Rodas5P(), abstol=1e-8, reltol=1e-8)
124124
plot!(sol, idxs=[duffing.y.u, duffing.u.u], layout=2, lab="")
125125
end
@@ -133,8 +133,8 @@ eqs = [
133133
connect(duffing.y, Cgs.scheduling_input) # Don't forget to connect the scheduling variable!
134134
]
135135
@named closed_loop = ODESystem(eqs, t, systems=[duffing, Cgs, fb, ref, F])
136-
prob = ODEProblem(structural_simplify(closed_loop), [], (0.0, 8.0))
137-
sol = solve(prob, Rodas5P(), abstol=1e-8, reltol=1e-8)
136+
prob = ODEProblem(structural_simplify(closed_loop), [F.xd => 0], (0.0, 8.0))
137+
sol = solve(prob, Rodas5P(), abstol=1e-8, reltol=1e-8, initializealg=NoInit())
138138
plot!(sol, idxs=[duffing.y.u, duffing.u.u], l=(2, :red), lab="Gain scheduled")
139139
plot!(sol, idxs=F.output.u, l=(1, :black, :dash, 0.5), lab="Ref")
140140
```

docs/src/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ m1 = 1
151151
m2 = 1
152152
k = 1000 # Spring stiffness
153153
c = 10 # Damping coefficient
154-
@named inertia1 = Inertia(; J = m1)
155-
@named inertia2 = Inertia(; J = m2)
154+
@named inertia1 = Inertia(; J = m1, w=0)
155+
@named inertia2 = Inertia(; J = m2, w=0)
156156
@named spring = Spring(; c = k)
157157
@named damper = Damper(; d = c)
158158
@named torque = Torque(use_support=false)
@@ -178,7 +178,7 @@ model = SystemModel() |> complete
178178
### Numeric linearization
179179
We can linearize this model numerically using `named_ss`, this produces a `NamedStateSpace{Continuous, Float64}`
180180
```@example LINEAIZE_SYMBOLIC
181-
lsys = named_ss(model, [model.torque.tau.u], [model.inertia1.phi, model.inertia2.phi])
181+
lsys = named_ss(model, [model.torque.tau.u], [model.inertia1.phi, model.inertia2.phi], op = Dict(model.torque.tau.u => 0))
182182
```
183183
### Symbolic linearization
184184
If we instead call `linearize_symbolic` and pass the jacobians into `ss`, we get a `StateSpace{Continuous, Num}`
@@ -192,6 +192,7 @@ That's pretty cool, but even nicer is to generate some code for this symbolic sy
192192

193193
```@example LINEAIZE_SYMBOLIC
194194
defs = ModelingToolkit.defaults(simplified_sys)
195+
defs = merge(Dict(unknowns(model) .=> 0), defs)
195196
x, pars = ModelingToolkit.get_u0_p(simplified_sys, defs, defs) # Extract the default state and parameter values
196197
197198
fun = Symbolics.build_function(symbolic_sys, unknowns(simplified_sys), ModelingToolkit.parameters(simplified_sys);

test/test_ODESystem.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ControlSystemsMTK,
22
ControlSystemsBase, ModelingToolkit, OrdinaryDiffEq, RobustAndOptimalControl
33
import ModelingToolkitStandardLibrary.Blocks as Blocks
44
conn = ModelingToolkit.connect
5+
connect = ModelingToolkit.connect
56
## Test SISO (single input, single output) system
67
@parameters t
78

@@ -22,7 +23,9 @@ fb = structural_simplify(fb0)
2223
# @test length(unknowns(P)) == 3 # 1 + u + y
2324
# @test length(unknowns(C)) == 4 # 2 + u + y
2425

25-
x0 = Pair[loopgain.P.x=>1.0]
26+
x0 = Pair[
27+
collect(loopgain.P.x) .=> 1.0;
28+
]
2629

2730
prob = ODEProblem(fb, x0, (0.0, 10.0))
2831
sol = solve(prob, Rodas5())
@@ -187,8 +190,8 @@ m2 = 1
187190
k = 1000 # Spring stiffness
188191
c = 10 # Damping coefficient
189192

190-
@named inertia1 = Inertia(; J = m1)
191-
@named inertia2 = Inertia(; J = m2)
193+
@named inertia1 = Inertia(; J = m1, w=0)
194+
@named inertia2 = Inertia(; J = m2, w=0)
192195

193196
@named spring = Spring(; c = k)
194197
@named damper = Damper(; d = c)
@@ -229,9 +232,12 @@ sys = ss((mats...,)[1:4]...)
229232

230233

231234
defs = ModelingToolkit.defaults(ssys)
232-
sympars = ModelingToolkit.parameters(ssys)
235+
defs = merge(Dict(unknowns(model) .=> 0), defs)
233236
_, p = ModelingToolkit.get_u0_p(ssys, defs, defs)
234237

238+
239+
sympars = ModelingToolkit.parameters(ssys)
240+
235241
fun = Symbolics.build_function(sys, sympars; expression=Val{false}, force_SA=true)
236242
fun(p)
237243
@test @allocated(fun(p)) <= 256

test/test_batchlin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ closed_loop_eqs = [
6464
@named closed_loop = ODESystem(closed_loop_eqs, t, systems=[duffing, C, fb, ref, F])
6565

6666
ssys = structural_simplify(closed_loop)
67-
prob = ODEProblem(ssys, [], (0.0, 8.0))
67+
prob = ODEProblem(ssys, [F.xd => 0], (0.0, 8.0))
6868
sol = solve(prob, Rodas5P(), abstol=1e-8, reltol=1e-8)
6969
# plot(sol)
7070

0 commit comments

Comments
 (0)