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))
183207Msi2, ws2 = hinfnorm2 (Si2)
184208bodeplot (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)
187212nyquistplot (Li2)
188213marginplot (Li2, w, adjust_phase_start= true )
189214
@@ -194,4 +219,4 @@ dmi2 = diskmargin(Li2)
194219plot (dmi2)
195220
196221dmi22 = diskmargin (Li22)
197- plot (dmi22)
222+ plot (dmi22)
0 commit comments