Commit 612db780 authored by Tristan Renon's avatar Tristan Renon 💬
Browse files

shgould be nothin

parent 7fd30596
Prog\Python\motorPhaser\.idea
Prog\Python\motorPhaser\__pycache__
Prog\Python\motorPhaser\venv
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-2, 2), ylim=(-2, 2))
N = 50
xSin = np.linspace(0, 2*np.pi, N) # start,stop,step
sin90 = (np.sin(xSin), np.cos(xSin))
phaseShift = (35, 90)
def animate(i):
ax.cla()
#This one start at 0, 0
ax.arrow(0, 0,
np.sin(phaseShift[0]/180*np.pi)*sin90[0][i], np.cos(phaseShift[0]/180*np.pi)*sin90[0][i],
head_width=.1, head_length=.1, fc='blue', ec='blue')
#This one should start at the end of the first one
ax.arrow(np.sin(phaseShift[0]/180*np.pi)*sin90[0][i], np.cos(phaseShift[0]/180*np.pi)*sin90[0][i],
np.sin(phaseShift[1]/180*np.pi)*sin90[1][i], np.cos(phaseShift[1]/180*np.pi)*sin90[1][i],
head_width=.1, head_length=.1, fc='red', ec='red')
# ax.arrow(0, 0,
# sin90[0][i], sin90[1][i],
# head_width=.1, head_length=.1, fc='green', ec='green')
ax.plot(np.sin(phaseShift[0]/180*np.pi)*sin90[0][:i]+np.sin(phaseShift[1]/180*np.pi)*sin90[1][:i], np.cos(phaseShift[0]/180*np.pi)*sin90[0][:i]+np.cos(phaseShift[1]/180*np.pi)*sin90[1][:i])
ax.set(xlim=(-2, 2), ylim=(-2, 2))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=N, blit=False, save_count=50)
plt.show()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-2, 2), ylim=(-2, 2))
N = 50
xSin = np.linspace(0, 2*np.pi, N) # start,stop,step
sin90 = (np.sin(xSin), np.cos(xSin))
def animate(i):
ax.cla()
#This one start at 0, 0
ax.arrow(0, 0,
sin90[0][i], 0,
head_width=.1, head_length=.1, fc='blue', ec='blue')
#This one should start at the end of the first one
ax.arrow(sin90[0][i], 0,
0, sin90[1][i],
head_width=.1, head_length=.1, fc='red', ec='red')
ax.arrow(0, 0,
sin90[0][i], sin90[1][i],
head_width=.1, head_length=.1, fc='green', ec='green')
ax.plot(sin90[0][:i], sin90[1][:i])
ax.set(xlim=(-2, 2), ylim=(-2, 2))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=N, blit=False, save_count=50)
plt.show()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-2, 2), ylim=(-2, 2))
N = 50
nSamples = 50
nPhases = 3
phaseShift = (0, 120, 240)
def generateSin(n=2, phaseShift=(0, 90)):
xSin = np.linspace(0, 2 * np.pi, nSamples)
ret = list()
for i in range(n):
ret.append(np.sin(xSin+phaseShift[i]/180*np.pi))
return tuple(ret)
generatedSin = generateSin(nPhases, phaseShift)
def animate(i):
ax.cla()
ax.arrow(0, 0,
np.sin(phaseShift[0]/180*np.pi)*generatedSin[0][i], np.cos(phaseShift[0]/180*np.pi)*generatedSin[0][i],
head_width=.1, head_length=.1, fc='blue', ec='blue')
#This one should start at the end of the first one
ax.arrow(np.sin(phaseShift[0]/180*np.pi)*generatedSin[0][i], np.cos(phaseShift[0]/180*np.pi)*generatedSin[0][i],
np.sin(phaseShift[1]/180*np.pi)*generatedSin[1][i], np.cos(phaseShift[1]/180*np.pi)*generatedSin[1][i],
head_width=.1, head_length=.1, fc='red', ec='red')
#This one should start at the end of the first one
ax.arrow(np.sin(phaseShift[1]/180*np.pi)*generatedSin[1][i]+np.sin(phaseShift[0]/180*np.pi)*generatedSin[0][i], np.cos(phaseShift[1]/180*np.pi)*generatedSin[1][i]+np.cos(phaseShift[0]/180*np.pi)*generatedSin[0][i],
np.sin(phaseShift[2]/180*np.pi)*generatedSin[2][i], np.cos(phaseShift[2]/180*np.pi)*generatedSin[2][i],
head_width=.1, head_length=.1, fc='green', ec='green')
ax.set(xlim=(-2, 2), ylim=(-2, 2))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=N, blit=False, save_count=50)
plt.show()
\ No newline at end of file
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
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)"
# 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()`
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13, 4))
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
def animate(i):
# Subplot 1
ax1.cla()
sliding = [[0, 0], [0, 0]]
plotX = np.zeros(i)
plotY = np.zeros(i)
for j in range(nPhases):
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]
# 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]]
ax1.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]
# 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]]
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]]
ax2.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
ax2.set(xlim=(-limit, limit), ylim=(-limit, limit))
# 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))
ani = animation.FuncAnimation(fig, animate, interval=20, 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
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-2, 2), ylim=(-2, 2))
N = 50
xSin = np.linspace(0, 2*np.pi, N) # start,stop,step
sin = np.sin(xSin)
def animate(i):
ax.cla()
#This one start at 0, 0
ax.arrow(0, 0,
sin[i], 0,
head_width=.1, head_length=.1, fc='blue', ec='blue')
ax.set(xlim=(-2, 2), ylim=(-2, 2))
ani = animation.FuncAnimation(fig, animate, interval=20, frames=N, blit=False, save_count=50)
plt.show()
\ No newline at end of file
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots(figsize=(8, 8))
ax.set(xlim=(-1.5, 1.5), ylim=(-1.5, 1.5))
N = 50
xSin = np.linspace(0, 2*np.pi, N) # start,stop,step
sin90 = (np.sin(xSin), np.cos(xSin))
line, = ax.plot(sin90[0], sin90[1])
def animate(i):
line.set_data(sin90[0][:i], sin90[1][:i])
return line,
ani = animation.FuncAnimation(
fig, animate, interval=20, frames=N, blit=True, save_count=N)
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
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
nSamples = 50
xSin = np.linspace(0, 2*np.pi, nSamples) # start,stop,step
sin90 = (np.sin(xSin), np.cos(xSin))
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()`
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12,4))
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
# Tweak spacing between subplots to prevent labels from overlapping
plt.subplots_adjust(hspace=0.5)
print(my_lines)
def animate(i):
## in this examples, i takes values 0-10 by steps of 0.01 (the frames in the animation call)
## and will represent the frequency of the 2nd wave in the top subplot
# update the content of the Line2D objects
my_lines[0].set_data(sin90[0][:i], sin90[1][:i])
ax1.set(xlim=(-2, 2), ylim=(-2, 2))
my_lines[1].set_data(sin90[0][:i], sin90[1][:i])
my_lines[2].set_data(sin90[0][:i], sin90[1][:i])
return my_lines ## return updated artists
ani = animation.FuncAnimation(fig, animate, interval=20, 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
nSamples = 50
nPhases = 10
# 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
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))
return tuple(ret), phaseShiftMec, phaseAmplitude
# generatedSin, phaseShiftMec, phaseAmplitude = generateSin(n=nPhases, phaseShiftReg=phaseShiftReg, phaseAmplitude=phaseAmplitude, phaseShiftMec=phaseShiftMec)
generatedSin, phaseShiftMec, phaseAmplitude = generateSin(n=nPhases)
def animate(i):
ax.cla()
sliding = [[0, 0], [0, 0]]
for j in range(nPhases):
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]]
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)
plt.show()
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.pyplot import cm
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)
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()
# 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)
def animate(i):
ax.cla()
sliding = [[0, 0], [0, 0]]
plotX = np.zeros(i)
plotY = np.zeros(i)
for j in range(nPhases):
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]]
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]
# 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)
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
nSamples = 50
nPhases = 5
phaseShift = (0, 72, 72*2, 72*3, 72*4)
color = ['blue', 'red', 'green', 'yellow', 'purple']