Commit 3f721fb9 authored by Tristan Renon's avatar Tristan Renon 💬
Browse files

optimized, pseudo-lib and I maybe fuc%'d up the gitignore again, I hate me......

optimized, pseudo-lib and I maybe fuc%'d up the gitignore again, I hate me... I hope one day I will be able to use this thing correctly
parent 612db780
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (motorPhaser)" project-jdk-type="Python SDK" />
</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="jdk" jdkName="Python 3.8 (motorPhaser)" jdkType="Python SDK" />
<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="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="be33ff8b-30c0-43bd-9f6e-60d554acbe8e" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/generateSinLib.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/allTogether.py" beforeDir="false" afterPath="$PROJECT_DIR$/allTogether.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/fixedArrow.py" beforeDir="false" afterPath="$PROJECT_DIR$/fixedArrow.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/multiVectorFinal.py" beforeDir="false" afterPath="$PROJECT_DIR$/multiVectorFinal.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/supplyGenerator.py" beforeDir="false" afterPath="$PROJECT_DIR$/supplyGenerator.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
</component>
<component name="ProjectId" id="1stc60WOZ6F2fArRjOVH43Iujzu" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RunManager" selected="Python.allTogether">
<configuration name="allTogether" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="motorPhaser" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/allTogether.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="doubleAnimation" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="motorPhaser" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/doubleAnimation.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="fixedArrow" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="motorPhaser" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/fixedArrow.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="multiVectorFinal" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="motorPhaser" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/multiVectorFinal.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="supplyGenerator" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="motorPhaser" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/supplyGenerator.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.allTogether" />
<item itemvalue="Python.fixedArrow" />
<item itemvalue="Python.multiVectorFinal" />
<item itemvalue="Python.supplyGenerator" />
<item itemvalue="Python.doubleAnimation" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="be33ff8b-30c0-43bd-9f6e-60d554acbe8e" name="Default Changelist" comment="" />
<created>1621695147492</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1621695147492</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="WindowStateProjectService">
<state x="414" y="175" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1621695231317">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="414" y="175" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621695231317" />
<state width="1899" height="282" key="GridCell.Tab.0.bottom" timestamp="1621702916510">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="282" key="GridCell.Tab.0.bottom/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621702916510" />
<state width="1899" height="282" key="GridCell.Tab.0.center" timestamp="1621702916509">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="282" key="GridCell.Tab.0.center/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621702916509" />
<state width="1899" height="282" key="GridCell.Tab.0.left" timestamp="1621702916509">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="282" key="GridCell.Tab.0.left/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621702916509" />
<state width="1899" height="282" key="GridCell.Tab.0.right" timestamp="1621702916509">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1899" height="282" key="GridCell.Tab.0.right/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621702916509" />
<state x="461" y="165" key="SettingsEditor" timestamp="1621696296426">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="461" y="165" key="SettingsEditor/0.0.1920.1040/1920.0.1920.1040/-1920.0.1920.1040@0.0.1920.1040" timestamp="1621696296426" />
</component>
</project>
\ No newline at end of file
......@@ -2,122 +2,91 @@ import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
nSamples = 50
import generateSinLib as gsl
inputNPhases = 5
nSamples = 50
inputNPhases = 97
# 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)"
# 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]
return arts ## return the artists created by `plt.plot()`
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)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13, 4))
limit = max(phaseAmplitude) * 1.1
ax3.set(xlim=(0, 2 * np.pi), ylim=(-limit, limit))
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
for j in range(nPhases):
ax3.plot(xSin, generatedSin[j])
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=(-(inputNPhases + 1) / 2, (inputNPhases + 1) / 2),
ylim=(-(inputNPhases + 1) / 2, (inputNPhases + 1) / 2))
ax2.set(xlim=(-limit, limit), ylim=(-limit, limit))
sliding1 = [[0, 0], [0, 0]]
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(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 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))
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)