Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
EMG analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ym13n22
EMG analysis
Commits
b43e9235
Commit
b43e9235
authored
10 months ago
by
ym13n22
Browse files
Options
Downloads
Patches
Plain Diff
first vision,problem:receive from 2 ports same time
parent
cb91d80e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
integration/Window.py
+67
-23
67 additions, 23 deletions
integration/Window.py
with
67 additions
and
23 deletions
integration/Window.py
+
67
−
23
View file @
b43e9235
...
...
@@ -47,23 +47,27 @@ class Window:
label4
=
tk
.
Label
(
self
.
frame4
,
text
=
"
Section 4
"
)
label4
.
place
(
relx
=
0.5
,
rely
=
0.5
,
anchor
=
'
center
'
)
#self.imu_thread = threading.Thread(target=self.initial_IMU)
#self.emg_thread = threading.Thread(target=self._initialise_EMG_graph)
#self.emg_thread.start()
#self.imu_thread.start()
self
.
imu_thread
=
threading
.
Thread
(
target
=
self
.
initial_IMU
)
self
.
emg_thread
=
threading
.
Thread
(
target
=
self
.
_initialise_EMG_graph
)
self
.
emg_thread
.
start
()
self
.
imu_thread
.
start
()
self
.
emg_data_1
=
[
-
1
]
*
41
self
.
emg_data_2
=
[
-
1
]
*
41
self
.
initial_IMU
()
self
.
_initialise_EMG_graph
()
#self.initial_IMU()
#self._initialise_EMG_graph()
self
.
display_IMU_thread
=
threading
.
Thread
(
target
=
self
.
update_display
)
self
.
display_EMG_thread
=
threading
.
Thread
(
target
=
self
.
EMG_Display
)
def
initial_IMU
(
self
):
# Serial Port Setup
if
'
COM6
'
in
self
.
ports
:
#port maybe different on different laptop
self
.
arduino
=
serial
.
Serial
(
'
COM6
'
,
115200
)
self
.
label2
=
tk
.
Label
(
self
.
frame2
,
text
=
"
Port: COM6
"
)
self
.
label2
.
place
(
relx
=
0.35
,
rely
=
0.8
,
anchor
=
'
center
'
)
self
.
label1
=
tk
.
Label
(
self
.
frame2
,
...
...
@@ -89,6 +93,7 @@ class Window:
sleep
(
1
)
# Conversions
self
.
transmitting
=
False
self
.
toRad
=
2
*
np
.
pi
/
360
self
.
toDeg
=
1
/
self
.
toRad
...
...
@@ -160,16 +165,23 @@ class Window:
# self.emg_label = tk.Label(self.frame1, text="Average EMG: 0", font=("Arial", 14))
# self.emg_label.pack(pady=10)
self
.
roll_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
roll is :
"
)
self
.
roll_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
roll_label
.
place
(
relx
=
0.2
,
rely
=
0.3
,
anchor
=
'
w
'
)
self
.
pitch_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
pitch is :
"
)
self
.
pitch_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
pitch_label
.
place
(
relx
=
0.2
,
rely
=
0.4
,
anchor
=
'
w
'
)
self
.
yaw_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
yaw is :
"
)
self
.
yaw_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
yaw_label
.
place
(
relx
=
0.2
,
rely
=
0.5
,
anchor
=
'
w
'
)
# Initialize the data transmission flag
self
.
transmitting
=
False
def
_initialise_EMG_graph
(
self
):
if
'
COM5
'
in
self
.
ports
:
#port maybe different on different laptop
self
.
arduino_EMG
=
serial
.
Serial
(
'
COM5
'
,
9600
,
timeout
=
1
)
self
.
label2
=
tk
.
Label
(
self
.
frame3
,
text
=
"
Port: COM5
"
)
self
.
label2
.
place
(
relx
=
0.23
,
rely
=
0.8
,
anchor
=
'
center
'
)
self
.
label1
=
tk
.
Label
(
self
.
frame3
,
...
...
@@ -193,6 +205,7 @@ class Window:
self
.
label1
.
place
(
relx
=
0.5
,
rely
=
0.9
,
anchor
=
'
center
'
)
# Create a figure and axis
self
.
EMG_transmitting
=
False
fig
=
Figure
(
figsize
=
((
self
.
width
/
200
),
(
self
.
height
/
200
)))
# Adjusting figsize based on frame size
self
.
ax1
=
fig
.
add_subplot
(
111
)
...
...
@@ -228,32 +241,61 @@ class Window:
self
.
canvas1
=
FigureCanvasTkAgg
(
fig
,
master
=
self
.
frame4
)
self
.
canvas1
.
draw
()
self
.
canvas1
.
get_tk_widget
().
pack
(
fill
=
tk
.
BOTH
,
expand
=
True
)
self
.
EMG_Display
()
self
.
outer_EMG_label
=
tk
.
Label
(
self
.
frame3
,
text
=
f
"
EMG for Extensor Carpi Ulnaris is :
"
)
self
.
outer_EMG_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
outer_EMG_label
.
place
(
relx
=
0.1
,
rely
=
0.2
,
anchor
=
'
w
'
)
self
.
outer_EMG_Number
=
tk
.
Label
(
self
.
frame3
,
text
=
""
,
fg
=
"
red
"
)
self
.
outer_EMG_Number
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
outer_EMG_Number
.
place
(
relx
=
0.2
,
rely
=
0.3
,
anchor
=
'
w
'
)
self
.
inner_EMG_label
=
tk
.
Label
(
self
.
frame3
,
text
=
f
"
EMG for Flexor Carpi Radialis is :
"
)
self
.
inner_EMG_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
inner_EMG_label
.
place
(
relx
=
0.1
,
rely
=
0.4
,
anchor
=
'
w
'
)
self
.
inner_EMG_Number
=
tk
.
Label
(
self
.
frame3
,
text
=
""
,
fg
=
"
blue
"
)
self
.
inner_EMG_Number
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
inner_EMG_Number
.
place
(
relx
=
0.2
,
rely
=
0.5
,
anchor
=
'
w
'
)
self
.
gesture_label
=
tk
.
Label
(
self
.
frame3
,
text
=
f
"
Gesture is :
"
)
self
.
gesture_label
.
config
(
font
=
(
"
Arial
"
,
12
))
self
.
gesture_label
.
place
(
relx
=
0.1
,
rely
=
0.6
,
anchor
=
'
w
'
)
self
.
EMG_transmitting
=
False
def
start_data_transmission
(
self
):
# Set the transmitting flag to True and start the update loop
self
.
arduino
=
serial
.
Serial
(
'
COM6
'
,
115200
)
self
.
transmitting
=
True
self
.
update_display
()
def
start_EMG_data_transmission
(
self
):
# Set the transmitting flag to True and start the update loop
self
.
arduino_EMG
=
serial
.
Serial
(
'
COM5
'
,
9600
,
timeout
=
1
)
self
.
EMG_transmitting
=
True
self
.
EMG_Display
()
def
disconnect
(
self
):
self
.
transmitting
=
False
self
.
root
.
after_cancel
(
self
.
update_display_id
)
if
self
.
arduino
is
not
None
:
self
.
arduino
.
close
()
self
.
arduino
=
None
def
EMG_disconnect
(
self
):
self
.
EMG_transmitting
=
False
self
.
root
.
after_cancel
(
self
.
EMG_display_id
)
if
self
.
arduino_EMG
is
not
None
:
self
.
arduino_EMG
.
close
()
self
.
arduino_EMG
=
None
def
update_display
(
self
):
if
self
.
transmitting
:
try
:
while
self
.
arduino
.
inWaiting
()
>
0
:
while
((
self
.
arduino
.
inWaiting
()
>
0
)
and
(
self
.
transmitting
==
True
)):
dataPacket
=
self
.
arduino
.
readline
()
dataPacket
=
dataPacket
.
decode
()
cleandata
=
dataPacket
.
replace
(
"
\r\n
"
,
""
)
...
...
@@ -273,15 +315,9 @@ class Window:
pitch
=
-
math
.
asin
(
2
*
(
q0
*
q2
-
q3
*
q1
))
yaw
=
-
math
.
atan2
(
2
*
(
q0
*
q3
+
q1
*
q2
),
1
-
2
*
(
q2
*
q2
+
q3
*
q3
))
roll_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
roll is :
"
+
str
(
roll
))
roll_label
.
config
(
font
=
(
"
Arial
"
,
12
))
roll_label
.
place
(
relx
=
0.2
,
rely
=
0.3
,
anchor
=
'
w
'
)
pitch_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
pitch is :
"
+
str
(
pitch
))
pitch_label
.
config
(
font
=
(
"
Arial
"
,
12
))
pitch_label
.
place
(
relx
=
0.2
,
rely
=
0.4
,
anchor
=
'
w
'
)
yaw_label
=
tk
.
Label
(
self
.
frame2
,
text
=
"
yaw is :
"
+
str
(
yaw
))
yaw_label
.
config
(
font
=
(
"
Arial
"
,
12
))
yaw_label
.
place
(
relx
=
0.2
,
rely
=
0.5
,
anchor
=
'
w
'
)
self
.
roll_label
.
config
(
text
=
"
roll is :
"
+
str
(
roll
))
self
.
pitch_label
.
config
(
text
=
"
pitch is :
"
+
str
(
pitch
))
self
.
yaw_label
.
config
(
text
=
"
yaw is :
"
+
str
(
yaw
))
# Rotation matrices
Rz
=
np
.
array
([
...
...
@@ -374,16 +410,24 @@ class Window:
print
(
f
"
An error occurred:
{
e
}
"
)
# Call update_display() again after 50 milliseconds
self
.
root
.
after
(
50
,
self
.
update_display
)
self
.
update_display_id
=
self
.
root
.
after
(
50
,
self
.
update_display
)
def
EMG_Display
(
self
):
if
self
.
EMG_transmitting
:
try
:
while
((
self
.
arduino_EMG
.
inWaiting
()
>
0
)
and
(
self
.
EMG_transmitting
==
True
)):
data
=
self
.
arduino_EMG
.
readline
()
emg_data
=
self
.
_decode
(
data
)
if
emg_data
is
not
None
:
print
(
f
"
EMG 1:
{
emg_data
[
0
]
}
, EMG 2:
{
emg_data
[
1
]
}
"
)
self
.
outer_EMG_Number
.
config
(
text
=
f
"
{
emg_data
[
0
]
}
"
)
self
.
inner_EMG_Number
.
config
(
text
=
f
"
{
emg_data
[
1
]
}
"
)
# Append the new data to the lists
self
.
emg_data_1
.
append
(
emg_data
[
0
])
...
...
@@ -403,7 +447,7 @@ class Window:
# Call update_display() again after 50 milliseconds
self
.
root
.
after
(
50
,
self
.
EMG_Display
)
self
.
EMG_display_id
=
self
.
root
.
after
(
50
,
self
.
EMG_Display
)
def
_decode
(
self
,
serial_data
):
serial_string
=
serial_data
.
decode
(
errors
=
"
ignore
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment