In [1]:
# Alexander Hebert
# ECE 6390
# Computer Project #2
# Pole assignment using controller type block companion form
# and state feedback
In [2]:
# Tested using Python v3.4 and IPython v2
In [3]:
# Import libraries
In [4]:
import numpy as np
In [5]:
import scipy
In [6]:
import sympy
In [7]:
from IPython.display import display
In [8]:
from sympy.interactive import printing
In [9]:
np.set_printoptions(precision=6)
In [10]:
#np.set_printoptions(suppress=True)
In [11]:
# Original system:
In [12]:
A = np.loadtxt('A_ex1.txt')
In [13]:
A
Out[13]:
In [14]:
n,nc = A.shape
In [15]:
B = np.loadtxt('B_ex1.txt')
In [16]:
B
Out[16]:
In [17]:
nr,m = B.shape
In [18]:
# Compute eigenvalues/poles of A to determine system stability:
In [19]:
A_eigvals, M = np.linalg.eig(A)
In [20]:
A_eigvals
Out[20]:
In [21]:
# Two poles lie in the RHP and are unstable.
In [22]:
A_eigvals_desired = np.array([-0.2,-0.5,A_eigvals[2],A_eigvals[3]])
In [23]:
A_eigvals_desired
Out[23]:
In [24]:
Lambda = np.diag(A_eigvals_desired)
In [25]:
Lambda
Out[25]:
In [26]:
# Pole assignment using controller type block companion form
# and state feedback
In [27]:
Bc = np.array([[0,0],[0,0],[1.,0],[0,1.]])
Bc
Out[27]:
In [28]:
Phi_c = np.concatenate((B,A.dot(B)),1)
Tc1 = np.dot(Bc.T,np.linalg.inv(Phi_c))
Tc1
Out[28]:
In [29]:
Tc = np.concatenate((Tc1,Tc1.dot(A)),0)
Tc
Out[29]:
In [30]:
Tc_inv = np.linalg.inv(Tc)
Tc_inv
Out[30]:
In [31]:
Ac = Tc.dot(A).dot(Tc_inv)
Ac
Out[31]:
In [32]:
Ac2 = -1*Ac[2:4,0:2]
Ac2
Out[32]:
In [33]:
Ac1 = -1*Ac[2:4,2:4]
Ac1
Out[33]:
In [34]:
# Check Bc
Tc.dot(B)
Out[34]:
In [35]:
# Calculations for Kc
# (s+0.2)*(s+0.5) = s^2 + 0.7s + 0.1
d1 = 0.7
d2 = 0.1
# (s+5.0566)*(s+8.6659) = s^2 + 13.7225s + 43.82
d3 = 13.7225
d4 = 43.82
In [36]:
D1 = np.array([[d1,0],[0,d3]])
D1
Out[36]:
In [37]:
D2 = np.array([[d2,0],[0,d4]])
D2
Out[37]:
In [38]:
Kc1 = D1 - Ac1
Kc1
Out[38]:
In [39]:
Kc2 = D2 - Ac2
Kc2
Out[39]:
In [40]:
Kc = np.concatenate((Kc2,Kc1),1)
Kc
Out[40]:
In [41]:
K = Kc.dot(Tc)
K
Out[41]:
In [42]:
np.linalg.norm(K)
Out[42]:
In [43]:
A_hat = A - B.dot(K)
A_hat
Out[43]:
In [44]:
A_hat_eigvals, M_hat = np.linalg.eig(A_hat)
A_hat_eigvals
Out[44]:
In [45]:
idx = A_hat_eigvals.argsort()[::-1]
A_hat_eigvals = A_hat_eigvals[idx]
A_hat_eigvals
Out[45]:
In [46]:
M_hat = M_hat[:,idx]
In [47]:
np.linalg.cond(M_hat)
Out[47]:
In [ ]: