Commit 8f63413a authored by Tristan Renon's avatar Tristan Renon
Browse files

working with stator

parent 79508994
from matplotlib import pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
fig, ax = plt.subplots(figsize=(8, 8))
lines = list()
lines.append(ax.plot([0, 1], [0, 2]))
lines.append(ax.plot([0, 2], [0, 1]))
ax.lines.pop(0)
xy = [0.2,0.2]
xytext =[0.5,0.5]
x_tail = 0.1
y_tail = 0.1
x_head = 0.9
y_head = 0.9
dx = x_head - x_tail
dy = y_head - y_tail
arrows = list()
arrow = mpatches.FancyArrowPatch((0,0), (1,1), arrowstyle='-|>', mutation_scale=20, color='red')
arrows.append(arrow)
arrow = mpatches.FancyArrowPatch((0,0), (1,2), arrowstyle='-|>', mutation_scale=20, color='red')
arrows.append(arrow)
ax.add_patch(arrows[0])
ax.add_patch(arrows[1])
arrows[0].remove()
arrows[0]=mpatches.FancyArrowPatch((0,0), (2,2), arrowstyle='-|>', mutation_scale=20, color='red')
ax.add_patch(arrows[0])
plt.show()
\ No newline at end of file
......@@ -7,13 +7,11 @@ import generateSinLib as gsl
nSamples = 50
inputNPhases = 5
# 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)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(inputNPhases, nSamples=nSamples)
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=inputNPhases, phaseShiftReg=inputPhaseShiftReg, phaseAmplitude=inputPhaseAmplitude, phaseShiftMec=inputPhaseShiftMec, nSamples=nSamples)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=inputNPhases, phaseAmplitude=inputPhaseAmplitude, phaseShiftMec=inputPhaseShiftMec, nSamples=nSamples)
......@@ -25,11 +23,14 @@ limit2 = max(phaseAmplitude) * 1.1
ax3.set(xlim=(0, 2 * np.pi), ylim=(-limit2, limit2))
actualAngles = list()
tempAngle = 5/180*np.pi
for j in range(nPhases):
color = next(ax2._get_lines.prop_cycler)['color']
ax3.plot(xSin, generatedSin[j])
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
vertical = ax3.axvline(x=xSin[0], color='black')
......@@ -97,6 +98,6 @@ def animate(i):
ax1.plot(plotX, plotY, color='skyblue')
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
ani = animation.FuncAnimation(fig, animate, interval=5, frames=nSamples, blit=False, save_count=nSamples)
plt.show()
\ No newline at end of file
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.patches as mpatches
import numpy as np
import generateSinLib as gsl
nSamples = 50
inputNPhases = 5
# 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)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(inputNPhases, nSamples=nSamples)
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=inputNPhases, phaseShiftReg=inputPhaseShiftReg, phaseAmplitude=inputPhaseAmplitude, phaseShiftMec=inputPhaseShiftMec, nSamples=nSamples)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=inputNPhases, phaseAmplitude=inputPhaseAmplitude, phaseShiftMec=inputPhaseShiftMec, nSamples=nSamples)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(16, 5))
limit1 = inputNPhases / 2 * 1.1
limit2 = max(phaseAmplitude) * 1.1
ax3.set(xlim=(0, 2 * np.pi), ylim=(-limit2, limit2))
ax2.set(xlim=(-limit2, limit2), ylim=(-limit2, limit2))
outterCircle = plt.Circle((0, 0), limit2, color='black', fill=False, linewidth=2)
innerCircle = plt.Circle((0, 0), limit2*0.9, color='black', fill=False, linewidth=2)
circleWiresUp = list()
circleWiresDown = list()
actualAngles = list()
angleCosPositive = list()
angleSinPositive = list()
angleCosNegative = list()
angleSinNegative = list()
tempAngle = 5/180*np.pi
arrows = [None] * nPhases
crosses = [None] * nPhases
dots = [None] * nPhases
sign = [None] * nPhases
for j in range(nPhases):
color = next(ax2._get_lines.prop_cycler)['color']
ax3.plot(xSin, generatedSin[j])
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
angleCosPositive.append(np.cos(actualAngles[j] + tempAngle) * limit2 * 0.95)
angleSinPositive.append(np.sin(actualAngles[j] + tempAngle) * limit2 * 0.95)
angleCosNegative.append(np.cos(actualAngles[j] - tempAngle) * limit2 * 0.95)
angleSinNegative.append(np.sin(actualAngles[j] - tempAngle) * limit2 * 0.95)
circleWiresUp.append(plt.Circle((angleCosPositive[j], angleSinPositive[j]), limit2*0.04, color=color, fill=False, linewidth=1))
circleWiresDown.append(plt.Circle((angleCosNegative[j], angleSinNegative[j]), limit2*0.04, color=color, fill=False, linewidth=1))
ax2.add_patch(circleWiresUp[j])
ax2.add_patch(circleWiresDown[j])
actualExcitation = generatedSin[j][0]
if actualExcitation > 0:
dots[j] = ax2.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=color, marker='.')
crosses[j] = ax2.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=color, marker='x')
else:
dots[j] = ax2.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=color, marker='.')
crosses[j] = ax2.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=color, marker='x')
vertical = ax3.axvline(x=xSin[0], color='black')
ax2.add_patch(outterCircle)
ax2.add_patch(innerCircle)
def animate(i):
# Subplot 1
ax1.cla()
ax1.set(xlim=(-limit1, limit1),
ylim=(-limit1, limit1))
ax2.set_prop_cycle(None)
sliding1 = [[0, 0], [0, 0]]
plotX = np.zeros(i)
plotY = np.zeros(i)
for j in range(nPhases):
# ------------------------------------------------------------------------------------------------------
# Calculations (Do it only once and reuse after)
actualExcitation = generatedSin[j][i]
actualAngle = actualAngles[j]
actualSin = np.sin(actualAngle)
actualCos = np.cos(actualAngle)
actualSinGen = actualSin * actualExcitation
actualCosGen = actualCos * actualExcitation
# ------------------------------------------------------------------------------------------------------
# Subplot 1 --------------------------------------------------------------------------------------------
colors = next(ax1._get_lines.prop_cycler)['color']
# New start = sum of last starts
sliding1[0][0] += sliding1[1][0]
sliding1[0][1] += sliding1[1][1]
# New end = sin-cos (x-y) of mechanical multiplied by power supply
sliding1[1] = [actualCosGen, actualSinGen]
ax1.arrow(sliding1[0][0], sliding1[0][1],
sliding1[1][0], sliding1[1][1],
head_width=.1, head_length=.1, fc=colors, ec=colors)
# Needed to draw the ellipse
xTemp = actualCos*generatedSin[j][:i]
yTemp = actualSin*generatedSin[j][:i]
# Have to sum all sin in x and all cos in y (still for ellipse)
plotX += xTemp
plotY += yTemp
# ------------------------------------------------------------------------------------------------------
# Subplot 2 --------------------------------------------------------------------------------------------
sliding2 = [[0, 0], [0, 0]]
if len(arrows) > 0 and arrows[j] != None:
arrows[j].remove()
colors = next(ax2._get_lines.prop_cycler)['color']
sliding2[0] = sliding2[1]
sliding2[1] = [actualCosGen, actualSinGen]
arrow = mpatches.FancyArrowPatch((sliding2[0][0], sliding2[0][1]), (sliding2[1][0], sliding2[1][1]),
arrowstyle='-|>', mutation_scale=20, color=colors)
arrows[j] = arrow
ax2.add_patch(arrows[j])
if actualExcitation > 0:
last = sign[j]
sign[j] = True
if sign[j] != last:
dots[j].remove()
crosses[j].remove()
dots[j] = ax2.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=colors, marker='.')
crosses[j] = ax2.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=colors, marker='x')
else:
last = sign[j]
sign[j] = False
if sign[j] != last:
dots[j].remove()
crosses[j].remove()
dots[j] = ax2.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=colors, marker='.')
crosses[j] = ax2.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=colors, marker='x')
# -----------------------------------------------------------------------------------------------------
# Subplot 3 -------------------------------------------------------------------------------------------
vertical.set_xdata(x=xSin[i])
ax1.plot(plotX, plotY, color='skyblue')
ani = animation.FuncAnimation(fig, animate, interval=5, frames=nSamples, blit=False, save_count=nSamples)
plt.show()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.pyplot import cm
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(0, 2*np.pi), ylim=(-2, 2))
for i in range(3):
print(next(ax._get_lines.prop_cycler)['color'])
\ No newline at end of file
......@@ -5,7 +5,7 @@ import matplotlib.animation as animation
import generateSinLib as gsl
nSamples = 50
nPhases = 5
nPhases = 9
# phaseAmplitude = (0, 1.382, 1.382, 1.382, 1.382)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
......@@ -17,34 +17,73 @@ nPhases = 5
# generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec, nSamples=nSamples)
generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=nPhases, nSamples=nSamples)
generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=nPhases, nSamples=nSamples)
fig, ax = plt.subplots(figsize=(8, 8))
limit = max(phaseAmplitude)*1.1
outterCircle = plt.Circle((0, 0), limit, color='black', fill=False, linewidth=2)
innerCircle = plt.Circle((0, 0), limit*0.9, color='black', fill=False, linewidth=2)
circleWiresUp = list()
circleWiresDown = list()
actualAngles = list()
angleCosPositive = list()
angleSinPositive = list()
angleCosNegative = list()
angleSinNegative = list()
tempAngle = 5/180*np.pi
for j in range(nPhases):
color = next(ax._get_lines.prop_cycler)['color']
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
angleCosPositive.append(np.cos(actualAngles[j] + tempAngle) * limit * 0.95)
angleSinPositive.append(np.sin(actualAngles[j] + tempAngle) * limit * 0.95)
angleCosNegative.append(np.cos(actualAngles[j] - tempAngle) * limit * 0.95)
angleSinNegative.append(np.sin(actualAngles[j] - tempAngle) * limit * 0.95)
circleWiresUp.append(plt.Circle((angleCosPositive[j], angleSinPositive[j]), limit*0.04, color=color, fill=False, linewidth=2))
circleWiresDown.append(plt.Circle((angleCosNegative[j], angleSinNegative[j]), limit*0.04, color=color, fill=False, linewidth=2))
def animate(i):
ax.cla()
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
sliding = [[0, 0], [0, 0]]
# ax.add_patch(outterCircle)
# ax.add_patch(innerCircle)
for j in range(nPhases):
# ax.add_patch(circleWiresUp[j])
# ax.add_patch(circleWiresDown[j])
actualExcitation = generatedSin[j][i]
actualAngle = phaseShiftMec[j] / 180 * np.pi
actualAngle = actualAngles[j]
actualSin = np.sin(actualAngle)
actualCos = np.cos(actualAngle)
actualSinGen = actualSin * actualExcitation
actualCosGen = actualCos * actualExcitation
colors = next(ax._get_lines.prop_cycler)['color']
sliding[0] += sliding[1]
sliding[1] = [actualCosGen, actualSinGen]
#@TODO: Peut être un set est-il possible plutôt que de tout effacer et tout retracer
# Réalisé dans fixedLines et fixedArrwoPatches
ax.arrow(sliding[0][0], sliding[0][1],
sliding[1][0], sliding[1][1],
head_width=.1, head_length=.1, fc=colors, ec=colors)
# Check if arrows are positive or negative to plot the dot or the cross on the wires
# if actualExcitation > 0:
# ax.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=colors, marker='.')
# ax.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=colors, marker='x')
# else:
# ax.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=colors, marker='x')
# ax.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=colors, marker='.')
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
ani = animation.FuncAnimation(fig, animate, interval=5, frames=nSamples, blit=False, save_count=nSamples)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.patches as mpatches
import generateSinLib as gsl
nSamples = 50
nPhases = 13
# phaseAmplitude = (0, 1.382, 1.382, 1.382, 1.382)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# phaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
# phaseAmplitude = (1, 1, 1, 1, 1)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# phaseShiftReg = phaseShiftMec
# generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec, nSamples=nSamples)
generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=nPhases, nSamples=nSamples)
fig, ax = plt.subplots(figsize=(8, 8))
limit = max(phaseAmplitude)*1.1
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
outterCircle = plt.Circle((0, 0), limit, color='black', fill=False, linewidth=2)
innerCircle = plt.Circle((0, 0), limit*0.9, color='black', fill=False, linewidth=2)
circleWiresUp = list()
circleWiresDown = list()
actualAngles = list()
angleCosPositive = list()
angleSinPositive = list()
angleCosNegative = list()
angleSinNegative = list()
tempAngle = 5/180*np.pi
arrows = [None] * nPhases
crosses = [None] * nPhases
dots = [None] * nPhases
sign = [None] * nPhases
for j in range(nPhases):
color = next(ax._get_lines.prop_cycler)['color']
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
angleCosPositive.append(np.cos(actualAngles[j] + tempAngle) * limit * 0.95)
angleSinPositive.append(np.sin(actualAngles[j] + tempAngle) * limit * 0.95)
angleCosNegative.append(np.cos(actualAngles[j] - tempAngle) * limit * 0.95)
angleSinNegative.append(np.sin(actualAngles[j] - tempAngle) * limit * 0.95)
circleWiresUp.append(plt.Circle((angleCosPositive[j], angleSinPositive[j]), limit*0.04, color=color, fill=False, linewidth=2))
circleWiresDown.append(plt.Circle((angleCosNegative[j], angleSinNegative[j]), limit*0.04, color=color, fill=False, linewidth=2))
ax.add_patch(circleWiresUp[j])
ax.add_patch(circleWiresDown[j])
actualExcitation = generatedSin[j][0]
if actualExcitation > 0:
dots[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=color, marker='.')
crosses[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=color, marker='x')
else:
dots[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=20, c=color, marker='.')
crosses[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=20, c=color, marker='x')
ax.add_patch(outterCircle)
ax.add_patch(innerCircle)
def animate(i):
sliding = [[0, 0], [0, 0]]
if len(arrows) > 0 and arrows[0] != None:
for j in range(nPhases):
arrows[j].remove()
ax.set_prop_cycle(None)
for j in range(nPhases):
actualExcitation = generatedSin[j][i]
actualAngle = actualAngles[j]
actualSin = np.sin(actualAngle)
actualCos = np.cos(actualAngle)
actualSinGen = actualSin * actualExcitation
actualCosGen = actualCos * actualExcitation
colors = next(ax._get_lines.prop_cycler)['color']
sliding[1] = [actualCosGen, actualSinGen]
# arrow = mpatches.Arrow(sliding[0][0], sliding[0][1], sliding[1][0], sliding[1][1], color=colors)
arrow = mpatches.FancyArrowPatch((sliding[0][0], sliding[0][1]), (sliding[1][0], sliding[1][1]), arrowstyle='-|>', mutation_scale=40, color=colors)
arrows[j] = arrow
ax.add_patch(arrows[j])
if actualExcitation > 0:
last = sign[j]
sign[j] = True
if sign[j] != last:
dots[j].remove()
crosses[j].remove()
dots[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=40, c=colors, marker='.')
crosses[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=100, c=colors, marker='x')
else:
last = sign[j]
sign[j] = False
if sign[j] != last:
dots[j].remove()
crosses[j].remove()
dots[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=40, c=colors, marker='.')
crosses[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=100, c=colors, marker='x')
ani = animation.FuncAnimation(fig, animate, interval=5, frames=nSamples, blit=False, save_count=nSamples)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import generateSinLib as gsl
nSamples = 50
nPhases = 5
s = 150
# phaseAmplitude = (0, 1.382, 1.382, 1.382, 1.382)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# phaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
# phaseAmplitude = (1, 1, 1, 1, 1)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# phaseShiftReg = phaseShiftMec
# generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec, nSamples=nSamples)
generatedSin, nPhases, _, phaseAmplitude, phaseShiftMec, xSin = gsl.generateSin(n=nPhases, nSamples=nSamples)
fig, ax = plt.subplots(figsize=(8, 8))
limit = max(phaseAmplitude)*1.1
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
outterCircle = plt.Circle((0, 0), limit, color='black', fill=False, linewidth=2)
innerCircle = plt.Circle((0, 0), limit*0.9, color='black', fill=False, linewidth=2)
circleWiresUp = list()
circleWiresDown = list()
actualAngles = list()
angleCosPositive = list()
angleSinPositive = list()
angleCosNegative = list()
angleSinNegative = list()
tempAngle = 5/180*np.pi
lines = list()
crosses = [None] * nPhases
dots = [None] * nPhases
sign = [None] * nPhases
for j in range(nPhases):
color = next(ax._get_lines.prop_cycler)['color']
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
angleCosPositive.append(np.cos(actualAngles[j] + tempAngle) * limit * 0.95)
angleSinPositive.append(np.sin(actualAngles[j] + tempAngle) * limit * 0.95)
angleCosNegative.append(np.cos(actualAngles[j] - tempAngle) * limit * 0.95)
angleSinNegative.append(np.sin(actualAngles[j] - tempAngle) * limit * 0.95)
circleWiresUp.append(plt.Circle((angleCosPositive[j], angleSinPositive[j]), limit*0.04, color=color, fill=False, linewidth=2))
circleWiresDown.append(plt.Circle((angleCosNegative[j], angleSinNegative[j]), limit*0.04, color=color, fill=False, linewidth=2))
ax.add_patch(circleWiresUp[j])
ax.add_patch(circleWiresDown[j])
actualExcitation = generatedSin[j][0]
if actualExcitation > 0:
dots[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=s/2, c=color, marker='.')
crosses[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=s, c=color, marker='x')
else:
dots[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=s/2, c=color, marker='.')
crosses[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=s, c=color, marker='x')
ax.add_patch(outterCircle)
ax.add_patch(innerCircle)
def animate(i):
sliding = [[0, 0], [0, 0]]
if len(lines) > 0:
for j in range(nPhases):
ax.lines.pop(0)
ax.set_prop_cycle(None)
for j in range(nPhases):
actualExcitation = generatedSin[j][i]
actualAngle = actualAngles[j]
actualSin = np.sin(actualAngle)
actualCos = np.cos(actualAngle)
actualSinGen = actualSin * actualExcitation
actualCosGen = actualCos * actualExcitation
colors = next(ax._get_lines.prop_cycler)['color']
sliding[1] = [actualCosGen, actualSinGen]
lines.append(ax.plot([sliding[0][0], sliding[1][0]], [sliding[0][1], sliding[1][1]], color=colors, linewidth=5))
if actualExcitation > 0:
last = sign[j]
sign[j] = True
if sign[j] != last:
dots[j].remove()
crosses[j].remove()
dots[j] = ax.scatter(angleCosPositive[j], angleSinPositive[j], s=s/2, c=colors, marker='.')
crosses[j] = ax.scatter(angleCosNegative[j], angleSinNegative[j], s=s, c=colors, marker='x')