Commit fff0a4c4 authored by Tristan Renon's avatar Tristan Renon
Browse files

Update 10 + 3D 24PM

parent 827e0659
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=50):
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=100):
# Generate things if user did not tell about them
if nSamples is None:
nSamples = 50
......@@ -22,4 +24,164 @@ def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None
for i in range(n):
ret.append(phaseAmplitude[i]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
\ No newline at end of file
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
def generateSquare(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=50):
# Generate things if user did not tell about them
if nSamples is None:
nSamples = 50
if phaseAmplitude is None or len(phaseAmplitude) != n:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None or len(phaseShiftMec) != n:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None or len(phaseShiftReg) != n:
phaseShiftReg = phaseShiftMec
# Generate x (0 to 2pi)
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
# Generate power supply for coils
for i in range(n):
ret.append(phaseAmplitude[i]*signal.square(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
def generateSinPWM(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=100):
# Generate things if user did not tell about them
if nSamples is None:
nSamples = 50
if phaseAmplitude is None or len(phaseAmplitude) != n:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None or len(phaseShiftMec) != n:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None or len(phaseShiftReg) != n:
phaseShiftReg = phaseShiftMec
# Generate x (0 to 2pi)
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
# Generate power supply for coils
for i in range(n):
sig = np.sin(xSin+phaseShiftReg[i]/180*np.pi)
ret.append(phaseAmplitude[i]*signal.square((xSin+phaseShiftReg[i]/180*np.pi)*29, duty=(sig+1)/2))
duty = (sig+1)/2
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin, duty
def generateTriangle(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=100):
# Generate things if user did not tell about them
if nSamples is None:
nSamples = 50
if phaseAmplitude is None or len(phaseAmplitude) != n:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None or len(phaseShiftMec) != n:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None or len(phaseShiftReg) != n:
phaseShiftReg = phaseShiftMec
# Generate x (0 to 2pi)
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
# Generate power supply for coils
for i in range(n):
ret.append(phaseAmplitude[i]*signal.sawtooth(xSin+phaseShiftReg[i]/180*np.pi+np.pi/2, 0.5))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
def generateTrapeze(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None, nSamples=100):
# Generate things if user did not tell about them
if nSamples is None:
nSamples = 50
if phaseAmplitude is None or len(phaseAmplitude) != n:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None or len(phaseShiftMec) != n:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None or len(phaseShiftReg) != n:
phaseShiftReg = phaseShiftMec
# Generate x (0 to 2pi)
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
# Generate power supply for coils
for i in range(n):
sig = np.sin(xSin+phaseShiftReg[i]/180*np.pi)
sig = signal.sawtooth()
ret.append(phaseAmplitude[i]*signal.square((xSin+phaseShiftReg[i]/180*np.pi)*30, duty=(sig+1)/2))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
# def trapeze(dataX, thetaZ, thetaOmega, nSamples=50):
# if nSamples is None:
# nSamples = 50
# if dataX is None:
# dataX = np.linspace(0, 2 * np.pi, nSamples)
# if thetaZ is None:
# thetaZ = dataX[-1]/64
# if thetaOmega is None:
# thetaOmega=thetaZ
#
# trapeze = dataX
# for i in range(len(dataX)):
# if dataX[i] <= dataX[-1]/2:
# if dataX[i] < thetaZ:
# trapeze[i] = 0
# elif dataX[i] < thetaZ+thetaOmega:
# trapeze[i] = FAIRE UNE PENTE de 0 à 1
# elif dataX[i] < dataX[-1]/2-thetaZ-thetaOmega:
# trapeze[i] = 1
# elif dataX[i] < dataX[-1]/2-thetaZ:
# trapeze[i] = FAIRE UNE PENTE de 1 à 0
# else:
# trapeze[i] = 0
# else:
# if dataX[i] < dataX[-1]/2+thetaZ:
# trapeze[i] = 0
# elif dataX[i] < dataX[-1]/2+thetaZ+thetaOmega:
# trapeze[i] = FAIRE UNE PENTE de 0 à -1
# elif dataX[i] < dataX[-1]-thetaZ-thetaOmega:
# trapeze[i] = -1
# elif dataX[i] < dataX[-1]-thetaZ:
# trapeze[i] = Faire Une pente de -1 à 0
# else:
# trapeze[i] = 0
# return trapeze
'''
n = 3
nSamples = 1000
res, _, _, _, _, xSin = generateSin(n, nSamples=nSamples)
# res, _, _, _, _, xSin = generateSquare(n)
ros, _, _, _, _, xSin, duty = generateSinPWM(n, nSamples=nSamples)
# res, _, _, _, _, xSin = generateTriangle(n)
# for i in range(n):
# plt.plot(xSin, res[i])
# plt.plot(xSin, ros[i])
plt.plot(xSin, res[0])
plt.plot(xSin, ros[1])
plt.plot(xSin, duty)
'''
plt.show()
......@@ -5,20 +5,20 @@ import matplotlib.animation as animation
import generateSinLib as gsl
nSamples = 50
nSamples = 100
inputNPhases = 5
inputPhaseAmplitude = (0, 1, 1, 1, 1)
# inputPhaseAmplitude = (0, 1, 1, 1, 1)
# inputPhaseAmplitude = (0, 1.382, 1.382, 1.382, 1.382)
inputPhaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
inputPhaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
# inputPhaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# inputPhaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(inputNPhases, inputPhaseShiftReg, inputPhaseAmplitude, inputPhaseShiftMec, nSamples=nSamples)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=inputNPhases, nSamples=nSamples)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(inputNPhases, inputPhaseShiftReg, inputPhaseAmplitude, inputPhaseShiftMec, nSamples=nSamples)
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _, _ = gsl.generateSinPWM(n=inputNPhases, nSamples=nSamples)
fig, ax = plt.subplots(figsize=(8, 8))
limit = (nPhases+1)/2
limit = (nPhases+1)/2*2
def animate(i):
ax.cla()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment