Skip to content

Commit d8d0a9c

Browse files
authored
Merge pull request #267 from don4get/refactor/clean-examples
Rename and clean up controllability/observability example and slycot import example
2 parents 908fabe + 6567c2c commit d8d0a9c

File tree

4 files changed

+82
-57
lines changed

4 files changed

+82
-57
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
""" check-controllability-and-observability.py
2+
3+
Example to check the controllability and the observability of a state space system.
4+
RMM, 6 Sep 2010
5+
"""
6+
7+
from __future__ import print_function
8+
9+
from scipy import * # Load the scipy functions
10+
from control.matlab import * # Load the controls systems library
11+
12+
# Parameters defining the system
13+
14+
m = 250.0 # system mass
15+
k = 40.0 # spring constant
16+
b = 60.0 # damping constant
17+
18+
# System matrices
19+
A = matrix([[1, -1, 1.],
20+
[1, -k / m, -b / m],
21+
[1, 1, 1]])
22+
23+
B = matrix([[0],
24+
[1 / m],
25+
[1]])
26+
27+
C = matrix([[1., 0, 1.]])
28+
29+
sys = ss(A, B, C, 0)
30+
31+
# Check controllability
32+
Wc = ctrb(A, B)
33+
print("Wc = ", Wc)
34+
35+
# Check Observability
36+
Wo = obsv(A, C)
37+
print("Wo = ", Wo)

examples/slicot-test.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/slycot-import-test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
""" slycot-import-test.py
2+
3+
Simple example script to test Slycot import
4+
RMM, 28 May 09
5+
"""
6+
7+
import numpy as np
8+
from scipy import *
9+
from control.matlab import *
10+
from control.exception import slycot_check
11+
12+
# Parameters defining the system
13+
m = 250.0 # system mass
14+
k = 40.0 # spring constant
15+
b = 60.0 # damping constant
16+
17+
# System matrices
18+
A = np.matrix([[1, -1, 1.], [1, -k / m, -b / m], [1, 1, 1]])
19+
B = np.matrix([[0], [1 / m], [1]])
20+
C = np.matrix([[1., 0, 1.]])
21+
sys = ss(A, B, C, 0)
22+
23+
# Python control may be used without slycot, for example for a pole placement.
24+
# Eigenvalue placement
25+
w = [-3, -2, -1]
26+
K = place(A, B, w)
27+
print("[python-control (from scipy)] K = ", K)
28+
print("[python-control (from scipy)] eigs = ", np.linalg.eig(A - B * K)[0])
29+
30+
# Before using one of its routine, check that slycot is installed.
31+
w = np.array([-3, -2, -1])
32+
if slycot_check():
33+
# Import routine sb01bd used for pole placement.
34+
from slycot import sb01bd
35+
36+
n = 3 # Number of states
37+
m = 1 # Number of inputs
38+
npp = 3 # Number of placed eigen values
39+
alpha = 1 # Maximum threshold for eigen values
40+
dico = 'D' # Discrete system
41+
_, _, _, _, _, K, _ = sb01bd(n, m, npp, alpha, A, B, w, dico, tol=0.0, ldwork=None)
42+
print("[slycot] K = ", K)
43+
print("[slycot] eigs = ", np.linalg.eig(A + np.dot(B, K))[0])
44+
else:
45+
print("Slycot is not installed.")

examples/test-statefbk.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)