-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Myo data in the time #83
Comments
Hi @AdrianIbarra , Not sure I can follow. myo-python/examples/03_live_emg.py Lines 31 to 52 in 3b72991
As you can see it stores the |
Yes I am using this program: from matplotlib import pyplot as plt
from collections import deque
from threading import Lock, Thread
import myo
import numpy as np
class EmgCollector(myo.DeviceListener):
"""
Collects EMG data in a queue with *n* maximum number of elements.
"""
def __init__(self, n):
self.n = n
self.lock = Lock()
self.emg_data_queue = deque(maxlen=n)
def get_emg_data(self):
with self.lock:
return list(self.emg_data_queue)
# myo.DeviceListener
def on_connected(self, event):
event.device.stream_emg(True)
def on_emg(self, event):
with self.lock:
self.emg_data_queue.append((event.timestamp, event.emg))
class Plot(object):
def __init__(self, listener):
self.n = listener.n
self.listener = listener
self.fig = plt.figure()
self.axes = [self.fig.add_subplot('81' + str(i)) for i in range(1, 9)]
[(ax.set_ylim([-100, 100])) for ax in self.axes]
self.graphs = [ax.plot(np.arange(self.n), np.zeros(self.n))[0] for ax in self.axes]
plt.ion()
def update_plot(self):
emg_data = self.listener.get_emg_data()
emg_data = np.array([x[1] for x in emg_data]).T
for g, data in zip(self.graphs, emg_data):
if len(data) < self.n:
# Fill the left side with zeroes.
data = np.concatenate([np.zeros(self.n - len(data)), data])
g.set_ydata(data)
plt.draw()
def main(self):
while True:
self.update_plot()
plt.pause(1.0 / 30)
def main():
myo.init()
hub = myo.Hub()
listener = EmgCollector(1000)
with hub.run_in_background(listener.on_event):
Plot(listener).main()
if __name__ == '__main__':
main() But, I know that the frecuncy is of 200 Hz and i can change te number of adquired data, but i don't know abut time, how many data i im getting in a certain period of time (ms), how can i know that? thanks again, i like you work. |
Not sure I understand the question. 200Hz means you're getting 200 measurements per seconds. |
Hi, my name is Adrian.
I have a question about Myo.
In the Python program I can change the number of data with this instruction: listener = EmgCollector (512),
but I want to know the time in which the data is acquired, how can i change that?
Thanks for you time.
The text was updated successfully, but these errors were encountered: