Skip to content
Browse files

Removed diode handling.

It is not correct to ignore them completely, but because we are not
involving the inductance of the coils while calculating the coil voltage
we are able to ignore this fact too without disturbing the overall
behaviour of the simulator.
  • Loading branch information...
1 parent d56c481 commit 93d7cf53dea73ec331afef8c580b0c86f730a6ca @esden committed Mar 25, 2012
Showing with 42 additions and 140 deletions.
  1. +1 −1 control.py
  2. +39 −116 dyn_model.py
  3. +2 −23 sim_1.py
View
2 control.py
@@ -27,7 +27,7 @@
PWM_freq = 200000
PWM_cycle_time = (1./200000)
-PWM_duty = .75
+PWM_duty = 1.
PWM_duty_time = PWM_cycle_time * PWM_duty
debug = False
View
155 dyn_model.py
@@ -86,13 +86,7 @@
iv_hv = 3
iv_lw = 4
iv_hw = 5
-iv_dhu = 6
-iv_dlu = 7
-iv_dhv = 8
-iv_dlv = 9
-iv_dhw = 10
-iv_dlw = 11
-iv_size = 12
+iv_size = 6
# Components of the perturbation vector
@@ -127,20 +121,6 @@
dv_ph_star = 6
dv_size = 7
-# All diodes conduction vector
-adc_uh = 0
-adc_ul = 1
-adc_vh = 2
-adc_vl = 3
-adc_wh = 4
-adc_wl = 5
-adc_size = 6
-
-# Diode conduction vector
-dc_h = 0
-dc_l = 1
-dc_size = 2
-
#
# Calculate backemf at a given omega offset from the current rotor position
#
@@ -168,44 +148,6 @@ def backemf(X,thetae_offset):
return bemf
-def diode(h, l, i, e, star):
- dh = 0
- dl = 0
-
- if ((h == 0) and (l == 0)):
- if (i < -0.01) or ((e + star) > ((VDC/2) + dvf)):
- dh = 1
- dl = 0
- elif (i > 0.01) or ((e + star) < ((-(VDC/2) - dvf))):
- dh = 0
- dl = 1
- else:
- dh = 0
- dl = 0
- else:
- dh = 0
- dl = 0
-
- D = [dh, dl]
-
- return D
-
-def diodes(X, Xdebug, U):
-
- DU = diode(U[iv_hu], U[iv_lu], X[sv_iu], Xdebug[dv_eu], Xdebug[dv_ph_star])
- DV = diode(U[iv_hv], U[iv_lv], X[sv_iv], Xdebug[dv_ev], Xdebug[dv_ph_star])
- DW = diode(U[iv_hw], U[iv_lw], X[sv_iw], Xdebug[dv_ew], Xdebug[dv_ph_star])
-
- Ds = [DU[dc_h],
- DU[dc_l],
- DV[dc_h],
- DV[dc_l],
- DW[dc_h],
- DW[dc_l]
- ]
-
- return Ds
-
#
# Calculate phase voltages
# Returns a vector of phase voltages in reference to the star point
@@ -217,19 +159,13 @@ def voltages(X, U):
# Check which phases are excited
pux = (U[iv_hu] == 1) or \
- (U[iv_lu] == 1) or \
- (U[iv_dlu] == 1) or \
- (U[iv_dhu] == 1)
+ (U[iv_lu] == 1)
pvx = (U[iv_hv] == 1) or \
- (U[iv_lv] == 1) or \
- (U[iv_dlv] == 1) or \
- (U[iv_dhv] == 1)
+ (U[iv_lv] == 1)
pwx = (U[iv_hw] == 1) or \
- (U[iv_lw] == 1) or \
- (U[iv_dlw] == 1) or \
- (U[iv_dhw] == 1)
+ (U[iv_lw] == 1)
vu = 0.
vv = 0.
@@ -239,116 +175,107 @@ def voltages(X, U):
if pux and pvx and pwx:
if (U[iv_hu] == 1):
vu = VDC/2.
- elif (U[iv_dhu] == 1):
- vu = VDC/2. + dvf
- elif (U[iv_dlu] == 1):
- vu = -(VDC/2. + dvf)
else:
vu = -VDC/2.
if (U[iv_hv] == 1):
vv = VDC/2.
- elif (U[iv_dhv] == 1):
- vv = VDC/2. + dvf
- elif (U[iv_dlv] == 1):
- vv = -(VDC/2. + dvf)
else:
vv = -VDC/2.
if (U[iv_hw] == 1):
vw = VDC/2.
- elif (U[iv_dhw] == 1):
- vw = VDC/2. + dvf
- elif (U[iv_dlw] == 1):
- vw = -(VDC/2. + dvf)
else:
vw = -VDC/2.
vm = (vu + vv + vw - eu - ev - ew) / 3.
elif pux and pvx:
+
+ # calculate excited phase voltages
if (U[iv_hu] == 1):
vu = VDC/2.
- elif (U[iv_dhu] == 1):
- vu = VDC/2. + dvf
- elif (U[iv_dlu] == 1):
- vu = -(VDC/2. + dvf)
else:
vu = -VDC/2.
if (U[iv_hv] == 1):
vv = VDC/2.
- elif (U[iv_dhv] == 1):
- vv = VDC/2. + dvf
- elif (U[iv_dlv] == 1):
- vv = -(VDC/2. + dvf)
else:
vv = -VDC/2.
+ # calculate star voltage
vm = (vu + vv - eu - ev) / 2.
+
+ # calculate remaining phase voltage
vw = ew + vm
+
+ # clip the voltage to freewheeling diodes
+ #if (vw > ((VDC/2) + dvf)):
+ # vw = (VDC/2) + dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+ #elif (vw < (-(VDC/2) - dvf)):
+ # vw = -(VDC/2) - dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+
elif pux and pwx:
if (U[iv_hu] == 1):
vu = VDC/2.
- elif (U[iv_dhu] == 1):
- vu = VDC/2. + dvf
- elif (U[iv_dlu] == 1):
- vu = -(VDC/2. + dvf)
else:
vu = -VDC/2.
if (U[iv_hw] == 1):
vw = VDC/2.
- elif (U[iv_dhw] == 1):
- vw = VDC/2. + dvf
- elif (U[iv_dlw] == 1):
- vw = -(VDC/2. + dvf)
else:
vw = -VDC/2.
vm = (vu + vw - eu - ew) / 2.
vv = ev + vm
+
+ # clip the voltage to freewheeling diodes
+ #if (vv > ((VDC/2) + dvf)):
+ # vv = (VDC/2) + dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+ #elif (vv < (-(VDC/2) - dvf)):
+ # vv = -(VDC/2) - dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+
elif pvx and pwx:
if (U[iv_hv] == 1):
vv = VDC/2.
- elif (U[iv_dhv] == 1):
- vv = VDC/2. + dvf
- elif (U[iv_dlv] == 1):
- vv = -(VDC/2. + dvf)
else:
vv = -VDC/2.
if (U[iv_hw] == 1):
vw = VDC/2.
- elif (U[iv_dhw] == 1):
- vw = VDC/2. + dvf
- elif (U[iv_dlw] == 1):
- vw = -(VDC/2. + dvf)
else:
vw = -VDC/2.
vm = (vv + vw - ev - ew) / 2.
vu = eu + vm
+
+ # clip the voltage to freewheeling diodes
+ #if (vu > ((VDC/2) + dvf)):
+ # vu = (VDC/2) + dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+ #elif (vu < (-(VDC/2) - dvf)):
+ # vu = -(VDC/2) - dvf;
+ # vm = (vu + vv + vw - eu - ev - ew) / 3.
+
elif pux:
if (U[iv_hu] == 1):
vu = VDC/2
- elif (U[iv_dhu] == 1):
- vu = VDC/2 + dvf
- elif (U[iv_dlu] == 1):
- vu = -(VDC/2 + dvf)
else:
vu = -VDC/2.
vm = (vu - eu)
vv = ev + vm
vw = ew + vm
+
+ # if we want to handle diodes properly how to do that here?
+
elif pvx:
if (U[iv_hv] == 1):
vv = VDC/2
- elif (U[iv_dhv] == 1):
- vv = VDC/2 + dvf
- elif (U[iv_dlv] == 1):
- vv = -(VDC/2 + dvf)
else:
vv = -VDC/2.
@@ -358,10 +285,6 @@ def voltages(X, U):
elif pwx:
if (U[iv_hw] == 1):
vw = VDC/2
- elif (U[iv_dhw] == 1):
- vw = VDC/2 + dvf
- elif (U[iv_dlu] == 1):
- vw = -(VDC/2 + dvf)
else:
vw = -VDC/2.
View
25 sim_1.py
@@ -58,20 +58,6 @@ def print_simulation_progress(count, steps):
if (sim_perc_last != sim_perc):
print "{}%".format(sim_perc)
-def copy_diodes(U, D):
- Uout = np.zeros(dm.iv_size)
-
- Uout[:] = U[:]
-
- Uout[dm.iv_dhu] = D[dm.adc_uh]
- Uout[dm.iv_dlu] = D[dm.adc_ul]
- Uout[dm.iv_dhv] = D[dm.adc_vh]
- Uout[dm.iv_dlv] = D[dm.adc_vl]
- Uout[dm.iv_dhw] = D[dm.adc_wh]
- Uout[dm.iv_dlw] = D[dm.adc_wl]
-
- return Uout
-
def drop_it(a, factor):
new = []
for n, x in enumerate(a):
@@ -88,16 +74,15 @@ def main():
# mp.plot_output(t_psim, Y_psim, '.')
freq_sim = 1e5 # simulation frequency
- compress_factor = 1
- time = pl.arange(0.0, 0.016, 1./freq_sim) # create time slice vector
+ compress_factor = 3
+ time = pl.arange(0.0, 0.1, 1./freq_sim) # create time slice vector
X = np.zeros((time.size, dm.sv_size)) # allocate state vector
Xdebug = np.zeros((time.size, dm.dv_size)) # allocate debug data vector
Y = np.zeros((time.size, dm.ov_size)) # allocate output vector
U = np.zeros((time.size, dm.iv_size)) # allocate input vector
X0 = [0, mu.rad_of_deg(0.1), 0, 0, 0] #
X[0,:] = X0
W = [0]
- D = np.zeros((time.size, dm.adc_size)) # allocate diode conduction vector
for i in range(1,time.size):
if i==1:
@@ -107,8 +92,6 @@ def main():
Y[i-1,:] = dm.output(X[i-1,:], Uim2) # get the output for the last step
U[i-1,:] = ctl.run(0, Y[i-1,:], time[i-1]) # run the controller for the last step
- D[i-1,:] = dm.diodes(X[i-1,:], Xdebug[i-1], U[i-1,:]) # calculate the diode states based on the last step
- U[i-1,:] = copy_diodes(U[i-1,:], D[i-1,:]) # copy diode conduction states to the input vector
tmp = integrate.odeint(dm.dyn, X[i-1,:], [time[i-1], time[i]], args=(U[i-1,:], W)) # integrate
X[i,:] = tmp[1,:] # copy integration output to the current step
X[i, dm.sv_theta] = mu.norm_angle( X[i, dm.sv_theta]) # normalize the angle in the state
@@ -124,7 +107,6 @@ def main():
X = compress(X, compress_factor)
U = compress(U, compress_factor)
Xdebug = compress(Xdebug, compress_factor)
- D = compress(D, compress_factor)
mp.plot_output(time, Y, '-')
# pl.show()
@@ -134,9 +116,6 @@ def main():
plt.figure(figsize=(10.24, 5.12))
mp.plot_debug(time, Xdebug)
- plt.figure(figsize=(10.24, 5.12))
- mp.plot_diodes(time, D)
-
pl.show()
if __name__ == "__main__":

0 comments on commit 93d7cf5

Please sign in to comment.
Something went wrong with that request. Please try again.