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

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.hevs.ch/tristan.renon/motorphaservisualisationtool into master
parents d50d3cd7 29464337
Prog/Python/motorPhaser/.idea/
Prog/Python/motorPhaser/__pycache__/
Prog/Python/motorPhaser/venv/
Prog/Python/motorPhaser/build/
Prog/Python/motorPhaser/dist/
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (motorPhaser)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/motorPhaser.iml" filepath="$PROJECT_DIR$/.idea/motorPhaser.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -2,122 +2,99 @@ import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
nSamples = 50
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)
xSin = np.linspace(0, 2*np.pi, nSamples) # start,stop,step
sin90 = (np.sin(xSin), np.cos(xSin))
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None):
# Generate things if user did not tell about them
if phaseAmplitude is None:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None:
if n == 2:
phaseShiftMec=(0, 90)
else:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None:
phaseShiftReg = phaseShiftMec
# Make sure people gave valid parameters
assert len(phaseShiftReg) == n, "phaseShiftReg is not the same size as Phases (n)"
assert len(phaseAmplitude) == n, "phaseAmplitude is not the same size as Phases (n)"
assert len(phaseShiftMec) == n, "phaseShiftMec is not the same size as Phases (n)"
# 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)
# 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]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin = generateSin(inputNPhases, inputPhaseShiftReg, inputPhaseAmplitude, inputPhaseShiftMec)
def create_plot(i):
l1, = i.plot(sin90[0], sin90[0], label='$y=f_1(t)$')
arts = [l1]
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13, 4))
limit1 = inputNPhases / 2 * 1.1
limit2 = max(phaseAmplitude) * 1.1
ax3.set(xlim=(0, 2 * np.pi), ylim=(-limit2, limit2))
return arts ## return the artists created by `plt.plot()`
actualAngles = list()
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13, 4))
for j in range(nPhases):
ax3.plot(xSin, generatedSin[j])
actualAngles.append(phaseShiftMec[j] / 180 * np.pi)
my_lines = [] ## array to keep track of the Line2D artists
l = create_plot(ax1)
my_lines += l ## add artists to array
l = create_plot(ax2)
my_lines += l
l = create_plot(ax3)
my_lines += l
vertical = ax3.axvline(x=xSin[0], color='black')
def animate(i):
# Subplot 1
ax1.cla()
sliding = [[0, 0], [0, 0]]
ax2.cla()
ax1.set(xlim=(-limit1, limit1),
ylim=(-limit1, limit1))
ax2.set(xlim=(-limit2, limit2), ylim=(-limit2, limit2))
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
sliding[0][0] += sliding[1][0]
sliding[0][1] += sliding[1][1]
sliding1[0][0] += sliding1[1][0]
sliding1[0][1] += sliding1[1][1]
# New end = sin-cos (x-y) of mechanical multiplied by power supply
sliding[1] = [np.sin(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i], np.cos(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i]]
sliding1[1] = [actualCosGen, actualSinGen]
ax1.arrow(sliding[0][0], sliding[0][1],
sliding[1][0], sliding[1][1],
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 = np.sin(phaseShiftMec[j]/180*np.pi)*generatedSin[j][:i]
yTemp = np.cos(phaseShiftMec[j]/180*np.pi)*generatedSin[j][:i]
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
ax1.plot(plotX, plotY, color='skyblue')
ax1.set(xlim=(-(inputNPhases+1)/2, (inputNPhases+1)/2), ylim=(-(inputNPhases+1)/2, (inputNPhases+1)/2))
# Subplot 2
ax2.cla()
sliding = [[0, 0], [0, 0]]
# ------------------------------------------------------------------------------------------------------
# Subplot 2 --------------------------------------------------------------------------------------------
sliding2 = [[0, 0], [0, 0]]
for j in range(nPhases):
colors = next(ax2._get_lines.prop_cycler)['color']
sliding[0] += sliding[1]
sliding[1] = [np.sin(phaseShiftMec[j] / 180 * np.pi) * generatedSin[j][i],
np.cos(phaseShiftMec[j] / 180 * np.pi) * generatedSin[j][i]]
sliding2[0] += sliding2[1]
sliding2[1] = [actualCosGen, actualSinGen]
ax2.arrow(sliding[0][0], sliding[0][1],
sliding[1][0], sliding[1][1],
ax2.arrow(sliding2[0][0], sliding2[0][1],
sliding2[1][0], sliding2[1][1],
head_width=.1, head_length=.1, fc=colors, ec=colors)
limit = max(phaseAmplitude) * 1.1
ax2.set(xlim=(-limit, limit), ylim=(-limit, limit))
# -----------------------------------------------------------------------------------------------------
# Subplot 3 -------------------------------------------------------------------------------------------
vertical.set_xdata(x=xSin[i])
# Subplot 3
ax3.cla()
for j in range(nPhases):
plt.plot(xSin, generatedSin[j])
plt.axvline(x=xSin[i], color='black')
limit = max(phaseAmplitude)*1.1
ax3.set(xlim=(0, 2 * np.pi), ylim=(-limit, limit))
ax1.plot(plotX, plotY, color='skyblue')
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
......
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.pyplot import cm
import generateSinLib as gsl
nSamples = 50
nPhases = 10
nPhases = 5
# phaseAmplitude = (0, 1.382, 1.382, 1.382, 1.382)
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
......@@ -14,58 +15,35 @@ nPhases = 10
# phaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
# phaseShiftReg = phaseShiftMec
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-2, 2), ylim=(-2, 2))
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None):
# Generate things if user did not tell about them
if phaseAmplitude is None:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None:
if n == 2:
phaseShiftMec = (0, 90)
else:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None:
phaseShiftReg = phaseShiftMec
# Make sure people gave valid parameters
assert len(phaseShiftReg) == n, "phaseShiftReg is not the same size as Phases (n)"
assert len(phaseAmplitude) == n, "phaseAmplitude is not the same size as Phases (n)"
assert len(phaseShiftMec) == n, "phaseShiftMec is not the same size as Phases (n)"
# 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]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
# 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)
return tuple(ret), phaseShiftMec, phaseAmplitude
# generatedSin, phaseShiftMec, phaseAmplitude = generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec)
generatedSin, phaseShiftMec, phaseAmplitude = generateSin(n=nPhases)
fig, ax = plt.subplots(figsize=(8, 8))
limit = max(phaseAmplitude)*1.1
def animate(i):
ax.cla()
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
sliding = [[0, 0], [0, 0]]
for j in range(nPhases):
actualExcitation = generatedSin[j][i]
actualAngle = phaseShiftMec[j] / 180 * np.pi
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] = [np.sin(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i], np.cos(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i]]
sliding[1] = [actualCosGen, actualSinGen]
ax.arrow(sliding[0][0], sliding[0][1],
sliding[1][0], sliding[1][1],
head_width=.1, head_length=.1, fc=colors, ec=colors)
limit = max(phaseAmplitude)*1.1
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
......
import numpy as np
def generateSin(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:
if n == 2:
phaseShiftMec=(0, 90)
else:
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]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec, xSin
\ 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
import generateSinLib as gsl
nSamples = 50
inputNPhases = 5
inputPhaseAmplitude = (0, 1, 1, 1, 1)
......@@ -14,71 +13,54 @@ inputPhaseAmplitude = (0, 1, 1, 1, 1)
inputPhaseShiftMec = (0, 72, 72*2, 72*3, 72*4)
inputPhaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-(inputNPhases+1)/2, (inputNPhases+1)/2), ylim=(-(inputNPhases+1)/2, (inputNPhases+1)/2))
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None):
# Generate things if user did not tell about them
if phaseAmplitude is None:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None:
if n == 2:
phaseShiftMec=(0, 90)
else:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None:
phaseShiftReg = phaseShiftMec
# Make sure people gave valid parameters
assert len(phaseShiftReg) == n, "phaseShiftReg is not the same size as Phases (n)"
assert len(phaseAmplitude) == n, "phaseAmplitude is not the same size as Phases (n)"
assert len(phaseShiftMec) == n, "phaseShiftMec is not the same size as Phases (n)"
# Generate x (0 to 2pi)
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(inputNPhases, inputPhaseShiftReg, inputPhaseAmplitude, inputPhaseShiftMec, nSamples=nSamples)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec, _ = gsl.generateSin(n=inputNPhases, nSamples=nSamples)
# Generate power supply for coils
for i in range(n):
ret.append(phaseAmplitude[i]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), n, phaseShiftReg, phaseAmplitude, phaseShiftMec
generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec = generateSin(inputNPhases, inputPhaseShiftReg, inputPhaseAmplitude, inputPhaseShiftMec)
# generatedSin, nPhases, phaseShiftReg, phaseAmplitude, phaseShiftMec = generateSin(n=inputNPhases)
fig, ax = plt.subplots(figsize=(8, 8))
limit = (nPhases+1)/2
def animate(i):
ax.cla()
sliding = [[0, 0], [0, 0]]
ax.set(xlim=(-limit, limit), ylim=(-limit, limit))
plotX = np.zeros(i)
plotY = np.zeros(i)
for j in range(nPhases):
# ------------------------------------------------------------------------------------------------------
# Calculations (Do it only one and reused after)
actualExcitation = generatedSin[j][i]
actualAngle = phaseShiftMec[j] / 180 * np.pi
actualSin = np.sin(actualAngle)
actualCos = np.cos(actualAngle)
actualSinGen = actualSin * actualExcitation
actualCosGen = actualCos * actualExcitation
# ------------------------------------------------------------------------------------------------------
# Subplot 1 --------------------------------------------------------------------------------------------
colors = next(ax._get_lines.prop_cycler)['color']
# New start = sum of last starts
sliding[0][0] += sliding[1][0]
sliding[0][1] += sliding[1][1]
# New end = sin-cos (x-y) of mechanical multiplied by power supply
sliding[1] = [np.sin(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i], np.cos(phaseShiftMec[j]/180*np.pi)*generatedSin[j][i]]
sliding[1] = [actualCosGen, actualSinGen]
ax.arrow(sliding[0][0], sliding[0][1],
sliding[1][0], sliding[1][1],
head_width=.1, head_length=.1, fc=colors, ec=colors)
# Needed to draw the ellipse
xTemp = np.sin(phaseShiftMec[j]/180*np.pi)*generatedSin[j][:i]
yTemp = np.cos(phaseShiftMec[j]/180*np.pi)*generatedSin[j][:i]
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
ax.plot(plotX, plotY, color='skyblue')
ax.set(xlim=(-(inputNPhases+1)/2, (inputNPhases+1)/2), ylim=(-(inputNPhases+1)/2, (inputNPhases+1)/2))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
......
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.pyplot import cm
import generateSinLib as gsl
nSamples = 50
nPhases = 10
......@@ -10,48 +11,20 @@ nPhases = 10
# phaseShiftReg = (0, 36, 180-36, 180+36, 360-36)
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(0, 2*np.pi), ylim=(-2, 2))
def generateSin(n=3, phaseShiftReg=None, phaseAmplitude=None, phaseShiftMec=None):
# Generate things if user did not tell about them
if phaseAmplitude is None:
phaseAmplitude = np.ones(n)
if phaseShiftMec is None:
if n == 2:
phaseShiftMec=(0, 90)
else:
phaseShiftMec = np.linspace(0, 360, n, endpoint=False)
if phaseShiftReg is None:
phaseShiftReg = phaseShiftMec
# Make sure people gave valid parameters
assert len(phaseShiftReg) == n, "phaseShiftReg is not the same size as Phases (n)"
assert len(phaseAmplitude) == n, "phaseAmplitude is not the same size as Phases (n)"
# 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]*np.sin(xSin+phaseShiftReg[i]/180*np.pi))
return tuple(ret), xSin, phaseAmplitude
# supply = generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec)
supply = generateSin(n=nPhases)
# supply, _, _, phaseAmplitude, _, xSin = generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec, nSamples=nSamples)
generatedSin, _, _, phaseAmplitude, _, xSin = gsl.generateSin(n=nPhases, nSamples=nSamples)
def animate(i):
plt.cla()
for j in range(nPhases):
plt.plot(supply[1], supply[0][j])
plt.axvline(x=supply[1][i], color='black')
vertical.set_xdata(x=xSin[i])
limit = max(supply[2])*1.1
ax.set(xlim=(0, 2 * np.pi), ylim=(-limit, limit))
for j in range(nPhases):
ax.plot(xSin, generatedSin[j])
vertical = ax.axvline(xSin[0], color='black')
limit = max(phaseAmplitude)*1.1
ax.set(xlim=(0, 2 * np.pi), ylim=(-limit, limit))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=nSamples, blit=False, save_count=nSamples)
......
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
#---------End of imports
from tkinter import Frame,Label,Entry,Button
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def Clear(self):
print("clear")
self.textAmplitude.delete(0, 'end')
self.textAmplitude.insert(0, "1.0")
self.textSpeed.delete(0, 'end')
self.textSpeed.insert(0, "1.0")
self.textPhases.delete(0, 'end')
self.textPhases.insert(0, "5")
self.textPhaseAmplitude.delete(0, 'end')
self.textPhaseAmplitude.insert(0, "0, 1.382, 1.382, 1.382, 1.382")
self.textPhaseShiftMec.delete(0, 'end')
self.textPhaseShiftMec.insert(0, "0, 72, 144, 216, 288")
self.textPhaseShiftReg.delete(0, 'end')
self.textPhaseShiftReg.insert(0, "0, 72, 144, 216, 288")
self.textnSamples.delete(0, 'end')
self.textnSamples.insert(0, "50")
def Plot(self):
self.v = float(self.textSpeed.get())
self.A = float(self.textAmplitude.get())
self.nSamples = int(self.textnSamples.get())
self.inputNPhases = int(self.textPhases.get())
self.inputPhaseAmplitude = np.ones(self.inputNPhases)