Giter VIP home page Giter VIP logo

myo-python's Introduction

Announcements

[Oct 15, 2018] Thalmic Labs have announced the discontinuation of the Myo armband. Software that used to be accessible on the Thalmic downloads page can be found on the GitHub releases page.

[Jun 28, 2018] Myo-Python 1.0 has been released. It comes with a number of API changes. If you have been following an older tutorial, you might have the new version installed but use code that worked with the old version.
Check the Migrating from v0.2.x section below.


Python bindings for the Myo SDK

Myo-Python is a CFFI wrapper for the Thalmic Myo SDK.

Table of Contents

Documentation

The documentation can currently be found in the docs/ directory in the GitHub Repository.

Example

Myo-Python mirrors the usage of the Myo C++ SDK in many ways as it also requires you to implement a DeviceListener that will then be invoked for any events received from a Myo device.

import myo

class Listener(myo.DeviceListener):
  def on_paired(self, event):
    print("Hello, {}!".format(event.device_name))
    event.device.vibrate(myo.VibrationType.short)
  def on_unpaired(self, event):
    return False  # Stop the hub
  def on_orientation(self, event):
    orientation = event.orientation
    acceleration = event.acceleration
    gyroscope = event.gyroscope
    # ... do something with that

if __name__ == '__main__':
  myo.init(sdk_path='./myo-sdk-win-0.9.0/')
  hub = myo.Hub()
  listener = Listener()
  while hub.run(listener.on_event, 500):
    pass

As an alternative to implementing a custom device listener, you can instead use the myo.ApiDeviceListener class which allows you to read the most recent state of one or multiple Myo devices.

import myo
import time

def main():
  myo.init(sdk_path='./myo-sdk-win-0.9.0/')
  hub = myo.Hub()
  listener = myo.ApiDeviceListener()
  with hub.run_in_background(listener.on_event):
    print("Waiting for a Myo to connect ...")
    device = listener.wait_for_single_device(2)
    if not device:
      print("No Myo connected after 2 seconds.")
      return
    print("Hello, Myo! Requesting RSSI ...")
    device.request_rssi()
    while hub.running and device.connected and not device.rssi:
      print("Waiting for RRSI...")
      time.sleep(0.001)
    print("RSSI:", device.rssi)
    print("Goodbye, Myo!")

Migrating from v0.2.x

The v0.2.x series of the Myo-Python library used ctypes and has a little bit different API. The most important changes are:

  • The Hub object no longer needs to be shut down explicitly
  • The DeviceListener method names changed to match the exact event name as specified by the Myo SDK (eg. from on_pair() to on_paired())
  • Hub.run(): The order of arguments is reversed (handler, duration_ms instead of duration_ms, handler)
  • myo.init(): Provides a few more parameters to control the way libmyo is detected.
  • myo.Feed: Renamed to myo.ApiDeviceListener

Projects using Myo-Python

Changes

v1.0.4 (2019-04-29)

  • Remove myo.quaternion, it was a leftover and the Quaternion class was actually in myo.types.math
  • move myo.types.math and myo.types.macaddr to myo package instead
  • myo.types package is now a stub for backwards compatibility
  • Depend on enum34 package instead of nr.types.enum which has been removed in nr.types>=2.0.0
  • Update the error message of a ValueError raised in myo.init()

v1.0.3 (2018-06-28)

  • Event.mac_address now returns None if the event's type is EventType.emg (#62)
  • Hub.run() now accepts DeviceListener objects for its handler parameter. This carries over to Hub.run_forever() and Hub.run_in_background().
  • Replace requirement nr>=2.0.10,<3 in favor of nr.types>=1.0.3

v1.0.2 (2018-06-09)

  • Fix Event.warmup_result (PR #58 @fribeiro1)

v1.0.1 (2018-06-09)

  • Fix Event.rotation_on_arm (#59)

v1.0.0 (2018-06-03)

  • Rewrite using CFFI

This project is licensed under the MIT License.
Copyright © 2015-2018 Niklas Rosenstein

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.