Esempio n. 1
0
 def __init__(self, low_myo, timestamp, firmware_version):
     super(Feed.MyoProxy, self).__init__()
     self.synchronized = threading.Condition()
     self._pair_time = timestamp
     self._unpair_time = None
     self._connect_time = None
     self._disconnect_time = None
     self._myo = low_myo
     self._emg = None
     self._orientation = Quaternion.identity()
     self._acceleration = Vector(0, 0, 0)
     self._gyroscope = Vector(0, 0, 0)
     self._pose = Pose.rest
     self._arm = None
     self._xdir = None
     self._rssi = None
     self._firmware_version = firmware_version
Esempio n. 2
0
 def __init__(self, low_myo, timestamp, firmware_version):
     super(Feed.MyoProxy, self).__init__()
     self.synchronized = threading.Condition()
     self._pair_time = timestamp
     self._unpair_time = None
     self._connect_time = None
     self._disconnect_time = None
     self._myo = low_myo
     self._emg = None
     self._orientation = Quaternion.identity()
     self._acceleration = Vector(0, 0, 0)
     self._gyroscope = Vector(0, 0, 0)
     self._pose = Pose.rest
     self._arm = None
     self._xdir = None
     self._rssi = None
     self._firmware_version = firmware_version
Esempio n. 3
0
    def gyroscope(self):
        """
        gyroscope -> Vector

        Returns the gyroscope :class:`myo.vector.Vector` for this
        event. Can only be called from the *orientation* event.
        """

        self._checktype('get gyroscope', enums.EventType.orientation)
        return Vector(lib.event_get_gyroscope(self, 0),
                      lib.event_get_gyroscope(self, 1),
                      lib.event_get_gyroscope(self, 2))
Esempio n. 4
0
    def acceleration(self):
        """
        acceleration -> Vector

        Returns the acceleration :class:`myo.vector.Vector` for this
        event. Can only be called from the *orientation* event.
        """

        self._checktype('get acceleration', enums.EventType.orientation)
        return Vector(lib.event_get_accelerometer(self, 0),
                      lib.event_get_accelerometer(self, 1),
                      lib.event_get_accelerometer(self, 2))
Esempio n. 5
0
 def __init__(self, low_myo, timestamp, firmware_version):
     super(DataCaptureListener.MyoProxy, self).__init__()
     self.synchronized = threading.Condition()
     self._pair_time = timestamp
     self._unpair_time = None
     self._connect_time = None
     self._disconnect_time = None
     self._locked = False
     self._emg_enabled = False
     self._myo = low_myo
     self._emg = None
     self._orientation = Quaternion.identity()
     self._acceleration = Vector(0, 0, 0)
     self._gyroscope = Vector(0, 0, 0)
     self._pose = Pose.rest
     self._arm = None
     self._xdir = None
     self._rssi = None
     self._battery_level = None
     self._locking_policy = libmyo.LockingPolicy.standard
     self._firmware_version = firmware_version
Esempio n. 6
0
    def rotation_of(source, dest):
        """
        Returns a :class:`Quaternion` that represents a rotation from
        vector *source* to *dest*.

        :param source: A vector object.
        :param dest: A vector object.
        :return: :class:`Quaternion`
        """

        source = Vector(source.x, source.y, source.z)
        dest = Vector(dest.x, dest.y, dest.z)
        cross = source.cross(dest)
        cos_theta = source.dot(dest)

        # Return identity if the vectors are the same direction.
        if cos_theta >= 1.0:
            return Quaternion.identity()

        # Product of the square of the magnitudes.
        k = math.sqrt(source.dot(source), dest.dot(dest))

        # Return identity in the degenerate case.
        if k <= 0.0:
            return Quaternion.identity()

        # Special handling for vectors facing opposite directions.
        if cos_theta / k <= -1:
            x_axis = Vector(1, 0, 0)
            y_axis = Vector(0, 1, 1)
            if abs(source.dot(x_ais)) < 1.0:
                cross = source.cross(x_axis)
            else:
                cross = source.cross(y_axis)

        return Quaternion(cross.x, cross.y, cross.z, k + cos_theta)
Esempio n. 7
0
    def rotation_of(source, dest):
        """
        Returns a :class:`Quaternion` that represents a rotation from
        vector *source* to *dest*.

        :param source: A vector object.
        :param dest: A vector object.
        :return: :class:`Quaternion`
        """

        source = Vector(source.x, source.y, source.z)
        dest = Vector(dest.x, dest.y, dest.z)
        cross = source.cross(dest)
        cos_theta = source.dot(dest)

        # Return identity if the vectors are the same direction.
        if cos_theta >= 1.0:
            return Quaternion.identity()

        # Product of the square of the magnitudes.
        k = math.sqrt(source.dot(source), dest.dot(dest))

        # Return identity in the degenerate case.
        if k <= 0.0:
            return Quaternion.identity()

        # Special handling for vectors facing opposite directions.
        if cos_theta / k <= -1:
            x_axis = Vector(1, 0, 0)
            y_axis = Vector(0, 1, 1)
            if abs(source.dot(x_ais)) < 1.0:
                cross = source.cross(x_axis)
            else:
                cross = source.cross(y_axis)

        return Quaternion(cross.x, cross.y, cross.z, k + cos_theta)
Esempio n. 8
0
    class MyoProxy(object):

        __slots__ = (
            'synchronized,_pair_time,_unpair_time,_connect_time,'
            '_disconnect_time,_myo,_emg,_orientation,_acceleration,'
            '_gyroscope,_pose,_arm,_xdir,_rssi,_firmware_version').split(',')

        def __init__(self, low_myo, timestamp, firmware_version):
            super(Feed.MyoProxy, self).__init__()
            self.synchronized = threading.Condition()
            self._pair_time = timestamp
            self._unpair_time = None
            self._connect_time = None
            self._disconnect_time = None
            self._myo = low_myo
            self._emg = None
            self._orientation = Quaternion.identity()
            self._acceleration = Vector(0, 0, 0)
            self._gyroscope = Vector(0, 0, 0)
            self._pose = Pose.rest
            self._arm = None
            self._xdir = None
            self._rssi = None
            self._firmware_version = firmware_version

        def __repr__(self):
            result = '<MyoProxy ('
            with self.synchronized:
                if self.connected:
                    result += 'connected) at 0x{0:x}>'.format(self._myo.value)
                else:
                    result += 'disconnected)>'
            return result

        def __assert_connected(self):
            if not self.connected:
                raise RuntimeError('Myo was disconnected')

        @property
        def connected(self):
            with self.synchronized:
                return (self._connect_time is not None
                        and self._disconnect_time is None)

        @property
        def paired(self):
            with self.synchronized:
                return (self.myo_ is None or self._unpair_time is not None)

        @property
        def pair_time(self):
            return self._pair_time

        @property
        def unpair_time(self):
            with self.synchronized:
                return self._unpair_time

        @property
        def connect_time(self):
            return self._connect_time

        @property
        def disconnect_time(self):
            with self.synchronized:
                return self._disconnect_time

        @property
        def firmware_version(self):
            return self._firmware_version

        @property
        def orientation(self):
            with self.synchronized:
                return self._orientation.copy()

        @property
        def acceleration(self):
            with self.synchronized:
                return self._acceleration.copy()

        @property
        def gyroscope(self):
            with self.synchronized:
                return self._gyroscope.copy()

        @property
        def pose(self):
            with self.synchronized:
                return self._pose

        @property
        def arm(self):
            with self.synchronized:
                return self._arm

        @property
        def x_direction(self):
            with self.synchronized:
                return self._xdir

        @property
        def rssi(self):
            with self.synchronized:
                return self._rssi

        def set_locking_policy(self, locking_policy):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_locking_policy(locking_policy)

        def set_stream_emg(self, emg):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_stream_emg(emg)

        def vibrate(self, vibration_type):
            with self.synchronized:
                self.__assert_connected()
                self._myo.vibrate(vibration_type)

        def request_rssi(self):
            """
            Requests the RSSI of the Myo armband. Until the RSSI is
            retrieved, :attr:`rssi` returns None.
            """

            with self.synchronized:
                self.__assert_connected()
                self._rssi = None
                self._myo.request_rssi()
Esempio n. 9
0
    class MyoProxy(object):

        __slots__ = (
            'synchronized,_pair_time,_unpair_time,_connect_time,'
            '_disconnect_time,_myo,_emg,_orientation,_acceleration,'
            '_gyroscope,_pose,_arm,_xdir,_rssi,_firmware_version').split(',')

        def __init__(self, low_myo, timestamp, firmware_version):
            super(Feed.MyoProxy, self).__init__()
            self.synchronized = threading.Condition()
            self._pair_time = timestamp
            self._unpair_time = None
            self._connect_time = None
            self._disconnect_time = None
            self._myo = low_myo
            self._emg = None
            self._orientation = Quaternion.identity()
            self._acceleration = Vector(0, 0, 0)
            self._gyroscope = Vector(0, 0, 0)
            self._pose = Pose.rest
            self._arm = None
            self._xdir = None
            self._rssi = None
            self._firmware_version = firmware_version

        def __repr__(self):
            result = '<MyoProxy ('
            with self.synchronized:
                if self.connected:
                    result += 'connected) at 0x{0:x}>'.format(self._myo.value)
                else:
                    result += 'disconnected)>'
            return result

        def __assert_connected(self):
            if not self.connected:
                raise RuntimeError('Myo was disconnected')

        @property
        def connected(self):
            with self.synchronized:
                return (
                    self._connect_time is not None and
                    self._disconnect_time is None
                )

        @property
        def paired(self):
            with self.synchronized:
                return (self.myo_ is None or self._unpair_time is not None)

        @property
        def pair_time(self):
            return self._pair_time

        @property
        def unpair_time(self):
            with self.synchronized:
                return self._unpair_time

        @property
        def connect_time(self):
            return self._connect_time

        @property
        def disconnect_time(self):
            with self.synchronized:
                return self._disconnect_time

        @property
        def firmware_version(self):
            return self._firmware_version

        @property
        def orientation(self):
            with self.synchronized:
                return self._orientation.copy()

        @property
        def acceleration(self):
            with self.synchronized:
                return self._acceleration.copy()

        @property
        def gyroscope(self):
            with self.synchronized:
                return self._gyroscope.copy()

        @property
        def pose(self):
            with self.synchronized:
                return self._pose

        @property
        def arm(self):
            with self.synchronized:
                return self._arm

        @property
        def x_direction(self):
            with self.synchronized:
                return self._xdir

        @property
        def rssi(self):
            with self.synchronized:
                return self._rssi

        def set_locking_policy(self, locking_policy):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_locking_policy(locking_policy)

        def set_stream_emg(self, emg):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_stream_emg(emg)

        def vibrate(self, vibration_type):
            with self.synchronized:
                self.__assert_connected()
                self._myo.vibrate(vibration_type)

        def request_rssi(self):
            """
            Requests the RSSI of the Myo armband. Until the RSSI is
            retrieved, :attr:`rssi` returns None.
            """

            with self.synchronized:
                self.__assert_connected()
                self._rssi = None
                self._myo.request_rssi()
Esempio n. 10
0
    class MyoProxy(object):

        __slots__ = (
            "synchronized,_pair_time,_unpair_time,_connect_time,"
            "_disconnect_time,_myo,_emg,_orientation,_acceleration,"
            "_gyroscope,_pose,_arm,_xdir,_rssi,_firmware_version,"
            "_locked,_emg_enabled,_battery_level,_locking_policy"
        ).split(",")

        def __init__(self, low_myo, timestamp, firmware_version):
            super(DataCaptureListener.MyoProxy, self).__init__()
            self.synchronized = threading.Condition()
            self._pair_time = timestamp
            self._unpair_time = None
            self._connect_time = None
            self._disconnect_time = None
            self._locked = False
            self._emg_enabled = False
            self._myo = low_myo
            self._emg = None
            self._orientation = Quaternion.identity()
            self._acceleration = Vector(0, 0, 0)
            self._gyroscope = Vector(0, 0, 0)
            self._pose = Pose.rest
            self._arm = None
            self._xdir = None
            self._rssi = None
            self._battery_level = None
            self._locking_policy = libmyo.LockingPolicy.standard
            self._firmware_version = firmware_version

        def __repr__(self):
            result = "<MyoProxy ("
            with self.synchronized:
                if self.connected:
                    result += "connected) at 0x{0:x}>".format(self._myo.value)
                else:
                    result += "disconnected)>"
            return result

        def __assert_connected(self):
            if not self.connected:
                raise RuntimeError("Myo was disconnected")

        @property
        def connected(self):
            with self.synchronized:
                return self._connect_time is not None and self._disconnect_time is None

        @property
        def paired(self):
            with self.synchronized:
                return self.myo_ is None or self._unpair_time is not None

        @property
        def pair_time(self):
            return self._pair_time

        @property
        def unpair_time(self):
            with self.synchronized:
                return self._unpair_time

        @property
        def connect_time(self):
            return self._connect_time

        @property
        def disconnect_time(self):
            with self.synchronized:
                return self._disconnect_time

        @property
        def firmware_version(self):
            return self._firmware_version

        @property
        def orientation(self):
            with self.synchronized:
                return self._orientation.copy()

        @property
        def acceleration(self):
            with self.synchronized:
                return self._acceleration.copy()

        @property
        def gyroscope(self):
            with self.synchronized:
                return self._gyroscope.copy()

        @property
        def pose(self):
            with self.synchronized:
                return self._pose

        @property
        def arm(self):
            with self.synchronized:
                return self._arm

        @property
        def x_direction(self):
            with self.synchronized:
                return self._xdir

        @property
        def rssi(self):
            with self.synchronized:
                return self._rssi

        @property
        def locked(self):
            with self.synchronized:
                return self._locked

        @property
        def emg_enabled(self):
            with self.synchronized:
                return self._emg_enabled

        @property
        def battery_level(self):
            with self.synchronized:
                return self._battery_level

        @property
        def locking_policy(self):
            with self.synchronized:
                return self._locking_policy

        def set_locking_policy(self, locking_policy):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_locking_policy(locking_policy)
                self._locking_policy = locking_policy

        def set_stream_emg(self, emg):
            with self.synchronized:
                self.__assert_connected()
                self._myo.set_stream_emg(emg)
                if emg == libmyo.StreamEmg.enabled:
                    self._emg_enabled = True
                else:
                    self._emg_enabled = False
                    self._emg = None

        def enable_emg_streaming(self):
            self.set_stream_emg(libmyo.StreamEmg.enabled)

        def disble_emg_streaming(self):
            self.set_stream_emg(libmyo.StreamEmg.disabled)

        def vibrate(self, vibration_type):
            with self.synchronized:
                self.__assert_connected()
                self._myo.vibrate(vibration_type)

        def request_rssi(self):
            """
            Requests the RSSI of the Myo armband. Until the RSSI is
            retrieved, :attr:`rssi` returns None.
            """
            with self.synchronized:
                self.__assert_connected()
                self._rssi = None
                self._myo.request_rssi()

        def request_battery_level(self):
            """
            Requests the battery level of the Myo armband. Until the RSSI is
            retrieved, :attr:`battery_level` returns None.
            """
            with self.synchronized:
                self.__assert_connected()
                self._battery_level = None
                self._myo.request_battery_level()