-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Robust toolbox dev #192
Closed
Closed
Changes from 59 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
8f3e4c7
Initial commit of the H-infinity synthesis toolbox
mgreiff 61ae0a3
Clean up dev and remove deprecated files
mgreiff 61694cd
Include tools for discrete-time synthesis and some tests
mgreiff d312409
Enhancement - Initial commit of the tests for the H-infinity design, …
mgreiff 909bec0
Enhancement - Include tests for stabilizability husing the Hautus Lem…
mgreiff b4b4e9c
Bugfix - Specify input types to handle method errors in the stabiliza…
mgreiff 8d18f6b
Enhancement - Add method error tests for the stabilizability and dete…
mgreiff 4cdcb12
Enhancement - Add check for detectability by the Hautus Lemma for usa…
mgreiff 5a63b53
Enhancement - Check for method errors when checking detectability of …
mgreiff 6de77ec
Enhancement - This test checks that the computations of the pseudoinv…
mgreiff 153883d
Bugfix - Make sure to check that only abstract matrix types are used …
mgreiff 6e70954
Enhancement - Add tests to verify that the pseudoinverse computation …
mgreiff 0eaad04
Enhancement - Check that the method correctly reports that no pseudoi…
mgreiff 3588cec
Enhancement - Add tests for the gamma-iterations, and speicically tes…
mgreiff 3fc2b7c
Enhancement - Add tests to check that a solution is reported to be no…
mgreiff fe2f1ae
Enhancement - Add test set for the bilinear transformation
mgreiff f8db6b1
Test that the SS-type data is discretized correctly, and that moving …
mgreiff e7a4b51
Enhancement - Add tests for discretization of extended state-space da…
mgreiff 3371fd3
Enhancement - Add test which runs the DC-motor example
mgreiff 7457c26
Add test which verifies optimality in the DC-motor case
mgreiff 7293cb7
Add test to check that the specifications are indeed satisfied by the…
mgreiff e863190
Encapsulate the DC motor example in a separate test set
mgreiff 1a594fb
Enhancement - Add test which runs the MIT open courseware example
mgreiff 17756e6
Enhancement - Add test to check optimality int the MIT open coursewar…
mgreiff 8a2b895
Enhancement - Add check to see that the specifications are met with t…
mgreiff 498df49
Enhancement - Add tests which run the quadtank example and make sure …
mgreiff 7ad1ad7
Move examples fom the dev directory to the example directory
mgreiff 26e397a
Enhancement - Check for optimality in the Quad-tank example H-infinit…
mgreiff d01b0a3
Enhancement - Check that the frequency-domain sspecifications are met…
mgreiff fe3dc87
Fix error throws in the specifications rewrite, include printstatemen…
mgreiff 08067e3
Add tests to verify that the conversion in the hInf_partition is done…
mgreiff 04eeee1
Add the hinfinity tests to the automatic testing
mgreiff c65c223
Parameterize Function - move hard coded numerical tolerance to be an …
mgreiff fb5fcc8
Remove Dead Code - remove unneeded variable epsilon
mgreiff 3ba522b
Inline Variable - remove the flag variable and return a boolean direc…
mgreiff 259dfda
Rename Variable - Rename the variable so that the controller is consi…
mgreiff 4ffaefe
Inline Variable - Removed the gammasquared variable
mgreiff 9785fca
Extract Variable - Extract exactly what is returned in the hInf_synth…
mgreiff a990295
Remove breaking underfined variable
mgreiff df01d94
Introduce Assertion - Make sure that the matrix which is to be factor…
mgreiff f25585e
Introduce Assertion - Assert that the matrix which is to be factorize…
mgreiff 68f56b8
Extract Method - Extracted a method for checking positive definitenes…
mgreiff fbe6a5b
Bugfix with string concatenation in _assert_real_and_PSD()
mgreiff 3aee485
Introduce Assertion - Throw an error when the conitions in _scale_mat…
mgreiff 1e8d72f
Add test for the coordinate transform using the QR decomposition, ena…
mgreiff d16169e
Add SVD scaling as an option, although, I need to figure out why resu…
mgreiff 9ef1a6e
Add tests for the SVD scaling
mgreiff 88148e9
Remove dead code and include error exception when attempting to secom…
mgreiff 2a0faf0
Add input error checks for the scaling function
mgreiff 0ab6a67
Fix input types to all functions, edit docstrings
mgreiff dc3e3bc
Edit docstring with list of all functions which are to be tested
mgreiff f6e4f31
Add docstrings
mgreiff 0e36097
Add recepie to visualize the H-infinity synthesis specifications agai…
mgreiff c5a2dee
Change the examples to use the recepies
mgreiff 7ef5745
Remove deprecated development files
mgreiff f2de685
Remove deprecated utilities file
mgreiff 37b4426
Include example pdf files of the controller synthesis
mgreiff 5c8dcf6
Fix discrete time examples so that they use the specificationsplot fu…
mgreiff df3cc3c
Remove TODOs from the ARE solver
mgreiff ba7bfeb
Remove MIMO example primarily used for debuging
mgreiff eed2a82
Clean up bib-entry for the doyle/Glover paper
mgreiff 2d0f99b
Removed pseudoinverse function
mgreiff 9a0fa95
remove PDF files
mgreiff c4c49fa
Change naming convention to be consistent with https://docs.julialang…
mgreiff f1569c2
Change naming convention to be consistent with https://docs.julialang…
mgreiff 8c2658b
Change name of all function to be compatible with the style guide
mgreiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
docs/build/ | ||
docs/site/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Plots | ||
using ControlSystems | ||
""" | ||
This is a simple SISO example with a pole in the origin, corresponding to the | ||
DC servos used in the Lund laboratories. It serves to exeplify how the syntheis | ||
can be done for simple SISO systems, and also demonstrates how we chan verify | ||
if the problem is feasible to solve using the ARE method. | ||
|
||
The example can be set to visualize and save plots using the variables | ||
MakePlots - true/false (true if plots are to be generated, false for testing) | ||
SavePlots - true/false (true if plots are to be saved, false for testing) | ||
""" | ||
MakePlots, SavePlots = false, false | ||
|
||
# Define the process | ||
Gtrue = tf([11.2], [1, 0.12,0]) | ||
|
||
# Sensitivity weight function | ||
M, wB, A = 1.5, 20.0, 1e-8 | ||
WS = tf([1/M, wB],[1, wB*A]) | ||
|
||
# Output sensitivity weight function | ||
WU = ss(1) | ||
|
||
# Complementary sensitivity weight function | ||
WT = [] | ||
|
||
# Form the P in the LFT F_l(P,C) as a partitioned state-space object | ||
P = hInf_partition(Gtrue, WS, WU, WT) | ||
|
||
# Check if the system is feasible for synythesis | ||
flag = hInf_assumptions(P) | ||
|
||
# Since it is not, modify the plant desciption | ||
epsilon = 1e-5 | ||
G = tf([11.2], [1, 0.12]) * tf([1], [1, epsilon]) | ||
|
||
# Form the P in the LFT Fl(P,C) as a partitioned state-space object | ||
P = hInf_partition(G, WS, WU, WT) | ||
|
||
# Check if the problem is feasible | ||
flag = hInf_assumptions(P) | ||
|
||
# Synthesize the H-infinity optimal controller | ||
flag, C, gamma = hInf_synthesize(P) | ||
|
||
# Extract the transfer functions defining some signals of interest | ||
Pcl, S, CS, T = hInf_signals(P, G, C) | ||
|
||
## Plot the specifications | ||
if MakePlots | ||
specificationplot([S, CS, T], [WS, WU, WT], gamma) | ||
if SavePlots | ||
savefig("example_DC_specifications.pdf") | ||
end | ||
end | ||
|
||
## Plot the closed loop gain from w to z | ||
if MakePlots | ||
specificationplot(Pcl, gamma; s_labels=["\$\\sigma(P_{cl}(j\\omega))\$"], w_labels=["\$\\gamma\$"]) | ||
if SavePlots | ||
savefig("example_DC_clgain.pdf") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Plots | ||
using ControlSystems | ||
""" | ||
This is a simple SISO example with a pole in the origin, corresponding to the | ||
DC servos used in the Lund laboratories. It serves to exeplify how the syntheis | ||
can be done for simple SISO systems, and also demonstrates how we chan verify | ||
if the problem is feasible to solve using the ARE method. | ||
|
||
The example can be set to visualize and save plots using the variables | ||
MakePlots - true/false (true if plots are to be generated, false for testing) | ||
SavePlots - true/false (true if plots are to be saved, false for testing) | ||
""" | ||
MakePlots = true | ||
|
||
# Define the process | ||
ts = 0.01 | ||
epsilon = 1e-5 | ||
Gd = ss(c2d(tf([11.2], [1, 0.12]) * tf([1], [1, epsilon]), ts)) | ||
|
||
# Sensitivity weight function | ||
M, wB, A = 1.5, 20.0, 1e-8 | ||
WS = tf([1/M, wB],[1, wB*A]) | ||
|
||
# Output sensitivity weight function | ||
WU = ss(1) | ||
|
||
# Complementary sensitivity weight function | ||
WT = [] | ||
|
||
# Create continuous time approximation of the process | ||
Gc = hInf_bilinear_z2s(ss(Gd)) | ||
|
||
# Form the P in the LFT Fl(P,C) as a partitioned state-space object | ||
Pc = hInf_partition(Gc, WS, WU, WT) | ||
|
||
# Check if the problem is feasible | ||
flag = hInf_assumptions(Pc) | ||
|
||
# Synthesize the H-infinity optimal controller | ||
flag, Cc, gamma = hInf_synthesize(Pc) | ||
|
||
# Extract the transfer functions defining some signals of interest, but do so | ||
# using discrete equivalent of the continuous time objects Pc, Cc and Gc | ||
PclD, SD, CSD, TD = hInf_signals( | ||
hInf_bilinear_s2z(Pc, ts), | ||
hInf_bilinear_s2z(Gc, ts), | ||
hInf_bilinear_s2z(Cc, ts) | ||
) | ||
|
||
# This solution is a bit hacky and should be revised | ||
Pcl = ss(PclD.A, PclD.B, PclD.C, PclD.D, ts) | ||
S = ss(SD.A, SD.B, SD.C, SD.D, ts) | ||
CS = ss(CSD.A, CSD.B, CSD.C, CSD.D, ts) | ||
T = ss(TD.A, TD.B, TD.C, TD.D, ts) | ||
|
||
# Visualize results | ||
if MakePlots | ||
specificationplot([S, CS, T], [WS, WU, WT], gamma) | ||
specificationplot(Pcl, gamma; s_labels=["\$\\sigma(P_{cl}(j\\omega))\$"], w_labels=["\$\\gamma\$"]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using ControlSystems | ||
using Plots | ||
|
||
""" | ||
This is very dense and horrible example used for debugging. CUrrently doesn't | ||
work due to the absence of enforcing a loopshift in h´the solver - I need to | ||
figure out how to doe this prolperly. | ||
""" | ||
|
||
# Define the process dynamics | ||
nx = 30 | ||
nu = 8 | ||
ny = 8 | ||
A = 10*rand(nx,nx) | ||
A -= (abs(maximum(real(eigvals(A))))+0.1) * Matrix{Float64}(I, size(A,1), size(A,2)) | ||
B = rand(nx,nu) | ||
C = rand(ny,nx) | ||
D = rand(ny,nu) | ||
|
||
G = hInf_bilinear_z2s(hInf_bilinear_s2z(ss(A,B,C,D), 0.005)) | ||
|
||
# Sensitivity weight function | ||
WSe = tf([0.1,1],[1000,1]) | ||
#WS = [WSe 0 0 ; 0 WSe 0 ; 0 0 WSe] | ||
WS = [WSe 0 0 0 ; 0 WSe 0 0 ; 0 0 WSe 0 ; 0 0 0 WSe] | ||
WS = [WS 0*WS; WS*0 WS] | ||
|
||
# Output sensitivity weight function | ||
WUe = 0.0001*tf([1,1],[0.1,1]) | ||
WU = [WUe 0 0 0 ; 0 WUe 0 0 ; 0 0 WUe 0 ; 0 0 0 WUe] | ||
WU = [WU 0*WU; WU*0 WU] | ||
|
||
#WU = [WUe 0 0 ; 0 WUe 0 ; 0 0 WUe ] | ||
# Complementary sensitivity weight function | ||
WTe = tf([10,1],[1,1]) | ||
WT = [WTe 0 0 0 ; 0 WTe 0 0 ; 0 0 WTe 0 ; 0 0 0 WTe] | ||
WT = [WT 0*WT; WT*0 WT] | ||
|
||
# Form augmented P dynamics in state-space | ||
P = hInf_partition(G, WS, WU, WT) | ||
|
||
# Check that the assumptions are satisfied | ||
flag = hInf_assumptions(P) | ||
|
||
# Synthesize the H-infinity optimal controller | ||
flag, K, gamma = hInf_synthesize(P; maxIter=20) | ||
|
||
Pcl, S, KS, T = hInf_signals(P, G, K) | ||
|
||
MakePlots = true | ||
SavePlots = false | ||
|
||
|
||
fmin = -8 | ||
fmax = 8 | ||
# Plot the singular values of the system | ||
f = [10^i for i in range(fmin, stop=fmax, length=10001)] | ||
|
||
valPcl = sigma(Pcl, f)[1]; | ||
valS = sigma(S, f)[1]; | ||
valKS = sigma(KS, f)[1]; | ||
valT = sigma(T, f)[1]; | ||
|
||
# Visualize the close loop gain | ||
pGain = plot(f, valPcl[:,1], xscale = :log10, yscale = :log10, color = :black, w=2, label="\$\\sigma(P_{w\\rightarrow z}(j\\omega))\$") | ||
plot!(f, gamma*ones(size(f)), xscale = :log10, yscale = :log10, color = :black, w=3, style=:dot, label="\$\\gamma\$") | ||
if size(valPcl,2) > 1 | ||
for ii = 2:size(valPcl,2) | ||
plot!(f, valPcl[:,ii], xscale = :log10, yscale = :log10, color = :black, w=1) | ||
end | ||
end | ||
|
||
# Plot the sensitivity functions of interest | ||
pSigma = plot(f, valS[:,1], xscale = :log10, yscale = :log10, color = :red, w=3, label="\$\\sigma(S(j\\omega))\$") | ||
if size(valS,2) > 1 | ||
for ii = 2:size(valS,2) | ||
plot!(f, valS[:,ii], xscale = :log10, yscale = :log10, color = :red, w=1, label="") | ||
end | ||
end | ||
plot!(f, valKS[:,1], xscale = :log10, yscale = :log10, color = :green, w=3, label="\$\\sigma(C(j\\omega)S(j\\omega)))\$") | ||
if size(valKS,2) > 1 | ||
for ii = 2:size(valKS,2) | ||
plot!(f, valKS[:,ii], xscale = :log10, yscale = :log10, color = :green, w=1, label="") | ||
end | ||
end | ||
plot!(f, valT[:,1], xscale = :log10, yscale = :log10, color = :blue, w=3, label="\$\\sigma(T(j\\omega)))\$") | ||
if size(valT,2) > 1 | ||
for ii = 2:size(valT,2) | ||
plot!(f, valT[:,ii], xscale = :log10, yscale = :log10, color = :blue, w=1, label="") | ||
end | ||
end | ||
|
||
# Visualize the weighting functions | ||
if isa(WS, LTISystem) || isa(WS, Number) | ||
valiWS = sigma(gamma/WS[1,1], f)[1] | ||
plot!(f, valiWS, xscale = :log10, yscale = :log10, color = :red, w=2, style=:dot, label="\$\\gamma\\sigma(W_S(j\\omega)^{-1})\$") | ||
end | ||
if isa(WU, LTISystem) || isa(WU, Number) | ||
valiWU = sigma(gamma/WU[1,1], f)[1] | ||
plot!(f, valiWU, xscale = :log10, yscale = :log10, color = :green, w=2, style=:dot, label="\$\\gamma\\sigma(W_U(j\\omega)^{-1})\$") | ||
end | ||
if isa(WT, LTISystem) || isa(WT, Number) | ||
valiWT = sigma(gamma/WT[1,1], f)[1] | ||
plot!(f, valiWT, xscale = :log10, yscale = :log10, color = :blue, w=2, style=:dot, label="\$\\gamma\\sigma(W_T(j\\omega)^{-1})\$") | ||
end | ||
|
||
l = @layout [ a ; b ] | ||
plt=plot(pGain, pSigma, layout=l, size=(600,600)) | ||
gui() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using ControlSystems | ||
using Plots | ||
|
||
""" | ||
This is a simple SISO example which was used for debugging the implementation, | ||
as this exact example was use in the lecture notes of the "Principles of Optimal | ||
Control" cours of the MIT OpenCourseWare [1], where the choice of weighting | ||
functions and dynamics gave rise to an H-infinity optimal cotnroller with a | ||
γ of approximately 1.36, where, in our case, we get a controller at 0.93 | ||
|
||
[1] https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-323-principles-of-optimal-control-spring-2008/lecture-notes/lec15.pdf | ||
|
||
The example can be set to visualize and save plots using the two variables | ||
ShowPlots - true/false (true if plots are to be generated, false for testing) | ||
filename - Set to string if files are to be saved, otherwise set a empty list | ||
""" | ||
MakePlots, SavePlots = false, false | ||
|
||
# Define the process | ||
G = tf([200], [0.025,1.0025,10.1,1]) | ||
|
||
# Sensitivity weight function | ||
M, wB, A = 1.5, 10, 1e-4 | ||
WS = tf([1/M, wB],[1, wB*A]) | ||
|
||
# Output sensitivity weight function | ||
WU = ss(0.1) | ||
|
||
# Complementary sensitivity weight function | ||
WT = [] | ||
|
||
# Form augmented P dynamics in state-space | ||
P = hInf_partition(G, WS, WU, WT) | ||
|
||
# Check that the assumptions are satisfied | ||
flag = hInf_assumptions(P) | ||
|
||
# Synthesize the H-infinity optimal controller | ||
flag, C, gamma = hInf_synthesize(P) | ||
|
||
# Extract the transfer functions defining some signals of interest | ||
Pcl, S, CS, T = hInf_signals(P, G, C) | ||
|
||
## Plot the specifications | ||
if MakePlots | ||
specificationplot([S, CS, T], [ss(WS), WU, WT], gamma) | ||
if SavePlots | ||
savefig("example_MIT_specifications.pdf") | ||
end | ||
end | ||
|
||
## Plot the closed loop gain from w to z | ||
if MakePlots | ||
specificationplot(Pcl, gamma; s_labels=["\$\\sigma(P_{cl}(j\\omega))\$"], w_labels=["\$\\gamma\$"]) | ||
if SavePlots | ||
savefig("example_MIT_clgain.pdf") | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps best to try to avoid redefining local variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the general MIMO example should be removed, as it is currently dysfunctional - I have yet to add a loop shift in the controller synthesis - I'll remove this script in its entirety for now.