学习SVPWM过程中使用python做一些模拟与仿真(二)

第二部分主要是对合成矢量在哪一个扇区进行判断,然后计算出所在扇区相邻的两个矢量的作用时间,最后对合成矢量在非线性区的部分进行矫正;

至于理论相关的分析,请结合以下这两篇博客理解,不多介绍:


https://blog.csdn.net/michaelf/article/details/94013805?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.compare&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-6.compare#_138


https://blog.csdn.net/qlexcel/article/details/74787619#comments


python实现这部分的代码如下:

'''
author : sunyan
'''

from matplotlib import pyplot as plt
import numpy as np
import math

class SVPWM_sim:

    def __init__(self):
        plt.figure(figsize = (10, 10))
        self.fre_to_time = 5

    def three_phase_to_two(self):
        for thate in range(0, 361, self.fre_to_time):
            plt.cla()                                   # 清除之前画的图
    
            ua = math.cos(math.radians(thate))
            ub = math.cos(math.radians(thate - 120))
            uc = math.cos(math.radians(thate + 120))

            xa0 = 0 
            ya0 = 0
            xa1 = ua
            ya1 = 0

            xb0 = xa1 
            yb0 = ya1
            xb1 = xb0 + ub * math.cos(math.radians(120)) 
            yb1 = yb0 + ub * math.sin(math.radians(120))

            xc0 = xb1 
            yc0 = yb1
            xc1 = xc0 + uc * math.cos(math.radians(240))
            yc1 = yc0 + uc * math.sin(math.radians(240))

            xu0 = 0
            yu0 = 0
            xu1 = (3 / 2) * math.cos(math.radians(thate))
            yu1 = (3 / 2) * math.sin(math.radians(thate))

            plt.annotate('', xy = (xa1, ya1), xytext = (xa0, ya0), \
                    arrowprops = dict(color = 'blue', width = 1))
            plt.annotate('', xy = (xb1, yb1), xytext = (xb0, yb0), \
                    arrowprops = dict(color = 'red', width = 1))
            plt.annotate('', xy = (xc1, yc1), xytext = (xc0, yc0), \
                    arrowprops = dict(color = 'yellow', width = 1))
            plt.annotate('', xy = (xu1, yu1), xytext = (xu0, yu0), \
                    arrowprops = dict(color = 'black', width = 1))

            plt.xlim(-2, 2)                             # 设置x轴范围
            plt.ylim(-2, 2)                             # 设置y轴范围
            plt.grid(True)

            plt.pause(0.01 * self.fre_to_time)          # 暂停1/100秒
        
        plt.show()

    def three_phase_to_two(self, udc = 100, km = 1, thate = 0):

        print('thate is : ' + str(thate))
        Ts = 2 * math.pi * 1 / 10000
        K = math.sqrt(3) * Ts / udc
        
        uarfa = km * (2 / 3) * udc * math.cos(math.radians(thate))
        ubata = km * (2 / 3) * udc * math.sin(math.radians(thate))

        u1 = ubata
        u2 = (math.sqrt(3) / 2 * uarfa) - ubata / 2
        u3 = (-math.sqrt(3) / 2 * uarfa) - ubata / 2

        if u1 > 0:
            A = 1
        else:
            A = 0
        if u2 > 0:
            B = 1
        else:
            B = 0
        if u3 > 0:
            C = 1
        else:
            C = 0
        
        N = 4 * C + 2 * B + A

        if N == 3:
            time4 = K * u2
            time6 = K * u1
            time7 = Ts - time4 - time6
            if (time4 + time6) > Ts:
                time4 = time4 / (time4 + time6) * Ts
                time6 = time6 / (time4 + time6) * Ts
                time7 = 0
            T4 = time4 / Ts * 100
            T6 = time6 / Ts * 100
            T7 = time7 / 2 / Ts * 100
            print('扇区1')
            print('T4 的占空比是:' + str(T4) + '%')
            print('T6 的占空比是:' + str(T6) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')
        elif N == 1:
            time6 = -K * u3
            time2 = -K * u2
            time7 = Ts - time6 - time2
            if (time6 + time2) > Ts:
                time6 = time6 / (time6 + time2) * Ts
                time2 = time2 / (time6 + time2) * Ts
                time7 = 0
            T6 = time6 / Ts * 100
            T2 = time2 / Ts * 100
            T7 = time7 / 2 / Ts * 100
            print('扇区2')
            print('T6 的占空比是:' + str(T6) + '%')
            print('T2 的占空比是:' + str(T2) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')
        elif N == 5:
            time2 = K * u1
            time3 = K * u3
            time7 = Ts - time2 - time3
            if (time2 + time3) > Ts:
                time2 = time2 / (time2 + time3) * Ts
                time3 = time3 / (time2 + time3) * Ts
                time7 = 0
            T2 = time2 / Ts * 100
            T3 = time3 / Ts * 100
            T7 = time7 / 2 / Ts * 100
            print('扇区3')
            print('T2 的占空比是:' + str(T2) + '%')
            print('T3 的占空比是:' + str(T3) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')
        elif N == 4:
            time3 = -K * u2
            time1 = -K * u1
            time7 = Ts - time3 - time1
            if (time3 + time1) > Ts:
                time3 = time3 / (time3 + time1) * Ts
                time1 = time1 / (time3 + time1) * Ts
                time7 = 0
            T3 = time3 / Ts * 100
            T1 = time1 / Ts * 100
            T7 = time7 / 2 / Ts * 100
            print('扇区4')
            print('T3 的占空比是:' + str(T3) + '%')
            print('T1 的占空比是:' + str(T1) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')
        elif N == 6:
            time1 = K * u3
            time5 = K * u2
            time7 = Ts - time1 - time5
            if (time1 + time5) > Ts:
                time1 = time1 / (time1 + time5) * Ts
                time5 = time5 / (time1 + time5) * Ts
                time7 = 0
            T1 = time1 / Ts * 100
            T5 = time5 / Ts * 100
            T7 = time7 / 2 / Ts *100
            print('扇区5')
            print('T2 的占空比是:' + str(T1) + '%')
            print('T3 的占空比是:' + str(T5) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')
        elif N == 2:
            time5 = -K * u1
            time4 = -K * u3
            time7 = Ts - time5 - time4
            if (time5 + time4) > Ts:
                time5 = time5 / (time5 + time4) * Ts
                time4 = time4 / (time5 + time4) * Ts
                time7 = 0
            T5 = time5 / Ts * 100
            T4 = time4 / Ts * 100
            T7 = time7 / 2 / Ts * 100
            print('扇区6')
            print('T5 的占空比是:' + str(T5) + '%')
            print('T4 的占空比是:' + str(T4) + '%')
            print('T7 的占空比是:' + str(T7) + '%')
            print('T0 的占空比是:' + str(T7) + '%')

 PS:以后有时间补上代码相关的注释;

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值