Formulate the equation of state of a one-degree-of-freedom system (spring mass damper system), and convert the equation of state to a transfer function with Python Control. For comparison, the method and description of obtaining the transfer function from the Laplace transform are also described.
The equation of state is expressed by the following equation.
\dot{x}(t)=Ax(t)+Bu(t) \\
y(t)=Cx(t)+Du(t)
Laplace transform of the equation of state
sX(s)=AX(s)+BU(s) \\
Y(s)=CX(s)+DU(s)
When you convert the expression,
sX(s)-AX(s)=BU(s) \\
(sI-A)X(s)=BU(s) \\
X(s)={(sI-A)}^{-1} BU(s) \\
The transfer function G (s) is
G(s)=\frac{Y(s)}{U(s)}=\frac{{(sI-A)}^{-1} BU(s) +DU(s)}{U(s)}=(sI-A)^{-1} B +DU
Obtained from.
In Python-Control By inputting the matrix of A, B, C, D into the control.ss2tf function, the transfer function can be obtained according to the above equation. http://python-control.readthedocs.io/en/latest/generated/control.ss2tf.html
m: Mass [kg] k: Spring constant [N / m] c: Viscous damping coefficient [N ・ s / m] f: Force [N]
If you say The above equation of motion is
m\ddot{x}+c\dot{x}+kx=f \\
Will be.
Transform the formula here
m\ddot{x}+c\dot{x}+kx=f \\
m\ddot{x}=-c\dot{x}-kx+f \\
\ddot{x}=-c/m \dot{x}-k/m x+f/m \\
And.
x_{1}=x \\
x_{2}=\dot{x} \\
If you say
\\
\dot x_{1} ={x_{2}} \\
\dot x_{2}= -c/m \dot{x_{2}}-k/m x_{1}+f/m \\
If you write this in a matrix
\\
\begin{bmatrix}
\dot x_{1} \\
\dot x_{2}
\end{bmatrix}
=
\begin{bmatrix}
0 & 1 \\
-k/m & -c/m
\end{bmatrix}
\begin{bmatrix}
x_{1} \\
x_{2}
\end{bmatrix}
+
\begin{bmatrix}
0 \\
1/m
\end{bmatrix}
f
further,
y=If x,\\
y=
\begin{bmatrix}
1 & 0
\end{bmatrix}
\begin{bmatrix}
x_{1} \\
x_{2}
\end{bmatrix}
Therefore,
\\
\begin{bmatrix}
\dot x_{1} \\
\dot x_{2}
\end{bmatrix}
=
\begin{bmatrix}
0 & 1 \\
-k/m & -c/m
\end{bmatrix}
\begin{bmatrix}
x_{1} \\
x_{2}
\end{bmatrix}
+
\begin{bmatrix}
0 \\
1/m
\end{bmatrix}
f \\
y=
\begin{bmatrix}
1 & 0
\end{bmatrix}
\begin{bmatrix}
x_{1} \\
x_{2}
\end{bmatrix}
Compared to the equation of state
x(t)=
\begin{bmatrix}
x_{1} \\
x_{2}
\end{bmatrix}
,
u(t)=f
,
A=
\begin{bmatrix}
0 & 1 \\
-k/m & -c/m
\end{bmatrix}
,
B=
\begin{bmatrix}
0 \\
1/m
\end{bmatrix}
,
C=
\begin{bmatrix}
1 & 0
\end{bmatrix}
,
D=[0]
Will be.
From the above, The code to find the transfer function with python control is as follows.
-signal_degree_of_freedom_system_1.py
#!/usr/bin/env python
from control.matlab import *
from matplotlib import pyplot as plt
def main():
k=3.0
m=0.1
c=0.01
A = [[0., 1], [-k/m, -c/m]]
B = [[0.], [1./m]]
C = [[1., 0.0]]
D = [[0.]]
sys1 = ss2tf(A, B, C, D)
print sys1
bode(sys1)
plt.show()
if __name__ == "__main__":
main()
Execution result
$ ./signal_degree_of_freedom_system_1.py
10
----------------
s^2 + 0.1 s + 30
From the equation of state equation, when u (t) = f,
m\ddot{x}(t)+c\dot{x}(t)+kx(t)=u(t) \\
Laplace transform
ms^2X(s)+cX(s)+kX(s)=U(s) \\
Furthermore, if y = x,
ms^2Y(s)+cY(s)+kY(s)=U(s) \\
\frac{Y(s)}{U(s)}=\frac{1}{ms^2+cs+k}
The transfer function is
G(s)=\frac{Y(s)}{U(s)}=\frac{1}{ms^2+cs+k}
From the above, The code to find the transfer function with python control is as follows.
#!/usr/bin/env python
from control.matlab import *
from matplotlib import pyplot as plt
def main():
k=3.0
m=0.1
c=0.01
num = [0, 0,1]
den = [m, c, k]
sys = tf(num, den)
print sys
bode(sys)
plt.show()
if __name__ == "__main__":
main()
Execution result
$ ./signal_degree_of_freedom_system_2.py
1
--------------------
0.1 s^2 + 0.01 s + 3
Sample code is stored below. https://github.com/nnn112358/python-control_test
Recommended Posts