加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tx_test_svpwm.py 20.71 KB
一键复制 编辑 原始数据 按行查看 历史
kp9527 提交于 2024-11-25 17:50 . 2023-11-01
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
import numpy as np
import matplotlib.pyplot as plt
# from scipy import signal
import clark_park as cp
SQRT_3 = np.sqrt(3)*32767
Tpwm = 2400 #pwm arr
Udc = 12 #母线电压
K = int(SQRT_3 * Tpwm / Udc/32768)#np.sqrt(3) * Tpwm / Udc #调制系数怎么得出来
def svpwm_creat(Ualpha, Ubeta, elec_angle):
#求出判断扇区的三个变量
Ua, Ub, Uc = cp.svpwm_alpha_beta_to_Uabc(Ualpha, Ubeta)
# print(K)
a = Ua.copy()
a[a>0] = 1
a[a<=0] = 0
b = Ub.copy()
b[b>0] = 1
b[b<=0] = 0
c = Uc.copy()
c[c>0] = 1
c[c<=0] = 0
sentor = 1 * a + 2 * b + 4 * c
# print(sentor)
#求出计算占空比的三个电压量
ARRa = []
ARRb = []
ARRc = []
for i in range(len(elec_angle)):
# 举例
# T7 = (T - Tx -Ty) / 2
# Ta = Tx + Ty + T7 = (T +Tx + Ty) / 2 最长
# Tb = Ta - Tx 中间
# Tc = Tb - ty 最短
# Ua = b , Ub = a - b , Uc = -a - b
if sentor[i] == 3:#N=3 S=1 Tx = T4 Ty = T6
# Tx = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T4 (a - b)
# Ty = K * Ubeta[i] #T6 b
Tx = K * Ub[i] #T4 (a - b)
Ty = K * Ua[i] #T6 b
# a b---c
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 1:#N=1 S=2 Tx = T2 Ty = T6
# Tx = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T2 -(a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T6 -(-a - b)
Tx = K * -Ub[i] #T2 -(a - b)
Ty = K * -Uc[i] #T6 -(-a - b)
# b a---c
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 5:#N=5 S=3 Tx = T2 Ty = T3
# Tx = K * Ubeta[i] #T2 b
# Ty = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T3 (-a - b)
Tx = K * Ua[i] #T2 b
Ty = K * Uc[i] #T3 (-a - b)
# b c---a
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 4:#N=4 S=4 Tx = T1 Ty = T3
# Tx = K * -Ubeta[i] #T1 -b
# Ty = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T3 -(a - b)
Tx = K * -Ua[i] #T1 -b
Ty = K * -Ub[i] #T3 -(a - b)
# c b---a
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 6:#N=6 S=5 Tx = T1 Ty = T5
# Tx = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T1 (-a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T5 (a - b)
Tx = K * Uc[i] #T1 (-a - b)
Ty = K * Ub[i] #T5 (a - b)
# c a---b
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 2:#N=2 S=6 Tx = T4 Ty = T5
# Tx = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T4 -(-a - b)
# Ty = K * -Ubeta[i] #T5 -b
Tx = K * -Uc[i] #T4 -(-a - b)
Ty = K * -Ua[i] #T5 b
# a c---b
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
Da = np.array(ARRa)
Db = np.array(ARRb)
Dc = np.array(ARRc)
Da = Da / Tpwm
Db = Db / Tpwm
Dc = Dc / Tpwm
plt.figure("U alpha beta")
plt.plot(elec_angle, Ualpha, label='Ualpha')
plt.plot(elec_angle, Ubeta, label='Ubeta')
plt.ylabel('alpha, beta')
# plt.legend()
plt.figure("U Ua Ub Uc")
plt.plot(elec_angle, Ua, label='ux')
plt.plot(elec_angle, Ub, label='uy')
plt.plot(elec_angle, Uc, label='uy')
plt.ylabel('X Y Z')
# plt.legend()
plt.figure("ARR a b c")
plt.plot(elec_angle, ARRa, label='A')
plt.plot(elec_angle, ARRb, label='B')
plt.plot(elec_angle, ARRc, label='C')
plt.ylabel('svpwm arr')
# plt.legend()
plt.figure("duty a b c")
plt.plot(elec_angle, Da, label='A')
plt.plot(elec_angle, Db, label='B')
plt.plot(elec_angle, Dc, label='C')
plt.ylabel('svpwm duty')
# plt.legend()
return Da, Db, Dc
def svpwm_creat_if(Ualpha, Ubeta, elec_angle):
#求出判断扇区的三个变量
Ua, Ub, Uc = cp.svpwm_alpha_beta_to_Uabc(Ualpha, Ubeta)
# print(type(Ua))
print(K)
a = Ua.copy()
a[a>0] = 1
a[a<=0] = 0
b = Ub.copy()
b[b>0] = 1
b[b<=0] = 0
c = Uc.copy()
c[c>0] = 1
c[c<=0] = 0
sentor = 1 * a + 2 * b + 4 * c
# print(sentor)
#求出计算占空比的三个电压量
ARRa = []
ARRb = []
ARRc = []
''' 未验证
for i in range(len(elec_angle)):
if c[i] > 0:
if b[i] > 0:
#sentor = 2
Tx = K * -Uc[i] #T4 -(-a - b)
Ty = K * -Ua[i] #T5 b
# a c---b
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
else:
if a[i] > 0:
#sentor = 1
Tx = K * -Ub[i] #T2 -(a - b)
Ty = K * -Uc[i] #T6 -(-a - b)
# b a---c
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
else:
#sentor = 6
Tx = K * Uc[i] #T1 (-a - b)
Ty = K * Ub[i] #T5 (a - b)
# c a---b
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
else:
if b[i] > 0:
if a[i] > 0:
#sentor = 3
Tx = K * Ub[i] #T4 (a - b)
Ty = K * Ua[i] #T6 b
# a b---c
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
else:
#sentor = 4
Tx = K * -Ua[i] #T1 -b
Ty = K * -Ub[i] #T3 -(a - b)
# c b---a
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
else:
#sentor = 5
Tx = K * Ua[i] #T2 b
Ty = K * Uc[i] #T3 (-a - b)
# b c---a
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
'''
# '''
for i in range(len(elec_angle)):
# sentor[i] = 0
if a[i] > 0 :
sentor[i] = 1
else:
sentor[i] = 0
if b[i] > 0 :
sentor[i] = sentor[i] + 2
# else:
# sentor[i] = 0
if c[i] > 0 :
sentor[i] = sentor[i] + 4
# else:
# sentor[i] = 0
# 举例
# T7 = (T - Tx -Ty) / 2
# Ta = Tx + Ty + T7 = (T +Tx + Ty) / 2 最长
# Tb = Ta - Tx 中间
# Tc = Tb - ty 最短
# Ua = b , Ub = a - b , Uc = -a - b
if sentor[i] == 3:#N=3 S=1 Tx = T4 Ty = T6
# Tx = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T4 (a - b)
# Ty = K * Ubeta[i] #T6 b
Tx = (K * Ub[i])/256 #T4 (a - b)
Ty = (K * Ua[i])/256 #T6 b
# a b---c
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 1:#N=1 S=2 Tx = T2 Ty = T6
# Tx = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T2 -(a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T6 -(-a - b)
Tx = (K * -Ub[i])/256 #T2 -(a - b)
Ty = (K * -Uc[i])/256 #T6 -(-a - b)
# b a---c
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 5:#N=5 S=3 Tx = T2 Ty = T3
# Tx = K * Ubeta[i] #T2 b
# Ty = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T3 (-a - b)
Tx = (K * Ua[i])/256 #T2 b
Ty = (K * Uc[i])/256 #T3 (-a - b)
# b c---a
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 4:#N=4 S=4 Tx = T1 Ty = T3
# Tx = K * -Ubeta[i] #T1 -b
# Ty = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T3 -(a - b)
Tx = (K * -Ua[i])/256 #T1 -b
Ty = (K * -Ub[i])/256 #T3 -(a - b)
# c b---a
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 6:#N=6 S=5 Tx = T1 Ty = T5
# Tx = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T1 (-a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T5 (a - b)
Tx = (K * Uc[i])/256 #T1 (-a - b)
Ty = (K * Ub[i])/256 #T5 (a - b)
# c a---b
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 2:#N=2 S=6 Tx = T4 Ty = T5
# Tx = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T4 -(-a - b)
# Ty = K * -Ubeta[i] #T5 -b
Tx = (K * -Uc[i])/256 #T4 -(-a - b)
Ty = (K * -Ua[i])/256 #T5 b
# a c---b
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
# '''
'''
for i in range(len(elec_angle)):
# 举例
# T7 = (T - Tx -Ty) / 2
# Ta = Tx + Ty + T7 = (T +Tx + Ty) / 2 最长
# Tb = Ta - Tx 中间
# Tc = Tb - ty 最短
# Ua = b , Ub = a - b , Uc = -a - b
if sentor[i] == 3:#N=3 S=1 Tx = T4 Ty = T6
# Tx = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T4 (a - b)
# Ty = K * Ubeta[i] #T6 b
Tx = K * Ub[i] #T4 (a - b)
Ty = K * Ua[i] #T6 b
# a b---c
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 1:#N=1 S=2 Tx = T2 Ty = T6
# Tx = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T2 -(a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T6 -(-a - b)
Tx = K * -Ub[i] #T2 -(a - b)
Ty = K * -Uc[i] #T6 -(-a - b)
# b a---c
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 5:#N=5 S=3 Tx = T2 Ty = T3
# Tx = K * Ubeta[i] #T2 b
# Ty = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T3 (-a - b)
Tx = K * Ua[i] #T2 b
Ty = K * Uc[i] #T3 (-a - b)
# b c---a
ARRb.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 4:#N=4 S=4 Tx = T1 Ty = T3
# Tx = K * -Ubeta[i] #T1 -b
# Ty = K * (-np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T3 -(a - b)
Tx = K * -Ua[i] #T1 -b
Ty = K * -Ub[i] #T3 -(a - b)
# c b---a
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 6:#N=6 S=5 Tx = T1 Ty = T5
# Tx = K * (-np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T1 (-a - b)
# Ty = K * (np.sqrt(3) * Ualpha[i] - Ubeta[i]) / 2 #T5 (a - b)
Tx = K * Uc[i] #T1 (-a - b)
Ty = K * Ub[i] #T5 (a - b)
# c a---b
ARRc.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRa.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
elif sentor[i] == 2:#N=2 S=6 Tx = T4 Ty = T5
# Tx = K * (np.sqrt(3) * Ualpha[i] + Ubeta[i]) / 2 #T4 -(-a - b)
# Ty = K * -Ubeta[i] #T5 -b
Tx = K * -Uc[i] #T4 -(-a - b)
Ty = K * -Ua[i] #T5 b
# a c---b
ARRa.append( (Tpwm + Tx + Ty) / 2 ) #计算总控比计数值
ARRc.append( (Tpwm + Tx + Ty) / 2 - Tx)
ARRb.append( (Tpwm + Tx + Ty) / 2 - Tx - Ty)
'''
Da = np.array(ARRa)
Db = np.array(ARRb)
Dc = np.array(ARRc)
Da = Da / Tpwm
Db = Db / Tpwm
Dc = Dc / Tpwm
plt.figure("alpha, beta")
# plt.title('alpha, beta')
plt.plot(Ualpha, label='Ualpha')
plt.plot(Ubeta, label='Ubeta')
plt.ylabel('alpha, beta')
# plt.legend()
plt.figure('X Y Z')
plt.plot(Ua, label='ux')
plt.plot(Ub, label='uy')
plt.plot(Uc, label='uy')
plt.ylabel('X Y Z')
# plt.legend()
plt.figure('svpwm arr')
plt.plot(ARRa, label='A')
plt.plot(ARRb, label='B')
plt.plot(ARRc, label='C')
plt.ylabel('svpwm arr')
# plt.legend()
plt.figure('svpwm duty')
plt.plot(Da, label='A')
plt.plot(Db, label='B')
plt.plot(Dc, label='C')
plt.ylabel('svpwm duty')
# plt.legend()
return Da, Db, Dc
def svpwm_yb(Ualpha, Ubeta, elec_angle):
K_svpwm = 1.5
da = []
db = []
dc = []
ARRa = []
ARRb = []
ARRc = []
sersenList = []
for i in range(len(elec_angle)):
Va_abs = np.abs(Ualpha[i])
Vb3_abs = np.abs(Ubeta[i] / np.sqrt(3))
if Ualpha[i] >= 0 and Ubeta[i]>=0 and Va_abs>=Vb3_abs:
#sentor 1
d4 = K_svpwm * (Ualpha[i] - Ubeta[i]/np.sqrt(3)) / Udc
d6 = K_svpwm * (Ubeta[i] * 2 / np.sqrt(3) ) / Udc
d7 = ( 1 - d4 - d6) / 2
da.append(d4 + d6 + d7) #A相高电平占空比
db.append(d6 + d7) #B相高电平占空比
dc.append(d7) #C相高电平占空比
sersenList.append(1)
elif Ubeta[i]>=0 and Va_abs<=Ubeta[i]/np.sqrt(3):
#sentor 2
d6 = K_svpwm * (Ualpha[i] + Ubeta[i]/np.sqrt(3)) / Udc
d2 = K_svpwm * (-Ualpha[i] + Ubeta[i] / np.sqrt(3) ) / Udc
d7 = ( 1 - d2 - d6) / 2
da.append(d6 + d7) #A相高电平占空比
db.append(d2 + d6 + d7) #B相高电平占空比
dc.append(d7) #C相高电平占空比
sersenList.append(2)
elif Ualpha[i]<=0 and Ubeta[i]>=0 and Va_abs>=Vb3_abs:
#sentor 3
d2 = K_svpwm * (2 * Ubeta[i]/np.sqrt(3)) / Udc
d3 = K_svpwm * (-Ualpha[i] - Ubeta[i] / np.sqrt(3) ) / Udc
d7 = ( 1 - d2 - d3) / 2
da.append(d7) #A相高电平占空比
db.append(d2 + d3 + d7) #B相高电平占空比
dc.append(d3 + d7) #C相高电平占空比
sersenList.append(3)
elif Ualpha[i]<=0 and Ubeta[i]<=0 and Va_abs>=Vb3_abs:
#sentor 4
d1 = -K_svpwm * (2 * Ubeta[i]/np.sqrt(3)) / Udc
d3 = K_svpwm * (-Ualpha[i] + Ubeta[i] / np.sqrt(3) ) / Udc
d7 = ( 1 - d3 - d1) / 2
da.append(d7) #A相高电平占空比
db.append(d3 + d7) #B相高电平占空比
dc.append(d1 + d3 + d7) #C相高电平占空比
sersenList.append(4)
elif Va_abs<=-Ubeta[i]/np.sqrt(3):
#sentor 5
d1 = K_svpwm * (-Ualpha[i] - Ubeta[i] / np.sqrt(3) ) / Udc
d5 = K_svpwm * (Ualpha[i] - Ubeta[i] / np.sqrt(3) ) / Udc
d7 = ( 1 - d5 - d1) / 2
da.append(d5 + d7) #A相高电平占空比
db.append(d7) #B相高电平占空比
dc.append(d1 + d5 + d7) #C相高电平占空比
sersenList.append(5)
elif Ualpha[i]>=0 and Ubeta[i]<=0 and Va_abs>=Vb3_abs:
#sentor 6
d4 = K_svpwm * (Ualpha[i] + Ubeta[i] / np.sqrt(3) ) / Udc
d5 = -K_svpwm * (2 * Ubeta[i] / np.sqrt(3) ) / Udc
d7 = ( 1 - d5 - d4) / 2
da.append(d4 + d5 + d7) #A相高电平占空比
db.append(d7) #B相高电平占空比
dc.append(d5 + d7) #C相高电平占空比
sersenList.append(6)
else:
print("err", i, len(elec_angle))
ARRa.append(Tpwm * da[-1])
ARRb.append(Tpwm * db[-1])
ARRc.append(Tpwm * dc[-1])
plt.figure("svpwm U alpha beta")
plt.plot(Ualpha, label='Ualpha')
plt.plot(Ubeta, label='Ubeta')
plt.plot(elec_angle, label='theta')
plt.ylabel('alpha, beta')
plt.legend()
# plt.figure("U Ua Ub Uc")
# plt.plot(elec_angle, Ua, label='ux')
# plt.plot(elec_angle, Ub, label='uy')
# plt.plot(elec_angle, Uc, label='uy')
# plt.ylabel('X Y Z')
# plt.legend()
plt.figure("svpwm ARR a b c")
sersenListBig = [i * 100 for i in sersenList]
plt.plot(ARRa, label='A')
plt.plot(ARRb, label='B')
plt.plot(ARRc, label='C')
plt.plot(elec_angle, label='theta')
# plt.plot(sersenListBig, label='C')
plt.ylabel('svpwm arr')
plt.legend()
plt.figure("svpwm duty a b c")
plt.plot(da, label='A')
plt.plot(db, label='B')
plt.plot(dc, label='C')
plt.plot(sersenList, label='C')
plt.plot(elec_angle, label='C')
plt.ylabel('svpwm duty')
plt.legend()
# return Da, Db, Dc
#输入三相电压,输出三相占空比
def svpwm_out(ARRa, ARRb, ARRc):
print(ARRa)
if __name__ == "__main__":
rpm_in = 1000
pole_in = 5
Pwm_frq = 16000
eRpm = rpm_in * pole_in / 60
eStep = 16384 * eRpm / Pwm_frq
print("rpm_in", rpm_in, "pole_in", pole_in, "eRpm", eRpm, "eStep", eStep)
elec_angle = np.arange(0, 1000, 1)
elec_angle = elec_angle * 2 * np.pi / 1000
elec_angle = elec_angle - np.pi
dem_Uq = 6.9 #Uq的最大值是 Udc/sqrt(3) cos30 * 2/3 Udc = sqrt(3)/2 * 2/3 * udc = udc/qurt(3)
dem_Ud = 3
dem_Uq = np.sqrt(Udc*Udc/3 - dem_Ud*dem_Ud)
print("cal :", dem_Uq, dem_Ud, Udc)
Ualpha, Ubeta = cp.park_inverse_conversion(dem_Uq, dem_Ud, elec_angle)
# plt.figure("Iq Id to alpha-beta")
# plt.plot(elec_angle, Ualpha, label='Uafla')
# plt.plot(elec_angle, Ubeta, label='Ubeta')
# plt.ylabel('alpha-beta')
# plt.legend()
# ARRa, ARRb, ARRc = svpwm_creat(Ualpha, Ubeta, elec_angle)#旧计算方式
svpwm_yb(Ualpha, Ubeta, elec_angle)
# svpwm_out(ARRa, ARRb, ARRc)
plt.show()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化