From 2ee6ccddbfebe15a06eadc699ea409034f91be86 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Sat, 5 Jan 2019 00:24:34 +0100 Subject: [PATCH 1/6] [tfvis.py] Fix python2 style print --- examples/tfvis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tfvis.py b/examples/tfvis.py index 7929f7023..e0c9b1e8e 100644 --- a/examples/tfvis.py +++ b/examples/tfvis.py @@ -348,7 +348,7 @@ def redraw(self): tvec, yvec = control.matlab.step(self.sys) plt.plot(tvec.T, yvec) except: - print "Error plotting step response" + print("Error plotting step response") plt.suptitle('Step Response') self.canvas_pzmap.show() From d478935268fc6c92b67462df4197f2d617eb5568 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Fri, 4 Jan 2019 23:50:06 +0100 Subject: [PATCH 2/6] [test-statefdk.py] Refactor style and imports --- examples/test-statefbk.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/test-statefbk.py b/examples/test-statefbk.py index b7467bc7e..a9b1a785c 100644 --- a/examples/test-statefbk.py +++ b/examples/test-statefbk.py @@ -1,26 +1,33 @@ -# test-statefbk.py - Unit tests for state feedback code +# test-statefbk.py - Example for state feedback code # RMM, 6 Sep 2010 -import numpy as np # Numerical library -from scipy import * # Load the scipy functions -from control.matlab import * # Load the controls systems library +from scipy import * # Load the scipy functions +from control.matlab import * # Load the controls systems library # Parameters defining the system -m = 250.0 # system mass -k = 40.0 # spring constant -b = 60.0 # damping constant + +m = 250.0 # system mass +k = 40.0 # spring constant +b = 60.0 # damping constant # System matrices -A = matrix([[1, -1, 1.], [1, -k/m, -b/m], [1, 1, 1]]) -B = matrix([[0], [1/m], [1]]) +A = matrix([[1, -1, 1.], + [1, -k / m, -b / m], + [1, 1, 1]]) + +B = matrix([[0], + [1 / m], + [1]]) + C = matrix([[1., 0, 1.]]) -sys = ss(A, B, C, 0); -# Controllability +sys = ss(A, B, C, 0) + +# Check controllability Wc = ctrb(A, B) print "Wc = ", Wc -# Observability +# Check Observability Wo = obsv(A, C) print "Wo = ", Wo From 68618e3710e293d2181b742c82524a1f76c1a5d3 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Fri, 4 Jan 2019 23:50:33 +0100 Subject: [PATCH 3/6] [test-statefbk.py] Fix python2 style print --- examples/test-statefbk.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/test-statefbk.py b/examples/test-statefbk.py index a9b1a785c..1274948f4 100644 --- a/examples/test-statefbk.py +++ b/examples/test-statefbk.py @@ -5,7 +5,6 @@ from control.matlab import * # Load the controls systems library # Parameters defining the system - m = 250.0 # system mass k = 40.0 # spring constant b = 60.0 # damping constant @@ -25,10 +24,8 @@ # Check controllability Wc = ctrb(A, B) -print "Wc = ", Wc +print("Wc = ", Wc) # Check Observability Wo = obsv(A, C) -print "Wo = ", Wo - - +print("Wo = ", Wo) From 83bb42188fa0ee9fb89b735ef468b4465c4ba934 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Fri, 4 Jan 2019 23:52:30 +0100 Subject: [PATCH 4/6] [slicot-test.py] Fix python2 style print --- examples/slicot-test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/slicot-test.py b/examples/slicot-test.py index f14e2995c..217f91a7a 100644 --- a/examples/slicot-test.py +++ b/examples/slicot-test.py @@ -19,8 +19,8 @@ # Eigenvalue placement #from slycot import sb01bd K = place(A, B, [-3, -2, -1]) -print "Pole place: K = ", K -print "Pole place: eigs = ", np.linalg.eig(A - B * K)[0] +print("Pole place: K = ", K) +print("Pole place: eigs = ", np.linalg.eig(A - B * K)[0]) # from slycot import ab01md # Ac, Bc, ncont, info = ab01md('I', A, B) From edfdf1cfff7d818f07dc4aed34d2ca6fd7d90a19 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Sat, 5 Jan 2019 00:22:18 +0100 Subject: [PATCH 5/6] Fix slycot test import --- examples/slicot-test.py | 26 -------------------- examples/slycot-import-test.py | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 26 deletions(-) delete mode 100644 examples/slicot-test.py create mode 100644 examples/slycot-import-test.py diff --git a/examples/slicot-test.py b/examples/slicot-test.py deleted file mode 100644 index 217f91a7a..000000000 --- a/examples/slicot-test.py +++ /dev/null @@ -1,26 +0,0 @@ -# Simple test function to test out SLICOT interface -# RMM, 28 May 09 - -import numpy as np # Numerical library -from scipy import * # Load the scipy functions -from control.matlab import * # Load the controls systems library - -# Parameters defining the system -m = 250.0 # system mass -k = 40.0 # spring constant -b = 60.0 # damping constant - -# System matrices -A = matrix([[1, -1, 1.], [1, -k/m, -b/m], [1, 1, 1]]) -B = matrix([[0], [1/m], [1]]) -C = matrix([[1., 0, 1.]]) -sys = ss(A, B, C, 0); - -# Eigenvalue placement -#from slycot import sb01bd -K = place(A, B, [-3, -2, -1]) -print("Pole place: K = ", K) -print("Pole place: eigs = ", np.linalg.eig(A - B * K)[0]) - -# from slycot import ab01md -# Ac, Bc, ncont, info = ab01md('I', A, B) diff --git a/examples/slycot-import-test.py b/examples/slycot-import-test.py new file mode 100644 index 000000000..7e4f0d9a9 --- /dev/null +++ b/examples/slycot-import-test.py @@ -0,0 +1,45 @@ +""" slycot-import-test.py + +Simple example script to test Slycot import +RMM, 28 May 09 +""" + +import numpy as np +from scipy import * +from control.matlab import * +from control.exception import slycot_check + +# Parameters defining the system +m = 250.0 # system mass +k = 40.0 # spring constant +b = 60.0 # damping constant + +# System matrices +A = np.matrix([[1, -1, 1.], [1, -k / m, -b / m], [1, 1, 1]]) +B = np.matrix([[0], [1 / m], [1]]) +C = np.matrix([[1., 0, 1.]]) +sys = ss(A, B, C, 0) + +# Python control may be used without slycot, for example for a pole placement. +# Eigenvalue placement +w = [-3, -2, -1] +K = place(A, B, w) +print("[python-control (from scipy)] K = ", K) +print("[python-control (from scipy)] eigs = ", np.linalg.eig(A - B * K)[0]) + +# Before using one of its routine, check that slycot is installed. +w = np.array([-3, -2, -1]) +if slycot_check(): + # Import routine sb01bd used for pole placement. + from slycot import sb01bd + + n = 3 # Number of states + m = 1 # Number of inputs + npp = 3 # Number of placed eigen values + alpha = 1 # Maximum threshold for eigen values + dico = 'D' # Discrete system + _, _, _, _, _, K, _ = sb01bd(n, m, npp, alpha, A, B, w, dico, tol=0.0, ldwork=None) + print("[slycot] K = ", K) + print("[slycot] eigs = ", np.linalg.eig(A + np.dot(B, K))[0]) +else: + print("Slycot is not installed.") From 1e6c70427c7ce46c2704459fa4dce364e691d516 Mon Sep 17 00:00:00 2001 From: Anthony De Bortoli Date: Sat, 5 Jan 2019 00:43:06 +0100 Subject: [PATCH 6/6] Add docstring to example and rename it --- ...tefbk.py => check-controllability-and-observability.py} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename examples/{test-statefbk.py => check-controllability-and-observability.py} (78%) diff --git a/examples/test-statefbk.py b/examples/check-controllability-and-observability.py similarity index 78% rename from examples/test-statefbk.py rename to examples/check-controllability-and-observability.py index 1274948f4..ea3254911 100644 --- a/examples/test-statefbk.py +++ b/examples/check-controllability-and-observability.py @@ -1,5 +1,8 @@ -# test-statefbk.py - Example for state feedback code -# RMM, 6 Sep 2010 +""" check-controllability-and-observability.py + +Example to check the controllability and the observability of a state space system. +RMM, 6 Sep 2010 +""" from scipy import * # Load the scipy functions from control.matlab import * # Load the controls systems library