internal void HandleEvent(libmyo.EventType type, DateTime timestamp, IntPtr evt) { switch (type) { case libmyo.EventType.Connected: if (Connected != null) { Connected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Disconnected: if (Disconnected != null) { Disconnected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.ArmSynced: if (ArmSynced != null) { Arm arm = (Arm)libmyo.event_get_arm(evt); XDirection xDirection = (XDirection)libmyo.event_get_x_direction(evt); ArmSynced(this, new ArmSyncedEventArgs(this, timestamp, arm, xDirection)); } break; case libmyo.EventType.ArmUnsynced: if (ArmUnsynced != null) { ArmUnsynced(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Orientation: if (AccelerometerData != null) { float x = libmyo.event_get_accelerometer(evt, 0); float y = libmyo.event_get_accelerometer(evt, 1); float z = libmyo.event_get_accelerometer(evt, 2); var accelerometer = new Vector3(x, y, z); AccelerometerData(this, new AccelerometerDataEventArgs(this, timestamp, accelerometer)); } if (GyroscopeData != null) { float x = libmyo.event_get_gyroscope(evt, 0); float y = libmyo.event_get_gyroscope(evt, 1); float z = libmyo.event_get_gyroscope(evt, 2); var gyroscope = new Vector3(x, y, z); GyroscopeData(this, new GyroscopeDataEventArgs(this, timestamp, gyroscope)); } if (OrientationData != null) { float x = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.X); float y = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Y); float z = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Z); float w = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.W); var orientation = new Quaternion(x, y, z, w); OrientationData(this, new OrientationDataEventArgs(this, timestamp, orientation)); } break; case libmyo.EventType.Pose: if (PoseChange != null) { var pose = (Pose)libmyo.event_get_pose(evt); PoseChange(this, new PoseEventArgs(this, timestamp, pose)); } break; case libmyo.EventType.Rssi: if (Rssi != null) { var rssi = libmyo.event_get_rssi(evt); Rssi(this, new RssiEventArgs(this, timestamp, rssi)); } break; case libmyo.EventType.Unlocked: if (Unlocked != null) { Unlocked(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Locked: if (Locked != null) { Locked(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Emg: Dictionary<int, sbyte> emgData = new Dictionary<int, sbyte>(); for(int i = 0; i < 8;i++) { emgData[i] = libmyo.event_get_emg(evt, (uint)i); } if (Emg != null) { Emg(this, new EmgEventArgs(this, timestamp, emgData)); } break; } }
internal void HandleEvent(libmyo.EventType type, DateTime timestamp, IntPtr evt) { bool outputEmgData = false; switch (type) { case libmyo.EventType.Connected: if (Connected != null) { Connected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Disconnected: if (Disconnected != null) { Disconnected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.ArmSynced: if (ArmSynced != null) { Arm arm = (Arm)libmyo.event_get_arm(evt); XDirection xDirection = (XDirection)libmyo.event_get_x_direction(evt); ArmSynced(this, new ArmSyncedEventArgs(this, timestamp, arm, xDirection)); } break; case libmyo.EventType.ArmUnsynced: if (ArmUnsynced != null) { ArmUnsynced(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Orientation: if (AccelerometerData != null) { float x = libmyo.event_get_accelerometer(evt, 0); float y = libmyo.event_get_accelerometer(evt, 1); float z = libmyo.event_get_accelerometer(evt, 2); var accelerometer = new Vector3(x, y, z); AccelerometerData(this, new AccelerometerDataEventArgs(this, timestamp, accelerometer)); } if (GyroscopeData != null) { float x = libmyo.event_get_gyroscope(evt, 0); float y = libmyo.event_get_gyroscope(evt, 1); float z = libmyo.event_get_gyroscope(evt, 2); var gyroscope = new Vector3(x, y, z); GyroscopeData(this, new GyroscopeDataEventArgs(this, timestamp, gyroscope)); } if (OrientationData != null) { float x = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.X); float y = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Y); float z = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Z); float w = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.W); var orientation = new Quaternion(x, y, z, w); OrientationData(this, new OrientationDataEventArgs(this, timestamp, orientation)); } break; case libmyo.EventType.Pose: if (PoseChange != null) { var pose = (Pose)libmyo.event_get_pose(evt); PoseChange(this, new PoseEventArgs(this, timestamp, pose)); } break; case libmyo.EventType.Rssi: if (Rssi != null) { var rssi = libmyo.event_get_rssi(evt); Rssi(this, new RssiEventArgs(this, timestamp, rssi)); } break; case libmyo.EventType.Emg: outputEmgData = true; SetEmgData(evt, timestamp); break; case libmyo.EventType.Unlocked: if (Unlocked != null) { Unlocked(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Locked: if (Locked != null) { Locked(this, new MyoEventArgs(this, timestamp)); } break; } if (!outputEmgData && streamEmg) { SetEmgData(evt, timestamp); } }
public static Vector3 operator *(Quaternion quat, Vector3 vec) { var qvec = new Quaternion(vec.X, vec.Y, vec.Z, 0); var result = quat * qvec * quat.Conjugate(); return new Vector3(result.X, result.Y, result.Z); }
// // TODO compound arithmetic operators // public static Quaternion Normalize(Quaternion quat) { return (quat / quat.Magnitude()); }
/// Calculate the pitch angle represented by the given unit Quaternion. public static float Pitch(Quaternion quat) { return (float)Math.Asin(2.0f * (quat._w * quat._y - quat._z * quat._x)); }
/// Calculate the yaw angle represented by the given unit Quaternion. public static float Yaw(Quaternion quat) { return (float)Math.Atan2(2.0f * (quat._w * quat._z + quat._x * quat._y), 1.0f - 2.0f * (quat._y * quat._y + quat._z * quat._z)); }
/// Calculate the roll angle represented by the given unit Quaternion. public static float Roll(Quaternion quat) { return (float)Math.Atan2(2.0f * (quat._w * quat._x + quat._y * quat._z), 1.0f - 2.0f * (quat._x * quat._x + quat._y * quat._y)); }
void myo_OnOrientationData(object sender, Thalmic.Myo.OrientationDataEventArgs e) { lock (_lock) { _myoQuaternion = e.Orientation; } }
public OrientationDataEventArgs(Myo myo, DateTime timestamp, Quaternion orientation) : base(myo, timestamp) { this.Orientation = orientation; }
internal void HandleEvent(libmyo.EventType type, DateTime timestamp, IntPtr evt) { switch (type) { case libmyo.EventType.Connected: if (Connected != null) { Connected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Disconnected: if (Disconnected != null) { Disconnected(this, new MyoEventArgs(this, timestamp)); } break; case libmyo.EventType.Orientation: if (AccelerometerData != null) { float x = libmyo.event_get_accelerometer(evt, 0); float y = libmyo.event_get_accelerometer(evt, 1); float z = libmyo.event_get_accelerometer(evt, 2); var accelerometer = new Vector3(x, y, z); AccelerometerData(this, new AccelerometerDataEventArgs(this, timestamp, accelerometer)); } if (GyroscopeData != null) { float x = libmyo.event_get_gyroscope(evt, 0); float y = libmyo.event_get_gyroscope(evt, 1); float z = libmyo.event_get_gyroscope(evt, 2); var gyroscope = new Vector3(x, y, z); GyroscopeData(this, new GyroscopeDataEventArgs(this, timestamp, gyroscope)); } if (OrientationData != null) { float x = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.X); float y = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Y); float z = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.Z); float w = libmyo.event_get_orientation(evt, libmyo.OrientationIndex.W); var orientation = new Quaternion(x, y, z, w); OrientationData(this, new OrientationDataEventArgs(this, timestamp, orientation)); } break; case libmyo.EventType.Pose: if (PoseChange != null) { var pose = (Pose)libmyo.event_get_pose(evt); PoseChange(this, new PoseEventArgs(this, timestamp, pose)); } break; case libmyo.EventType.Rssi: if (Rssi != null) { var rssi = libmyo.event_get_rssi(evt); Rssi(this, new RssiEventArgs(this, timestamp, rssi)); } break; } }
public OrientationDataEventArgs(Myo myo, DateTime timestamp, Quaternion orientation) : base(myo, timestamp) { this.Orientation = orientation; }