Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Tristan Renon
motorPhaserVisualisationTool
Commits
8f63413a
Commit
8f63413a
authored
May 27, 2021
by
Tristan Renon
Browse files
working with stator
parent
79508994
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
489 additions
and
23 deletions
+489
-23
Management/motorPhaser.pptx
Management/motorPhaser.pptx
+0
-0
Prog/Exe/rotatingFieldVisualisationToolExe.zip
Prog/Exe/rotatingFieldVisualisationToolExe.zip
+0
-0
Prog/Exe/rotatingFieldVisualisationToolExeWithStator.zip
Prog/Exe/rotatingFieldVisualisationToolExeWithStator.zip
+0
-0
Prog/Python/motorPhaser/Training/2enhancedVector+circle.py
Prog/Python/motorPhaser/Training/2enhancedVector+circle.py
+0
-0
Prog/Python/motorPhaser/Training/2simpleVector+circle.py
Prog/Python/motorPhaser/Training/2simpleVector+circle.py
+0
-0
Prog/Python/motorPhaser/Training/3enhancedVector.py
Prog/Python/motorPhaser/Training/3enhancedVector.py
+0
-0
Prog/Python/motorPhaser/Training/arrowDrawing.py
Prog/Python/motorPhaser/Training/arrowDrawing.py
+0
-0
Prog/Python/motorPhaser/Training/circleDrawing.py
Prog/Python/motorPhaser/Training/circleDrawing.py
+0
-0
Prog/Python/motorPhaser/Training/doubleAnimation.py
Prog/Python/motorPhaser/Training/doubleAnimation.py
+0
-0
Prog/Python/motorPhaser/Training/supplyGenerator.py
Prog/Python/motorPhaser/Training/supplyGenerator.py
+0
-0
Prog/Python/motorPhaser/Training/testDelete.py
Prog/Python/motorPhaser/Training/testDelete.py
+34
-0
Prog/Python/motorPhaser/Training/tkinterTest.py
Prog/Python/motorPhaser/Training/tkinterTest.py
+0
-0
Prog/Python/motorPhaser/allTogether.py
Prog/Python/motorPhaser/allTogether.py
+4
-3
Prog/Python/motorPhaser/allTogetherWithStator.py
Prog/Python/motorPhaser/allTogetherWithStator.py
+160
-0
Prog/Python/motorPhaser/colorFuck.py
Prog/Python/motorPhaser/colorFuck.py
+0
-11
Prog/Python/motorPhaser/fixedArrow.py
Prog/Python/motorPhaser/fixedArrow.py
+44
-5
Prog/Python/motorPhaser/fixedArrowPatches.py
Prog/Python/motorPhaser/fixedArrowPatches.py
+112
-0
Prog/Python/motorPhaser/fixedLines.py
Prog/Python/motorPhaser/fixedLines.py
+110
-0
Prog/Python/motorPhaser/generateSinLib.py
Prog/Python/motorPhaser/generateSinLib.py
+1
-4
Prog/Python/motorPhaser/setup.py
Prog/Python/motorPhaser/setup.py
+24
-0
No files found.
Management/motorPhaser.pptx
View file @
8f63413a
No preview for this file type
Prog/Exe/rotatingFieldVisualisationToolExe.zip
0 → 100644
View file @
8f63413a
File added
Prog/Exe/rotatingFieldVisualisationToolExeWithStator.zip
0 → 100644
View file @
8f63413a
File added
Prog/Python/motorPhaser/2enhancedVector+circle.py
→
Prog/Python/motorPhaser/
Training/
2enhancedVector+circle.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/2simpleVector+circle.py
→
Prog/Python/motorPhaser/
Training/
2simpleVector+circle.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/3enhancedVector.py
→
Prog/Python/motorPhaser/
Training/
3enhancedVector.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/arrowDrawing.py
→
Prog/Python/motorPhaser/
Training/
arrowDrawing.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/circleDrawing.py
→
Prog/Python/motorPhaser/
Training/
circleDrawing.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/doubleAnimation.py
→
Prog/Python/motorPhaser/
Training/
doubleAnimation.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/supplyGenerator.py
→
Prog/Python/motorPhaser/
Training/
supplyGenerator.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/Training/testDelete.py
0 → 100644
View file @
8f63413a
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
Prog/Python/motorPhaser/tkinterTest.py
→
Prog/Python/motorPhaser/
Training/
tkinterTest.py
View file @
8f63413a
File moved
Prog/Python/motorPhaser/allTogether.py
View file @
8f63413a
...
...
@@ -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
Prog/Python/motorPhaser/allTogetherWithStator.py
0 → 100644
View file @
8f63413a
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
Prog/Python/motorPhaser/colorFuck.py
deleted
100644 → 0
View file @
79508994
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
Prog/Python/motorPhaser/fixedArrow.py
View file @
8f63413a
...
...
@@ -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
()
Prog/Python/motorPhaser/fixedArrowPatches.py
0 → 100644
View file @
8f63413a
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
()
Prog/Python/motorPhaser/fixedLines.py
0 → 100644
View file @
8f63413a
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'
)