dzhu / myo-raw

MIT License
218 stars 115 forks source link

Armband disconnects after a few seconds #30

Open Girum opened 6 years ago

Girum commented 6 years ago

Hi! Well, when I run the program, something like:

from myo_raw import MyoRaw
import sys

m = MyoRaw(sys.argv[1] if len (sys.agv) >= 2 else None)

def emg_hdl(emg, moving):
    print(emg)

m.add_emg_handler(emg_hdl)
m.connect()

try:
    while True:
        m.run()
except KeyboardInterrupt:
    pass
finally:
    m.disconnect()
    print("Disconnected")

And after a few seconds, the rectangular LED on armband (for connection) offs.... How to not disconnect?

hananabilabd commented 6 years ago

I had the same problem did you get to solve it ?

hananabilabd commented 6 years ago

@Girum it operates excellent with me and then after 1 minutes it crushes

MartineGirard commented 6 years ago

Hello I have the same problem, do you have an idea to solve it?

hananabilabd commented 6 years ago

@MartineGirard if you are asking about the disconnection issue I think it has been resolved by PyoConnect and someone else has fixed this bug by making it connect again after disconnecting ---> but if you were asking about the EMG_Rate , I still had the same issue

MartineGirard commented 6 years ago

@hananabilabd thanks for your answer but i have this problem of disconnection with Myo_Raw, not MyoConnect. And I didn't find any solution, if you could link me the thread where this guy you talk about have fixed this bug i would be gratefull.

hananabilabd commented 6 years ago

@MartineGirard

link or you can try the PyoConnect script ,, Run it and it will make sure it is connected all time Are you running it on linux ?

MartineGirard commented 6 years ago

@hananabilabd Yes, i am running it on Linux. Thanks for your two solutions. But i would like to use only myo-raw and i would like it not to disconnect. Maybe if i don't find any solutions i will try PyoConnect.

Girum commented 6 years ago

Sorry for the late! I didn't has much sucess with MyoRaw. The, I found other to use, and I'm using now. https://github.com/Alvipe/Open-Myo

hananabilabd commented 6 years ago

@Girum Thanks But does it read frames quickly ?

Girum commented 6 years ago

Yes... Of course, it all depends of your code. I've logged The results, and input them (after get RMS, etc) thrhougth a MLP. In the train/Test it works fine, but, in Real time, for example, tô predict, it losts acc. Well, I dont know for What you use the data too...

hananabilabd commented 6 years ago

@Girum all i need to do is to handle the RAW EMG data like in myo_raw
and then pass it to a classifier which we have built ,, My problem in myo_raw, that emg data frame is very slow , I receive 512 frame of emg every 10 sec which is very slow while in windows running the capture data provided by MYO_SDK gives me 3000 frame in 10 seconds so my question is , can open_myo do that on linux ?

hananabilabd commented 6 years ago

@Girum

Girum commented 6 years ago

@hananabilabd Well, maybe my problem ia the same. We trying to solve this too... But seen The open-myo code, we realized that has no sleep in code, or something like that... So, the problem has to be on the bluepy module... And that is the difficult. For curiosity: how you measure the 512 and 3000 frames?

hananabilabd commented 6 years ago

@Girum I discovered where is the problem :D Furthermore I measure 512 frames by calculating how many times the code enters the function ""process_emg"" and using stopwatch ,, like this

def process_emg(emg):
    #print(emg)
    global i
    i+=1
    print (i)

or just by concatenating frames until you get 512 frame like this

def process_emg(emg):
    #print(emg)
    global b
    b= np.append(b,[[emg[0],emg[1],emg[2],emg[3],emg[4],emg[5],emg[6],emg[7]]],0)
    if b.shape[0]==512:
        final(b)

so the problem of slowness was because of using EMG_Filtered instead of EMG_RAW Further more when I use Filtered_EMG i got 8 column of data in each frame like this :: f But when i use RAW_EMG i get 2 sets of frames at a time ,, Do you know what is this for ?? @Girum ff

Girum commented 6 years ago

@hananabilabd hmm, great. We do something like this, but with some "sleep" to measure the time between receive The data and make The calculus.

About your question... The base between myo_raw and open_myo maybe The same... So, the Myo, receive 2 arrays with 8 values at time. Its your "protocol", because BLE is not very speedy. Them, in the 4 characteristcs, you receive 16 values, separated in two arrays. If You open The main code, you'll see it catchs The Value and split in these 2 arrays.

Characteristc 0: 16 values Characteristic 1: 16 values Characteristic 2: 16 values Characteristic 3: 16 values

In the Filtered, for some reason we didnt realize, it receive the 8 bit.... We think that, for a complete signal, oncoe you have to pass for the 4 Characteristic, you have to save all of them, which means 64 values. The Filtered maybe sim the values, and, of course, apply some Value to filter.

Girum commented 6 years ago

Here, you have all the BLE code to catch The values. But... Some commands are different in the modules (dont know why).

https://github.com/thalmiclabs/myo-bluetooth/blob/master/myohw.h

hananabilabd commented 6 years ago

Thanks I have a little Question for you ,, when using MYO-Classifier with this configuration classifier mode on open_myo

and i run code ,, it gives me waiting .. waiting ,, and don't get the (process_classifier) notification ,, except for one time which Ran correctly ,, Can you guess where may be the problem where ?it sometimes works ,, but most of the time with this configuration gives me waiting

and what's the difference between RAW and RAW_UNFILT in Classifier mode b

Girum commented 6 years ago

Hi. I have't test the classifier, because I'm making my own neural network to classify the positions. But, some problems (even in the emg handler) was of time of use the functions. After some time, it disconnects. One solution (poor) that I made is to, after the whole process, after you make the calculus, etc, activate the sleepMode function. It works for me 90% the times.

About the RAW_UNFILT, weel, i don't know the difference too. But, I ever used the RAW (0x02). If I'm not wrong, the lib was written after the Myo releases the link I gave you. So the commands differ (and it's a thing that I'm investigating...).

I used the BLE code, because, after the first attempt in C++ in Windows, I mande a Android App to catch these values, and use that link...

Girum commented 6 years ago

It seens that RAW is filtered for 60Hz, and UNFILT is the most RAW value. Consider so use the RAW and not RAW_UNFILT

hananabilabd commented 6 years ago

Hi Thanks so you are saying that RAW is filtered at 60 HZ and RAW_UNFILT is not filtered at all , Right ? another thing if you are making your "" own neural network to classify the positions"" Can you still share these codes on Github :D because we also had made classifier to detect 5 movements Regards

Girum commented 6 years ago

Yes! Thats right. About the code its a WIP project haha. As soon I made more resultados, Im going to share the code (when it works correctly)

hananabilabd commented 6 years ago

Hello Mr @Girum

how can i disconnect the MYO i tried both

myo_device.services.sleep_mode(0) 
myo_device.services.sleep_mode(2) 

but with no success

Girum commented 6 years ago

Hello! Well, I havent try to diwconnect myo... Since, it has no function for that. You can only power off or set the sleep Mode to 0 (myo disconnects after a time of inactivity) or 1 (myo never sleeps.) Maybe, to disconnect, you have to end the program, or something like make null the myo_device (but, dont forget to do a conditional, since the others functions depends on it)

hananabilabd commented 6 years ago

@Girum Thanks i successfully found the disconnect function in btle.py another Question did you try to operate Open-MYO on the generic Bluetooth of a laptop , not the bluetooth of Raspberry ?

Girum commented 6 years ago

Good! The btle function is much bigger. I'm investigate that right now for the speed of ble receives. By the way, I used the ble directly in the PC, but with another tools, like a NodeJS module for ble (noble). For windows, I had buy a ble 4.0 dongle and substitute the driver with the program Zadig (because with the "default" driver, it doesnt works). I used too with the Android, using the Myohw.h that I post previously.

hananabilabd commented 6 years ago

but what if i wanna use the MYO_usb Dongle on linux , with Open_myo Is it even possible ?

Girum commented 6 years ago

Hmm, I Think it is, since the lib Was made for Linux. I never tried. If you try, ler me know =). I didnt try yet because I want to embed the code

Alvipe commented 6 years ago

@hananabilabd, of course you can use the Open Myo module in a Linux laptop/PC (that was the idea). However, it does not work with the Bluetooth dongle included with the Myo armband, as this dongle does not use the Bluetooth 4.0 protocol as it is, but a proprietary protocol made by the dongle manufacturer (Bluegiga). You will need a generic BTLE antenna, such as this one.

hananabilabd commented 6 years ago

@Alvipe Thanks but can it still work with Generic bluetooth of my Laptop like this ? v

Alvipe commented 6 years ago

@hananabilabd, if it's a BTLE (Bluetooth 4) antenna, it will probably work. The best way of confirming it is by testing it yourself.

Girum commented 6 years ago

@hananabilabd Since your BLE is 4.0, até least in Windows, I have to use the Zadig https://zadig.akeo.ie/. Once you change the ble driver for the WinUSB it will work. In Linux, it will automatically

hananabilabd commented 6 years ago

So you are saying you make Open Myo work on windows , Right @Girum ?

Girum commented 6 years ago

No... I said that because you show the Windows device manager. Open Myo works only in Linux