Exemplo n.º 1
0
def display_state_and_command(time, X, U):

    titles_state = ['$\\theta$', '$\omega$', '$i_u$', '$i_v$', '$i_w$']
    titles_cmd = ['$u_l$', '$u_h$', '$v_l$', '$v_h$', '$w_l$', '$w_h$']
    for i in range(0, 2):
        plt.subplot(6, 2, 2 * i + 1)
        plt.plot(time, mu.deg_of_rad(X[:, i]), 'r', linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(2, dm.sv_size):
        plt.subplot(6, 2, 2 * i + 1)
        plt.plot(time, X[:, i], 'r', linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(0, 6):
        plt.subplot(6, 2, 2 * i + 2)
        plt.plot(time, U[:, i], 'r', linewidth=3.0)
        plt.title(titles_cmd[i])
Exemplo n.º 2
0
def display_state_and_command(time, X, U):

    titles_state = ['$\\theta$', '$\omega$', '$i_u$', '$i_v$', '$i_w$']
    titles_cmd = ['$u_l$', '$u_h$', '$v_l$', '$v_h$', '$w_l$', '$w_h$']
    for i in range(0, 2):
        plt.subplot(6, 2, 2*i+1)
        plt.plot(time,mu.deg_of_rad(X[:,i]), 'r', linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(2, dm.sv_size):
        plt.subplot(6, 2, 2*i+1)
        plt.plot(time, X[:,i], 'r', linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(0, 6):
        plt.subplot(6, 2, 2*i+2)
        plt.plot(time, U[:,i], 'r', linewidth=3.0)
        plt.title(titles_cmd[i])
Exemplo n.º 3
0
def display_state_and_command(time, X, U):

    titles_state = ["$\\theta$", "$\omega$", "$i_u$", "$i_v$", "$i_w$"]
    titles_cmd = ["$u_l$", "$u_h$", "$v_l$", "$v_h$", "$w_l$", "$w_h$"]
    for i in range(0, 2):
        plt.subplot(6, 2, 2 * i + 1)
        plt.plot(time, mu.deg_of_rad(X[:, i]), "r", linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(2, dm.sv_size):
        plt.subplot(6, 2, 2 * i + 1)
        plt.plot(time, X[:, i], "r", linewidth=3.0)
        plt.title(titles_state[i])
    for i in range(0, 6):
        plt.subplot(6, 2, 2 * i + 2)
        plt.plot(time, U[:, i], "r", linewidth=3.0)
        plt.title(titles_cmd[i])
Exemplo n.º 4
0
def plot_output(time, Y, ls):
    ang_unit = ang_unit_rpm

    # Phase current
    ax = plt.subplot(4, 1, 1)
    ax.yaxis.set_label_text('A', {'color'    : 'k', 'fontsize'   : 15 })
    plt.plot(time,Y[:,dm.ov_iu], ls, linewidth=1.5)
    plt.plot(time,Y[:,dm.ov_iv], ls, linewidth=1.5)
    plt.plot(time,Y[:,dm.ov_iw], ls, linewidth=1.5)
    plt.legend(['$i_u$', '$i_v$', '$i_w$'], loc='upper right')
    plt.title('Phase current')

    # Phase terminal voltage
    ax = plt.subplot(4, 1, 2)
    ax.yaxis.set_label_text('V', {'color'    : 'k', 'fontsize'   : 15 })
    plt.plot(time,Y[:,dm.ov_vu], ls, linewidth=1.5)
    plt.plot(time,Y[:,dm.ov_vv], ls, linewidth=1.5)
    plt.plot(time,Y[:,dm.ov_vw], ls, linewidth=1.5)
    plt.legend(['$v_u$', '$v_v$', '$v_w$'], loc='upper right')
    plt.title('Phase terminal voltage')

    # Rotor mechanical position
    ax = plt.subplot(4, 1, 3)
    ax.yaxis.set_label_text('Deg', {'color'    : 'k', 'fontsize'   : 15 })
    plt.plot(time,mu.deg_of_rad(Y[:,dm.ov_theta]), ls, linewidth=1.5)
#    plt.plot(time, Y[:,dm.ov_theta], ls, linewidth=1.5)
    plt.title('Rotor angular position')

    # Rotor mechanical angular speed
    ax = plt.subplot(4, 1, 4)

    if (ang_unit == ang_unit_rad_s):
        ax.yaxis.set_label_text('Rad/s', {'color'    : 'k', 'fontsize'   : 15 })
        plt.plot(time,Y[:,dm.ov_omega], ls, linewidth=1.5)
    elif (ang_unit == ang_unit_deg_s):
        ax.yaxis.set_label_text('Deg/s', {'color'    : 'k', 'fontsize'   : 15 })
        plt.plot(time,mu.degps_of_radps(Y[:,dm.ov_omega]), ls, linewidth=1.5)
    elif (ang_unit == ang_unit_rpm):
        ax.yaxis.set_label_text('RPM', {'color'    : 'k', 'fontsize'   : 15 })
        plt.plot(time,mu.rpm_of_radps(Y[:,dm.ov_omega]), ls, linewidth=1.5)

    plt.title('Rotor Rotational Velocity')
Exemplo n.º 5
0
def plot_output(time, Y, ls):
    ang_unit = ang_unit_rpm

    # Phase current
    ax = plt.subplot(4, 1, 1)
    ax.yaxis.set_label_text('A', {'color': 'k', 'fontsize': 15})
    plt.plot(time, Y[:, dm.ov_iu], ls, linewidth=1.5)
    plt.plot(time, Y[:, dm.ov_iv], ls, linewidth=1.5)
    plt.plot(time, Y[:, dm.ov_iw], ls, linewidth=1.5)
    plt.legend(['$i_u$', '$i_v$', '$i_w$'], loc='upper right')
    plt.title('Phase current')

    # Phase terminal voltage
    ax = plt.subplot(4, 1, 2)
    ax.yaxis.set_label_text('V', {'color': 'k', 'fontsize': 15})
    plt.plot(time, Y[:, dm.ov_vu], ls, linewidth=1.5)
    plt.plot(time, Y[:, dm.ov_vv], ls, linewidth=1.5)
    plt.plot(time, Y[:, dm.ov_vw], ls, linewidth=1.5)
    plt.legend(['$v_u$', '$v_v$', '$v_w$'], loc='upper right')
    plt.title('Phase terminal voltage')

    # Rotor mechanical position
    ax = plt.subplot(4, 1, 3)
    ax.yaxis.set_label_text('Deg', {'color': 'k', 'fontsize': 15})
    plt.plot(time, mu.deg_of_rad(Y[:, dm.ov_theta]), ls, linewidth=1.5)
    #    plt.plot(time, Y[:,dm.ov_theta], ls, linewidth=1.5)
    plt.title('Rotor angular position')

    # Rotor mechanical angular speed
    ax = plt.subplot(4, 1, 4)

    if (ang_unit == ang_unit_rad_s):
        ax.yaxis.set_label_text('Rad/s', {'color': 'k', 'fontsize': 15})
        plt.plot(time, Y[:, dm.ov_omega], ls, linewidth=1.5)
    elif (ang_unit == ang_unit_deg_s):
        ax.yaxis.set_label_text('Deg/s', {'color': 'k', 'fontsize': 15})
        plt.plot(time, mu.degps_of_radps(Y[:, dm.ov_omega]), ls, linewidth=1.5)
    elif (ang_unit == ang_unit_rpm):
        ax.yaxis.set_label_text('RPM', {'color': 'k', 'fontsize': 15})
        plt.plot(time, mu.rpm_of_radps(Y[:, dm.ov_omega]), ls, linewidth=1.5)

    plt.title('Rotor Rotational Velocity')
Exemplo n.º 6
0
def run_hpwm_l_on_bipol(Sp, Y, t):
    elec_angle = mu.norm_angle(Y[dm.ov_theta] * dm.NbPoles/2)

    U = np.zeros(dm.iv_size)

    step = "none"

    # switching pattern based on the "encoder"
    # H PWM L ON pattern
    if 0. <= elec_angle <= (math.pi * (1./6.)): # second half of step 1
        # U off
        # V low
        # W hpwm
        hu = 0
        lu = 0
        hv = 0
        lv = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "1b"
    elif (math.pi * (1.0/6.0)) < elec_angle <= (math.pi * (3.0/6.0)): # step 2
        # U hpwm
        # V low
        # W off
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hu = 1
        else:
            hu = 0
        lu = 0
        hv = 0
        lv = 1
        hw = 0
        lw = 0
        step = "2 "
    elif (math.pi * (3.0/6.0)) < elec_angle <= (math.pi * (5.0/6.0)): # step 3
        # U hpwm
        # V off
        # W low
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hu = 1
        else:
            hu = 0
        lu = 0
        hv = 0
        lv = 0
        hw = 0
        lw = 1
        step = "3 "
    elif (math.pi * (5.0/6.0)) < elec_angle <= (math.pi * (7.0/6.0)): # step 4
        # U off
        # V hpwm
        # W low
        hu = 0
        lu = 0
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hv = 1
        else:
            hv = 0
        lv = 0
        hw = 0
        lw = 1
        step = "4 "
    elif (math.pi * (7.0/6.0)) < elec_angle <= (math.pi * (9.0/6.0)): # step 5
        # U low
        # V hpwm
        # W off
        hu = 0
        lu = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hv = 1
        else:
            hv = 0
        lv = 0
        hw = 0
        lw = 0
        step = "5 "
    elif (math.pi * (9.0/6.0)) < elec_angle <= (math.pi * (11.0/6.0)): # step 6
        # U low
        # V off
        # W hpwm
        hu = 0
        lu = 1
        hv = 0
        lv = 0
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "6 "
    elif (math.pi * (11.0/6.0)) < elec_angle <= (math.pi * (12.0/6.0)): # first half of step 1
        # U off
        # V low
        # W hpwm
        hu = 0
        lu = 0
        hv = 0
        lv = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "1a"
    else:
        print 'ERROR: The electrical angle is out of range!!!'

    # Assigning the scheme phase values to the simulator phases
    # "Connecting the controller wires to the motor" ^^
    # This way we can for example decide which direction we want to turn the motor
    U[dm.iv_hu] = hu
    U[dm.iv_lu] = lu
    U[dm.iv_hv] = hw
    U[dm.iv_lv] = lw
    U[dm.iv_hw] = hv
    U[dm.iv_lw] = lv

    if debug:
        print 'time {} step {} eangle {} switches {}'.format(t, step, mu.deg_of_rad(elec_angle), U)

    return U
Exemplo n.º 7
0
def run_hpwm_l_on_bipol(Sp, Y, t):
    elec_angle = mu.norm_angle(Y[dm.ov_theta] * dm.NbPoles / 2)

    U = np.zeros(dm.iv_size)

    step = "none"

    # switching pattern based on the "encoder"
    # H PWM L ON pattern
    if 0. <= elec_angle <= (math.pi * (1. / 6.)):  # second half of step 1
        # U off
        # V low
        # W hpwm
        hu = 0
        lu = 0
        hv = 0
        lv = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "1b"
    elif (math.pi * (1.0 / 6.0)) < elec_angle <= (math.pi *
                                                  (3.0 / 6.0)):  # step 2
        # U hpwm
        # V low
        # W off
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hu = 1
        else:
            hu = 0
        lu = 0
        hv = 0
        lv = 1
        hw = 0
        lw = 0
        step = "2 "
    elif (math.pi * (3.0 / 6.0)) < elec_angle <= (math.pi *
                                                  (5.0 / 6.0)):  # step 3
        # U hpwm
        # V off
        # W low
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hu = 1
        else:
            hu = 0
        lu = 0
        hv = 0
        lv = 0
        hw = 0
        lw = 1
        step = "3 "
    elif (math.pi * (5.0 / 6.0)) < elec_angle <= (math.pi *
                                                  (7.0 / 6.0)):  # step 4
        # U off
        # V hpwm
        # W low
        hu = 0
        lu = 0
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hv = 1
        else:
            hv = 0
        lv = 0
        hw = 0
        lw = 1
        step = "4 "
    elif (math.pi * (7.0 / 6.0)) < elec_angle <= (math.pi *
                                                  (9.0 / 6.0)):  # step 5
        # U low
        # V hpwm
        # W off
        hu = 0
        lu = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hv = 1
        else:
            hv = 0
        lv = 0
        hw = 0
        lw = 0
        step = "5 "
    elif (math.pi * (9.0 / 6.0)) < elec_angle <= (math.pi *
                                                  (11.0 / 6.0)):  # step 6
        # U low
        # V off
        # W hpwm
        hu = 0
        lu = 1
        hv = 0
        lv = 0
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "6 "
    elif (math.pi *
          (11.0 / 6.0)) < elec_angle <= (math.pi *
                                         (12.0 / 6.0)):  # first half of step 1
        # U off
        # V low
        # W hpwm
        hu = 0
        lu = 0
        hv = 0
        lv = 1
        if math.fmod(t, PWM_cycle_time) <= PWM_duty_time:
            hw = 1
        else:
            hw = 0
        lw = 0
        step = "1a"
    else:
        print("ERROR: The electrical angle is out of range!!!")

    # Assigning the scheme phase values to the simulator phases
    # "Connecting the controller wires to the motor" ^^
    # This way we can for example decide which direction we want to turn the motor
    U[dm.iv_hu] = hu
    U[dm.iv_lu] = lu
    U[dm.iv_hv] = hw
    U[dm.iv_lv] = lw
    U[dm.iv_hw] = hv
    U[dm.iv_lw] = lv

    if debug:
        print('time {} step {} eangle {} switches {}'.format(
            t, step, mu.deg_of_rad(elec_angle), U))

    return U