利用Python制作动图演示坐标变换理论

利用Python制作动图演示坐标变换理论

永磁同步电机是一个非线性、强耦合的物理系统,因而不便直接进行控制。后有研究人员创造性的提出了坐标变换理论(后逐渐成为矢量控制的一个部分),让永磁同步电机得以转化为一种类直流电机模型,此时电机成为了一个弱耦合系统,电压表达式中仍含有直流耦合项。本文通过Python演示了矢量控制中的坐标变换过程,读者需对矢量控制中的坐标变换理论较为了解。

电脑需要一个能运行Python代码的环境,我使用的软件环境

  • Sublime Text
  • 可能需要借助anaconda安装一些依赖库

坐标变换理论的一种数学形式

下文以三相电流的数学形式描述坐标变换理论,此处采用余弦形式
[ i a i b i c ] = [ I 1 cos ⁡ ( ω e t ) I 1 cos ⁡ ( ω e t − 2 3 π ) I 1 cos ⁡ ( ω e t + 2 3 π ) ] \left[ \begin{array}{c} i_a\\ i_b\\ i_c\\ \end{array} \right] =\left[ \begin{array}{c} I_1\cos \left( \omega _et \right)\\ I_1\cos \left( \omega _et-\frac{2}{3}\pi \right)\\ I_1\cos \left( \omega _et+\frac{2}{3}\pi \right)\\ \end{array} \right] iaibic=I1cos(ωet)I1cos(ωet32π)I1cos(ωet+32π)
式中: I 1 I_1 I1是相电流幅值, ω e \omega_e ωe是电频率, i a i_a ia i b i_b ib i c i_c ic是相电流

三相自然坐标系至两相静止坐标系的变换矩阵为
T 3 s / 2 s = 2 3 [ 1 − 1 2 − 1 2 0 3 2 − 3 2 2 2 2 2 2 2 ] \boldsymbol{T}_{3s/2s}=\frac{2}{3}\left[ \begin{matrix} 1& -\frac{1}{2}& -\frac{1}{2}\\ 0& \frac{\sqrt{3}}{2}& -\frac{\sqrt{3}}{2}\\ \frac{\sqrt{2}}{2}& \frac{\sqrt{2}}{2}& \frac{\sqrt{2}}{2}\\ \end{matrix} \right] T3s/2s=321022 2123 22 2123 22

[ i α i β ] = T 3 s / 2 s [ i a i b i c ] \left[ \begin{array}{c} i_{\alpha}\\ i_{\beta}\\ \end{array} \right] =\boldsymbol{T}_{3s/2s}\left[ \begin{array}{c} i_a\\ i_b\\ i_c\\ \end{array} \right] [iαiβ]=T3s/2siaibic

i α = 2 3 [ I 1 cos ⁡ ( ω e t ) − 1 2 I 1 cos ⁡ ( ω e t − 2 3 π ) − 1 2 I 1 cos ⁡ ( ω e t − 4 3 π ) ] = 2 3 [ I 1 cos ⁡ ( ω e t ) − 1 2 × 2 I 1 cos ⁡ ( ω e t ) cos ⁡ ( 2 π 3 ) ] = I 1 cos ⁡ ( ω e t ) \begin{aligned} i_{\alpha}&=\frac{2}{3}\left[ I_1\cos \left( \omega _et \right) -\frac{1}{2}I_1\cos \left( \omega _et-\frac{2}{3}\pi \right) -\frac{1}{2}I_1\cos \left( \omega _et-\frac{4}{3}\pi \right) \right] \\ &=\frac{2}{3}\left[ I_1\cos \left( \omega _et \right) -\frac{1}{2}\times 2I_1\cos \left( \omega _et \right) \cos \left( \frac{2\pi}{3} \right) \right] \\ &=I_1\cos \left( \omega _et \right) \end{aligned} iα=32[I1cos(ωet)21I1cos(ωet32π)21I1cos(ωet34π)]=32[I1cos(ωet)21×2I1cos(ωet)cos(32π)]=I1cos(ωet)

i β = 2 3 [ 3 2 I 1 cos ⁡ ( ω e t − 2 3 π ) − 3 2 I 1 cos ⁡ ( ω e t − 4 3 π ) ] = 2 3 × 3 2 × 2 I 1 sin ⁡ ( ω e t ) sin ⁡ ( 2 π 3 ) = I 1 sin ⁡ ( ω e t ) \begin{aligned} i_{\beta}&=\frac{2}{3}\left[ \frac{\sqrt{3}}{2}I_1\cos \left( \omega _et-\frac{2}{3}\pi \right) -\frac{\sqrt{3}}{2}I_1\cos \left( \omega _et-\frac{4}{3}\pi \right) \right] \\ &=\frac{2}{3}\times \frac{\sqrt{3}}{2}\times 2I_1\sin \left( \omega _et \right) \sin \left( \frac{2\pi}{3} \right) \\ &=I_1\sin \left( \omega _et \right) \end{aligned} iβ=32[23 I1cos(ωet32π)23 I1cos(ωet34π)]=32×23 ×2I1sin(ωet)sin(32π)=I1sin(ωet)

两相静止坐标系至旋转坐标系的变换矩阵为
T 2 s / 2 r = [ cos ⁡ ( ω e t ) sin ⁡ ( ω e t ) − sin ⁡ ( ω e t ) cos ⁡ ( ω e t ) ] \boldsymbol{T}_{2s/2r}=\left[ \begin{matrix} \cos \left( \omega _et \right)& \sin \left( \omega _et \right)\\ -\sin \left( \omega _et \right)& \cos \left( \omega _et \right)\\ \end{matrix} \right] T2s/2r=[cos(ωet)sin(ωet)sin(ωet)cos(ωet)]

[ i d i q ] = T 2 s / 2 r [ i α i β ] \left[ \begin{array}{c} i_d\\ i_q\\ \end{array} \right] =\boldsymbol{T}_{2s/2r}\left[ \begin{array}{c} i_{\alpha}\\ i_{\beta}\\ \end{array} \right] [idiq]=T2s/2r[iαiβ]

i d = cos ⁡ ( ω e t ) i α + sin ⁡ ( ω e t ) i β = I 1 \begin{aligned} i_d&=\cos \left( \omega _et \right) i_{\alpha}+\sin \left( \omega _et \right) i_{\beta} \\ &=I_1 \end{aligned} id=cos(ωet)iα+sin(ωet)iβ=I1

i q = − sin ⁡ ( ω e t ) i α + cos ⁡ ( ω e t ) i β = 0 \begin{aligned} i_q&=-\sin \left( \omega _et \right) i_{\alpha}+\cos \left( \omega _et \right) i_{\beta} \\ &=0 \end{aligned} iq=sin(ωet)iα+cos(ωet)iβ=0

若三相电流采用正弦(sin)形式,则各轴系的电流分量为
[ i a i b i c ] = [ I 1 sin ⁡ ( ω e t ) I 1 sin ⁡ ( ω e t − 2 π 3 ) I 1 sin ⁡ ( ω e t − 4 π 3 ) ] \left[ \begin{array}{c} i_a\\ i_b\\ i_c\\ \end{array} \right] =\left[ \begin{array}{c} I_1\sin \left( \omega _et \right)\\ I_1\sin \left( \omega _et-\frac{2\pi}{3} \right)\\ I_1\sin \left( \omega _et-\frac{4\pi}{3} \right)\\ \end{array} \right] iaibic=I1sin(ωet)I1sin(ωet32π)I1sin(ωet34π)

[ i α i β ] = [ I 1 sin ⁡ ( ω e t ) − I 1 cos ⁡ ( ω e t ) ] \left[ \begin{array}{c} i_{\alpha}\\ i_{\beta}\\ \end{array} \right] =\left[ \begin{array}{c} I_1\sin \left( \omega _et \right)\\ -I_1\cos \left( \omega _et \right)\\ \end{array} \right] [iαiβ]=[I1sin(ωet)I1cos(ωet)]

[ i d i q ] = [ 0 − I 1 ] \left[ \begin{array}{c} i_d\\ i_q\\ \end{array} \right] =\left[ \begin{array}{c} 0\\ -I_1\\ \end{array} \right] [idiq]=[0I1]

三相坐标系动图代码

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig1, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line1, = ax.plot(x, np.cos(x),label="$f_a$")
line2, = ax.plot(x, np.cos(x-2*np.pi/3),label="$f_b$")
line3, = ax.plot(x, np.cos(x-4*np.pi/3),label="$f_c$")

def animate(i):
    line1.set_ydata(np.cos(x + i / 50))  # update the data.
    line2.set_ydata(np.cos(x + i / 50-2*np.pi/3))
    line3.set_ydata(np.cos(x + i / 50-4*np.pi/3))
    return line1,line2,line3

ani = animation.FuncAnimation(
    fig1, animate, interval=20, blit=True, save_count=50)

plt.legend(loc='upper center', bbox_to_anchor=(0.9, 0.98),shadow=False)
plt.xticks([])
plt.yticks([])
# plt.axis('off')
plt.show()

# export gif
writer = animation.PillowWriter(
    fps=15, metadata=dict(artist='Me'), bitrate=1800)
ani.save("three_phase_voltage.gif", writer=writer)

代码运行结果

利用Python制作动图演示坐标变换理论_第1张图片

两相静止坐标系动图源代码

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig1, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
y1 = 2/3*(np.cos(x)-1/2*np.cos(x-2*np.pi/3)-1/2*np.cos(x-4*np.pi/3))
y2 = 2/3*(np.sqrt(3)/2*np.cos(x-2*np.pi/3)-np.sqrt(3)/2*np.cos(x-4*np.pi/3))

line1, = ax.plot(x, y1 ,label="$f_{\\alpha}$")
line2, = ax.plot(x, y2 ,label="$f_{\\beta}$")

def animate(i):
    line1.set_ydata(2/3*(np.cos(x + i / 50)-1/2*np.cos(x + i / 50-2*np.pi/3)-1/2*np.cos(x + i / 50-4*np.pi/3)))  # update the data.
    line2.set_ydata(2/3*(np.sqrt(3)/2*np.cos(x + i / 50-2*np.pi/3)-np.sqrt(3)/2*np.cos(x + i / 50-4*np.pi/3)))
    return line1,line2

ani = animation.FuncAnimation(
    fig1, animate, interval=20, blit=True, save_count=50)

plt.legend(loc='upper center', bbox_to_anchor=(0.9, 0.98),shadow=False)
plt.xticks([])
plt.yticks([])
# plt.axis('off')
plt.show()

# export gif
writer = animation.PillowWriter(
    fps=15, metadata=dict(artist='Me'), bitrate=1800)
ani.save("clarke_3st2s.gif", writer=writer)

代码运行结果

利用Python制作动图演示坐标变换理论_第2张图片

运动轴系动图源代码

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig1, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.001)

y5 = np.cos(x)*(2/3*(np.cos(x)-1/2*np.cos(x-2*np.pi/3)-1/2*np.cos(x-4*np.pi/3)))+np.sin(x)*(2/3*(np.sqrt(3)/2*np.cos(x-2*np.pi/3)-np.sqrt(3)/2*np.cos(x-4*np.pi/3)))
y6 = -np.sin(x)*(2/3*(np.cos(x)-1/2*np.cos(x-2*np.pi/3)-1/2*np.cos(x-4*np.pi/3)))+np.cos(x)*(2/3*(np.sqrt(3)/2*np.cos(x-2*np.pi/3)-np.sqrt(3)/2*np.cos(x-4*np.pi/3)))

line1, = ax.plot(x, y5 ,label="$f_d$")
line2, = ax.plot(x, y6 ,label="$f_q$")

def animate(i):
    line1.set_ydata(np.cos(x + i / 50)*(2/3*(np.cos(x + i / 50)-1/2*np.cos(x + i / 50-2*np.pi/3)-1/2*np.cos(x + i / 50-4*np.pi/3)))+np.sin(x + i / 50)*(2/3*(np.sqrt(3)/2*np.cos(x + i / 50-2*np.pi/3)-np.sqrt(3)/2*np.cos(x + i / 50-4*np.pi/3))))  # update the data.
    line2.set_ydata(-np.sin(x + i / 50)*(2/3*(np.cos(x + i / 50)-1/2*np.cos(x + i / 50-2*np.pi/3)-1/2*np.cos(x + i / 50-4*np.pi/3)))+np.cos(x + i / 50)*(2/3*(np.sqrt(3)/2*np.cos(x + i / 50-2*np.pi/3)-np.sqrt(3)/2*np.cos(x + i / 50-4*np.pi/3))))
    return line1,line2

ani = animation.FuncAnimation(
    fig1, animate, interval=20, blit=True, save_count=50)

plt.legend(loc='upper center', bbox_to_anchor=(0.9, 0.96),shadow=False)
plt.xticks([])
plt.yticks([])
# plt.axis('off')

plt.show()

# ecxport GIF
writer = animation.PillowWriter(
    fps=15, metadata=dict(artist='Me'), bitrate=1800)
ani.save("park_2st2r.gif", writer=writer)

代码运行结果

利用Python制作动图演示坐标变换理论_第3张图片

代码拓展

对于二维物理描述,若能给出时域数学表达式,可以在本文代码的基础上进行修改,替换相应的数学表达式即可获得动图。

参考文献

https://matplotlib.org/stable/gallery/animation/simple_anim.html#sphx-glr-gallery-animation-simple-anim-py

你可能感兴趣的:(电机控制,矢量控制,坐标变换,python,动画)