-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathemg_ascii_graph.py
executable file
·69 lines (53 loc) · 1.65 KB
/
emg_ascii_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
"""
Script that prints in bar plot
the value of the EMG sensors.
Needs ascii_graph:
sudo pip install ascii_graph
Author: Sammy Pfeiffer <Sammy.Pfeiffer at student.uts.edu.au>
"""
from __future__ import print_function
from ascii_graph import Pyasciigraph
from random import randrange
from time import sleep
import os
import rospy
from ros_myo.msg import EmgArray
def test():
while True:
ea = EmgArray()
arr = []
for i in range(8):
arr.append(randrange(0, 1024))
ea.data = arr
graph = Pyasciigraph(multivalue=False)
emg_data = []
for idx, d in enumerate(ea.data):
emg_data.append((idx, d))
emg_data.append(('MAX_VAL', 1024))
for emg_line in graph.graph('EMG values:', emg_data):
print(emg_line)
sleep(0.5)
os.system('clear')
if __name__ == '__main__':
# test()
rospy.init_node('emg_bar_plot')
rospy.loginfo("Printing plot of EMG values...")
def emg_cb(ea):
# Clear screen
print("\n\n\n\n\n\n\n\n\n\n\n\n")
graph = Pyasciigraph()
emg_data = []
# This bar is just for scale
emg_data.append(('MAX_VAL', 2048))
for idx, d in enumerate(ea.data):
bar_title = "EMG #" + str(idx)
emg_data.append((bar_title, d))
for emg_line in graph.graph('EMG values:', emg_data):
print(emg_line)
emg_sub = rospy.Subscriber('/myo_raw/myo_emg',
EmgArray,
emg_cb,
queue_size=1)
rospy.loginfo("Awaiting publications...")
rospy.spin()