Control engineering study notes. The second.
Last time finds the transfer function / state space model from the equation of motion of the mass point of the spring-mass damper system, and the Python library of the control system "[[ I simulated using "Python Control Systems Library" (https://python-control.readthedocs.io/en/0.8.3/index.html).
This time, for ** RLC series circuit **, we will find the transfer function / state space model from the circuit equation and simulate it using Python.
![2020-04-28_09h00_39.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/152805/f10d0f88-eba1-d2ca-9ebc-75858504a7d3. png)
Normally, the circuit equation is formulated using ** current ** $ i (t) $ as follows.
However, here, in order to correspond to the dynamical system of previous, ** charge ** $ q (t) $ using the following relationship. I will write the circuit equation using.
The circuit equation with the charge $ q (t) $ is as follows.
Organize the formula by changing the derivative to dot notation.
This has the same form as the equation of motion of the mass point with one degree of freedom (below) in the spring-mass damper system shown in previous. You can see that.
In the model of mechanics, the transfer function was calculated with the force $ f (t) $ as the ** input ** to the system and the displacement $ y (t) $ as the ** output ** from the system.
If it corresponds to that, the transfer function is obtained by using the input voltage $ v \ _i (t) $ as the ** input ** for the system and the charge $ q (t) $ as the ** output ** from the system. However, it is not easy to directly observe (measure) the ** charge ** $ q (t) $ ** **. Also, in reality, it is the voltage of each element that is of interest. Therefore, ** in the case of an electric circuit, the transfer function is calculated using the voltage as the output **.
Here, the input voltage $ v \ i (t) $ is the ** input ** $ u (t) $ to the system, the voltage across the capacitor $ v {C} (t) $ is the system ** output **. Find the transfer function with $ y (t) $.
Make the above output an expression for $ q (t) $.
Change this to the above circuit equation $ L \ ddot {q} (t) + R \ dot {q} (t) + \ frac {1} {C} q (t) = v_ {i} (t) $ Substitute to get:
Laplace transforming this to find the system's ** transfer function ** $ G (s) = Y (s) / U (s) $ (at this time, $ \ dot {y} (Assuming 0) = 0 $ and $ y (0) = 0 $).
In the dynamic model, the transfer function with force as input and displacement as output, mass as $ m $, damping coefficient as $ c $, and spring constant as $ k $ is as follows. You can see that both the dynamical system and the circuit system have very similar shapes.
Use Python's ** Python Control Systems Library ** for simulation. Set the transfer function to model the system and simulate the ** step response **.
In the dynamical system, we simulated the ** impulse response ** to observe the displacement when a force is applied to the mass point for a moment, but in the electric circuit, the input voltage $ v_ {i} (t) = 1 \ Since it is more natural to observe the capacitor voltage $ v_ {C} $ when, (t \ ge0) $ is set, let's look at the ** step response **.
Preparation (Google Colab.environment)
!pip install --upgrade sympy
!pip install slycot
!pip install control
Step response simulation (transfer function)
import numpy as np
import control.matlab as ctrl
import matplotlib.pyplot as plt
R = 2 #Resistance value
L = 1e-3 #Inductance
C = 10e-6 #Capacitance
sys = ctrl.tf((1),(L*C,R*C,1))
print(sys)
t_range = (0,0.01)
y, t = ctrl.step(sys, T=np.linspace(*t_range, 400))
plt.figure(figsize=(7,4),dpi=120,facecolor='white')
plt.hlines(1,*t_range,colors='gray',ls=':')
plt.plot(t,y)
plt.xlim(*t_range)
plt.ylim(bottom=0)
plt.show()
Execution result
1
------------
s^2 + s + 10
Assuming that the input voltage is $ v_ {i} (t) = 1 , (t \ ge0) $, the capacitor voltage $ v_ {C} $ oscillates first and finally $ 1 , \ [\ You can see that it settles in mathrm {V} ] $.
Describe your system as a state-space model $ \ mathcal {P} $ as follows:
python
\mathcal{P}\,:\,\left\{
\begin{array}{l}
\dot{\boldsymbol{x}} = \mathbf{A}\boldsymbol{x} + \mathbf{B}\boldsymbol{u}&Equation of state\\
\boldsymbol{y} = \mathbf{C}\boldsymbol{x} + \mathbf{D}\boldsymbol{u}&Output equation (observation equation)
\end{array}
\right.
As a preparation, the circuit equation $ LC \ ddot {y} (t) + RC \ dot {y} (t) + y (t) = u (t) $, $ \ ddot {y} (t) = .. Transform it into .$.
As $ x \ _1 (t) = y (t) $, $ x \ _2 (t) = \ dot {y} (t) $, ** state ** $ \ boldsymbol {x} = \ [x \ _1 , , x \ _2] ^ T $ is set.
From this, $ \ dot {x} \ _1 (t) = \ dot {y} (t) = x \ _2 $. Also, $ \ dot {x} \ _2 (t) =-\ frac {1} {LC} y (t)-\ frac {R} {L} \ dot {y} (t) + \ frac {1} {LC} u (t) $.
From the above, the following ** equation of state ** can be obtained.
python
\left[
\begin{array}{c}
\dot{x}_1 \\
\dot{x}_2
\end{array}
\right]
=\left[
\begin{array}{cc}
0 & 1 \\
-\frac{1}{LC} & -\frac{R}{L}
\end{array}
\right]
\left[
\begin{array}{c}
x_1 \\
x_2
\end{array}
\right]
+ \left[
\begin{array}{c}
0 \\
\frac{1}{LC}
\end{array}
\right] u
python
\dot{\boldsymbol{x}}
=\left[
\begin{array}{cc}
0 & 1 \\
-\frac{1}{LC} & -\frac{R}{L}
\end{array}
\right]
\boldsymbol{x} + \left[
\begin{array}{cc}
0 \\
\frac{1}{LC}
\end{array}
\right] u
Also, obtain the following ** output equation ** (observation equation) (** capacitor voltage ** $ v_ {C} $ corresponding state $ x_1 $ and ** current ** corresponding $ Cx \ _2 (= C \ dot {y} (t) = C \ dot {v} _ {C} (t) = C \ big (\ frac {1} {C} \ dot {q} (t) \ big) = \ dot {q} (t) = i (t) ,) Observing $).
python
y = \left[
\begin{array}{cc}
1 & 0\\
0 & C\\
\end{array}
\right] \left[
\begin{array}{c}
x_1 \\
x_2
\end{array}
\right]
However, $ \ mathbf {D} = 0 $.
Simulate ** step response ** in the state space model.
Preparation for using Japanese in graphs (Google Colab.environment)
!pip install japanize-matplotlib
Simulation of step response (state space model)
import numpy as np
import control.matlab as ctrl
import matplotlib.pyplot as plt
import japanize_matplotlib
R = 2 #Resistance value
L = 1e-3 #Inductance
C = 10e-6 #Capacitance
A = [[0,1],[-1/(L*C), -R/L]]
B = [[0],[1/(L*C)]]
C = [[1,0],[0,C]]
D = 0
sys = ctrl.ss(A,B,C,D)
#print(sys)
t_range = (0,0.01)
y, t = ctrl.step(sys, T=np.linspace(*t_range, 400))
fig, ax = plt.subplots(nrows=2, figsize=(7,5),dpi=120,sharex='col')
fig.patch.set_facecolor('white')
fig.subplots_adjust(hspace=0.1)
for i,s in enumerate(['Capacitor voltage','Current']) :
ax[i].hlines(0,*t_range,colors='gray',ls=':')
ax[i].plot(t,y[:,i])
ax[i].set_ylabel(s)
ax[i].set_xlim(*t_range)
plt.show()
Recommended Posts