Skip to content

Commit a428271

Browse files
committed
includes
1 parent 1205380 commit a428271

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/lqg_control_flat_planar.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
include("planar_flat.jl") # Get FlatDyadBot
2-
using DyadControlSystems
3-
import DyadControlSystems as JSC
4-
using LinearAlgebra
2+
53

64
# Create the plant directly - no wrapper component needed
75

src/pid_control_flat_planar.jl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
# cd(joinpath(@__DIR__, ".."))
2+
# using Pkg
3+
# Pkg.activate(".")
4+
include("planar_flat.jl") # Get FlatDyadBot
5+
6+
# @named plant = FlatDyadBot()
7+
# plant = complete(plant)
8+
# inputs = [plant.control_input.u]
9+
# outputs = [plant.theta_output.u]
10+
11+
12+
# P0 = named_ss(plant, inputs, outputs; op = Dict([inputs .=> 0; plant.b_trans=>0; plant.b_rot=>0; plant.x => big(0.0)]), allow_input_derivatives=true)
13+
14+
# Pt = named_ss(plant, inputs, outputs; op = Dict([inputs .=> 0; plant.b_trans=>1; plant.b_rot=>0; plant.x => big(0.0)]), allow_input_derivatives=true)
15+
16+
# Pr = named_ss(plant, inputs, outputs; op = Dict([inputs .=> 0; plant.b_trans=>0; plant.b_rot=>1; plant.x => big(0.0)]), allow_input_derivatives=true)
17+
18+
# Ptr = named_ss(plant, inputs, outputs; op = Dict([inputs .=> 0; plant.b_trans=>1; plant.b_rot=>1; plant.x => big(0.0)]), allow_input_derivatives=true)
19+
20+
# Ps = [P0, Pt, Pr, Ptr]
21+
22+
# nyquistplot(8 .* Ps)
23+
124
@component function AngleControlledFlatDyadBot(; name)
225
pars = @parameters begin
326
theta_ref = deg2rad(180) # Reference angle (upright)
427
end
528

629
systems = @named begin
730
plant = FlatDyadBot()
8-
controller = Blocks.LimPID(k=15.6, Ti=12.2, Td=0.16, Nd=25, u_max=7)
31+
controller = Blocks.LimPID(k=15.6, Ti=Inf, Td=0.16, Nd=25, u_max=7)
932
ref = Blocks.Constant(k=theta_ref)
1033
end
1134

@@ -56,6 +79,7 @@ spec = JSC.PIDAutotuningAnalysisSpec(;
5679
Mks = 400.0, # Control sensitivity constraint
5780
wl = 1e-2, # Lower frequency bound
5881
wu = 1e3, # Upper frequency bound
82+
ki_ub = 0.0, # Tune PD controller
5983
num_frequencies = 200,
6084
soft = true,
6185
)
@@ -83,9 +107,9 @@ display(optimized_params)
83107
systems = @named begin
84108
plant = FlatDyadBot()
85109
# Inner loop: angle controller
86-
inner_controller = Blocks.LimPID(k=15.6, Ti=12.2, Td=0.16, Nd=25, u_max=7)
110+
inner_controller = Blocks.LimPID(k=15.6, Ti=Inf, Td=0.16, Nd=25, u_max=7)
87111
# Outer loop: velocity controller
88-
outer_controller = Blocks.LimPID(k=0.54, Ti=2.1, Td=0, Nd=600, wd=1, wp=0.5)
112+
outer_controller = Blocks.LimPID(k=0.54, Ti=2.48, Td=0, Nd=600, wd=1, wp=0.5)
89113
neg_gain = Blocks.Gain(k=1)
90114
ref = Blocks.Step(height=x_ref, start_time=5)
91115
# Add pi offset to inner loop reference
@@ -183,7 +207,8 @@ w = exp10.(LinRange(-1, 3, 1000))
183207
Msi2, ws2 = hinfnorm2(Si2)
184208
bodeplot(Si2, w, plotphase=false); hline!([Msi2], l=(:dash, :black), label="\$M_S = \$$(round(Msi2, digits=2))")
185209

186-
Li2 = inv(Si2) - 1 |> minreal
210+
Li2 = minreal(inv(Si2) - 1, 1e-12)
211+
Li2 = convert(StateSpace{Continuous, Float64}, Li2)
187212
nyquistplot(Li2)
188213
marginplot(Li2, w, adjust_phase_start=true)
189214

@@ -194,4 +219,4 @@ dmi2 = diskmargin(Li2)
194219
plot(dmi2)
195220

196221
dmi22 = diskmargin(Li22)
197-
plot(dmi22)
222+
plot(dmi22)

src/planar_flat.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import ModelingToolkitStandardLibrary.Blocks
55
using OrdinaryDiffEq
66
using DyadControlSystems, ControlSystemsBase, ControlSystemsMTK
77
using Plots
8+
import DyadControlSystems as JSC
9+
using LinearAlgebra
10+
11+
812
Plots.default(size=(1200,1200))
913
connect = ModelingToolkit.connect
1014

0 commit comments

Comments
 (0)