class myo.Hub

High-level interface for the Myo Hub which manages data processing and event triggering for a Myo device.

Note

There can only be one Hub instance. The constructor of the Hub class will return the existing instance if it has not been shut down since then.

clear_exception()

If an exception is set, the Hub can not be re-run. This method will clear the stored exception if there is any.

exception

Set when an exception occured within the listener. The Hub can not be re-run if this is set. Use clear_exception() to remove the exception from the Hub.

join(timeout=None)

If the Hub was run with a thread, it can be joined (waiting blocked) with this method. If the Hub was not started within a thread, this method will do nothing.

run(interval_ms, listener, lil_sleep=0.01)

Run the Hub with an execution interval of interval_ms and the specified listener until the Hub was stopped. This method does not block the main thread. Returns the thread object that was created.

The Hub and its thread will stop as soon as stop() was called or the DeviceListener returns False from one of its callback methods.

lil_sleep specifies a number of seconds to sleep after the Hub has been started. This will allow the Hub thread to start before anything else is called.

run_once(duration_ms, listener)

Run listener for duration_ms seconds.

running
Returns:True if the Hub is running, False if not.
set_locking_policy(locking_policy)

Sets the locking policy.

shutdown()

Shut the hub down. If the hub is still running, it will be stopped right where it is. Call it before the hub is being garbage collected, or a warning will be printed that it has not been called.

Do not call this method from a DeviceListener as it would cause the current thread to be joined which is not possible. Use stop() to request a stop.

stop(join=False)

Request the Stop of the Hub when it is running. When join is True, this function will block the current thread until the Hub is not running anymore.

stop_requested
Returns:True if the Hub has been stopped with a call to stop(), False if not. The Hub could still be running though.
stopped
Returns:True if the Hub has been stopped with a call to stop(), False if not. The Hub could still be running though.
class myo.DeviceListener

Interface for listening to data sent from a Myo device. Return False from one of its callback methods to instruct the Hub to stop processing.

The DeviceListener operates between the high and low level of the myo Python bindings. The myo object that is passed to callback methods is a myo.lowlevel.ctyping.Myo object.

on_accelerometor_data(myo, timestamp, acceleration)
on_arm_sync(myo, timestamp, arm, x_direction, rotation, warmup_state)
on_arm_unsync(myo, timestamp)
on_battery_level_received(myo, timestamp, level)
on_connect(myo, timestamp, firmware_version)
on_disconnect(myo, timestamp)
on_emg_data(myo, timestamp, emg)
on_event(kind, event)

Called before any of the event callbacks.

on_event_finished(kind, event)

Called after the respective event callbacks have been invoked. This method is always triggered, even if one of the callbacks requested the stop of the Hub.

on_gyroscope_data(myo, timestamp, gyroscope)
on_lock(myo, timestamp)
on_orientation_data(myo, timestamp, orientation)
on_pair(myo, timestamp, firmware_version)
on_pose(myo, timestamp, pose)
on_rssi(myo, timestamp, rssi)
on_unlock(myo, timestamp)
on_unpair(myo, timestamp)
on_warmup_completed(myo, timestamp, warmup_result)
class myo.Feed

This class implements the DeviceListener interface to collect all data and make it available to another thread on-demand.

import myo as libmyo
feed = libmyo.device_listener.Feed()
hub = libmyo.Hub()
hub.run(1000, feed)

try:
    while True:
        myos = feed.get_connected_devices()
        if myos:
            print myos[0], myos[0].orientation
        time.sleep(0.5)
finally:
    hub.stop(True)
    hub.shutdown()
class MyoProxy(low_myo, timestamp, firmware_version)
acceleration
arm
connect_time
connected
disconnect_time
emg
firmware_version
gyroscope
orientation
pair_time
paired
pose
request_rssi()

Requests the RSSI of the Myo armband. Until the RSSI is retrieved, rssi returns None.

rssi
set_locking_policy(locking_policy)
set_stream_emg(emg)
synchronized
unpair_time
vibrate(vibration_type)
x_direction
Feed.get_connected_devices(self) → list of Feed.MyoProxy

Returns a list of connected Myo’s.

Feed.get_devices() → list of Feed.MyoProxy

Returns a list of paired and connected Myo’s.

Feed.on_event(kind, event)
Feed.wait_for_single_device(timeout) → Feed.MyoProxy or None

Waits until a Myo is was paired and connected with the Hub and returns it. If the timeout is exceeded, returns None. This function will not return a Myo that is only paired but not connected.

Parameters:
  • timeout – The maximum time to wait for a device.
  • interval – The interval at which the function should exit sleeping. We can not sleep endlessly, otherwise the main thread can not be exit, eg. through a KeyboardInterrupt.