Skip to content

Commit 3571b77

Browse files
committed
simplify
1 parent 8f134b2 commit 3571b77

1 file changed

Lines changed: 36 additions & 55 deletions

File tree

src/lqg_control_flat_planar.jl

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232
@component function LQGFlatDyadBot2(; name)
3333
systems = @named begin
3434
plant = FlatDyadBot()
35-
L = Add4(K = ones(1, 4))
35+
L = Add4(K = 1e-10*ones(1, 4))
3636
end
3737

3838
eqs = [
@@ -66,8 +66,12 @@ lqg_spec = JSC.LQGAnalysisSpec(;
6666
r1_diag = [1.0], # Disturbance noise covariance
6767
r2_diag = [0.001, 0.001], # Measurement noise covariance (x, theta)
6868
wl = 1e-2,
69-
wu = 1e3,
69+
wu = 314,
7070
num_frequencies = 200,
71+
integrator_indices = [1],
72+
integrator_r1_diag = [0.1],
73+
# disc = "zoh",
74+
# Ts = 0.01,
7175
)
7276

7377
# Run the LQG analysis
@@ -84,72 +88,44 @@ observer_gain = lqg_asol.K
8488
display(controller_gain)
8589
display(observer_gain)
8690

87-
##
88-
89-
# cm = complete(plant)
90-
ssys = mtkcompile(plant)
91-
op = [
92-
ssys.L.K => -lqg_asol.L / lqg_asol.P_reduced.C
93-
]
94-
95-
96-
prob = ODEProblem(ssys, op, (0, 1))
97-
sol = solve(prob, Rodas5P())
98-
plot(sol, ylims=(-5, 5)); hline!([π], l=(:dash, :black), primary=false)
99-
100-
10191
##
10292

10393
get_Cfffb(; name) = System(ss(lqg_asol.Cfffb); name)
10494
get_Cff(; name) = System(ss(lqg_asol.Cff); name)
10595
get_Cfb(; name) = System(ss(lqg_asol.Cfb); name)
10696

10797
@component function LQGFlatDyadBot4(; name)
98+
pars = @parameters begin
99+
step_time = 5
100+
step_height = 0.15
101+
end
108102
systems = @named begin
109-
plantfffb = FlatDyadBot()
110-
C = get_Cfffb()
111103
plant = FlatDyadBot()
112-
Cff = get_Cff()
113-
Cfb = get_Cfb()
114-
add = Blocks.Add(k1=1, k2=-1)
104+
C = get_Cfffb()
115105
end
116106

117107
eqs = [
118-
C.input.u[1] ~ ifelse(t>5, 0.15, 0) # rx
108+
C.input.u[1] ~ ifelse(t>step_time, step_height, 0) # rx
119109
C.input.u[2] ~ 0 # rxd
120110
C.input.u[3] ~ 0 # rtheta
121111
C.input.u[4] ~ 0 # rthetad
122-
C.input.u[5] ~ plantfffb.x_output.u # x
123-
C.input.u[6] ~ plantfffb.theta_output.u-pi # theta
124-
connect(C.output, :ufffb, plantfffb.control_input)
125-
126-
Cff.input.u[1] ~ ifelse(t>5, 0.15, 0) # rx
127-
Cff.input.u[2] ~ 0 # rxd
128-
Cff.input.u[3] ~ 0 # rtheta
129-
Cff.input.u[4] ~ 0 # rthetad
130-
Cfb.input.u[1] ~ plant.x_output.u # x
131-
Cfb.input.u[2] ~ plant.theta_output.u-pi # theta
132-
connect(Cff.output, add.input1)
133-
connect(Cfb.output, add.input2)
134-
connect(add.output, :u, plant.control_input)
112+
C.input.u[5] ~ plant.x_output.u # x
113+
C.input.u[6] ~ plant.theta_output.u-pi # theta
114+
connect(C.output, :u, plant.control_input)
135115
]
136116
guesses = [
137-
plantfffb.theta_ddot => 0,
138-
plant.theta_ddot => 0
117+
plant.theta_ddot => 0,
139118
]
140-
System(eqs, t, [], []; systems, name, guesses)
119+
System(eqs, t, [], pars; systems, name, guesses)
141120
end
142121

143122
@named lqg_cl = LQGFlatDyadBot4()
144123

145124
ssys = mtkcompile(lqg_cl)
146125

147126
op = [
148-
# collect(ssys.C.x) .=> nothing
149-
# ssys.C.output.u => 0
150-
# D(ssys.C.output.u) => 0
151127
ssys.plant.theta => deg2rad(160)
152-
ssys.plantfffb.theta => deg2rad(160)
128+
ssys.plant.theta => deg2rad(160)
153129
]
154130

155131
prob = ODEProblem(ssys, op, (0, 20))
@@ -158,26 +134,31 @@ plot(sol, idxs=[
158134
ssys.plant.theta
159135
ssys.plant.x
160136
ssys.plant.tau
161-
ssys.plantfffb.theta
162-
ssys.plantfffb.x
163-
ssys.plantfffb.tau
164-
]); hline!([π 0.3], l=(:dash, :black), primary=false, ylims=(-1, 4))
137+
]); hline!([π prob.ps[ssys.step_height]], l=(:dash, :black), primary=false, ylims=(-1, 4))
165138

166139

167140
##
168141

169-
LT = lqg_asol.Cfb*system_mapping(lqg_asol.P_ext)
142+
# LT = lqg_asol.Cfb*system_mapping(lqg_asol.P_ext)
170143

171-
plot(diskmargin(LT))
144+
# ##
145+
# L2 = get_named_looptransfer(lqg_cl, [lqg_cl.u])
146+
# L2 = -minreal(L2, 1e-8)
147+
148+
# S2 = get_named_sensitivity(lqg_cl, [lqg_cl.u])
172149

173-
##
174-
L2 = get_named_looptransfer(lqg_cl, [lqg_cl.u])
175-
L2 = -L2#minreal(L2, 1e-12)
176150

177-
bodeplot([LT, L2]) # why not identical?
151+
# dmi = diskmargin(LT, offset=0)
152+
# dmi2 = diskmargin(L2, offset=0) # offset due to hard to cancel pole/zero pair in origin
178153

154+
# plot(dmi)
155+
# plot!(dmi2)
179156

180-
dmi2 = diskmargin(L2)
181-
plot!(dmi2)
157+
# bodeplot([LT, L2], adjust_phase_start=false) # why not identical?
182158

183-
# TODO: test the Cff and Cfb separate contorllers, they do not appear to agree with Cfffb at all
159+
# ##
160+
# P_ext = system_mapping(lqg_asol.P_ext)
161+
# @named model = FlatDyadBot()
162+
# cm = complete(model)
163+
# P2 = named_ss(cm, [cm.control_input.u], [cm.x, cm.theta], op=Dict(cm.control_input.u => 0), allow_input_derivatives=true)
164+
# bodeplot([P_ext, P2], adjust_phase_start=false)

0 commit comments

Comments
 (0)