-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmy_plot.py
99 lines (80 loc) · 3.63 KB
/
my_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# Open-BLDC pysim - Open BrushLess DC Motor Controller python simulator
# Copyright (C) 2011 by Antoine Drouin <[email protected]>
# Copyright (C) 2011 by Piotr Esden-Tempski <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import matplotlib.pyplot as plt
import dyn_model as dm
import misc_utils as mu
ang_unit_rad_s = 0
ang_unit_deg_s = 1
ang_unit_rpm = 2
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')
def plot_debug(time, Xdebug):
plt.subplot(4, 1, 1)
plt.plot(time,Xdebug[:,dm.dv_eu], linewidth=1.5)
plt.plot(time,Xdebug[:,dm.dv_ev], linewidth=1.5)
plt.plot(time,Xdebug[:,dm.dv_ew], linewidth=1.5)
plt.legend(['$U_{BEMF}$', '$V_{BEMF}$', '$W_{BEMF}$'], loc='upper right')
plt.subplot(4, 1, 2)
plt.plot(time,Xdebug[:,dm.dv_ph_U], linewidth=1.5)
plt.plot(time,Xdebug[:,dm.dv_ph_V], linewidth=1.5)
plt.plot(time,Xdebug[:,dm.dv_ph_W], linewidth=1.5)
plt.legend(['$U$', '$V$', '$W$'], loc='upper right')
plt.subplot(4, 1, 3)
plt.plot(time,Xdebug[:,dm.dv_ph_star], linewidth=1.5)
plt.legend(['$star$'], loc='upper right')
def plot_diodes(time, D):
titles_diodes = ['$dhu$', '$dlu$', '$dhv$', '$dlv$', '$dhw$', '$dlw$']
for i in range(0, dm.adc_size):
plt.subplot(6, 2, 2*i+1)
plt.plot(time,D[:,i], 'r', linewidth=1.5)
plt.title(titles_diodes[i])