This repository has been archived by the owner on Apr 5, 2021. It is now read-only.
forked from Alvipe/Open-Myo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (51 loc) · 1.98 KB
/
main.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
# Copyright 2018 Alvaro Villoslada (Alvipe)
# This file is part of Open Myo.
# Open Myo is distributed under a GPL 3.0 license
import open_myo as myo
def process_emg(emg):
print(emg)
def process_imu(quat, acc, gyro):
print(quat)
def process_sync(arm, x_direction):
print(arm, x_direction)
def process_classifier(pose):
print(pose)
def process_battery(batt):
print("Battery level: %d" % batt)
def led_emg(emg):
"""Sets the LED to be red over a certain threshold, otherwise it is set to purple."""
if(emg[0] > 80):
myo_device.services.set_leds([255, 0, 0], [128, 128, 255])
else:
myo_device.services.set_leds([128, 128, 255], [128, 128, 255])
# assign the device to a var. get the MAC address first!
myo_mac_addr = myo.get_myo()
myo_device = myo.Device()
# print developer information to console.
print("MAC address: %s" % myo_mac_addr)
fw = myo_device.services.firmware()
print("Firmware version: %d.%d.%d.%d" % (fw[0], fw[1], fw[2], fw[3]))
print("Battery level: %d" % myo_device.services.battery())
# never sleep.
myo_device.services.sleep_mode(1)
# set logo & bar LED color to purple.
myo_device.services.set_leds([128, 128, 255], [128, 128, 255])
# short vibration.
myo_device.services.vibrate(1)
# define which services we wish to subscribe to.
myo_device.services.battery_notifications()
# myo_device.services.classifier_notifications()
myo_device.services.emg_filt_notifications()
# myo_device.services.emg_raw_notifications()
# myo_device.services.imu_notifications()
myo_device.services.set_mode(myo.EmgMode.FILT, myo.ImuMode.ALL, myo.ClassifierMode.OFF)
myo_device.add_emg_event_handler(process_emg)
myo_device.add_emg_event_handler(led_emg)
# myo_device.add_imu_event_handler(process_imu)
myo_device.add_sync_event_handler(process_sync)
# myo_device.add_classifier_event_handler(process_classifier)
# main program loop. await service notifications.
while True:
if myo_device.services.waitForNotifications(1):
continue
print("Waiting...")