示例#1
0
 /// <summary>
 /// Method called upon receiving the even myodata received. It passes on the orientation data to the UpdateOrientation class in Mainwindow
 /// </summary>
 /// <param name="e"></param>
 public void CalculateAccelerometer(AccelerometerDataEventArgs e)
 {
     accelerometerX = e.Accelerometer.X / 5;
     accelerometerY = e.Accelerometer.Y / 5;
     accelerometerZ = e.Accelerometer.Z / 5;
     mWindow.UpdateAccelerometer(accelerometerX, accelerometerY, accelerometerZ);
 }
示例#2
0
        private void Myo_AccelerometerDataAcquired(object sender, AccelerometerDataEventArgs e)
        {
            //float fMulti = 10.0f;
            //m_CGrap.Push((int)Math.Round(e.Accelerometer.X * fMulti), (int)Math.Round(e.Accelerometer.Y * fMulti), (int)Math.Round(e.Accelerometer.Z * fMulti));
            if (m_anHandle[0] == e.Myo.Handle.ToInt32())
            {
                m_afAcc[0] = e.Accelerometer.X; // / 57.1f * 90.0f;
                m_afAcc[1] = e.Accelerometer.Y; // / 57.1f * 90.0f;
                m_afAcc[2] = e.Accelerometer.Z; /// 57.1f * 90.0f;
                if (m_CTIdAcc.Get() >= 200)
                {
                    m_CTIdAcc.Set();
                    float[] afAngle = new float[3];
                    afAngle[0] = (float)Ojw.CMath.R2D((double)m_afAcc[0]); //(float)Math.Atan(m_afAcc[0] / (float)Math.Sqrt(m_afAcc[1] * m_afAcc[1] + m_afAcc[2] * m_afAcc[2]));
                    afAngle[1] = (float)Ojw.CMath.R2D((double)m_afAcc[1]); //(float)Math.Atan(m_afAcc[1] / (float)Math.Sqrt(m_afAcc[2] * m_afAcc[2] + m_afAcc[0] * m_afAcc[0]));
                    afAngle[2] = (float)Ojw.CMath.R2D((double)m_afAcc[2]); //(float)Math.Atan(m_afAcc[2] / (float)Math.Sqrt(m_afAcc[0] * m_afAcc[0] + m_afAcc[1] * m_afAcc[1]));
                    Ojw.CMessage.Write("Acc : {0}, {1}, {2}", afAngle[0], afAngle[1], afAngle[2]);
                    a = afAngle[0];
                    b = afAngle[1];
                }
            }
#if false
            if (m_CTIdAcc.Get() >= 1000)
            {
                m_CTIdAcc.Set();
                float[] afAngle = new float[3];
                afAngle[0] = (float)Ojw.CMath.R2D((double)m_afAcc[0]); //(float)Math.Atan(m_afAcc[0] / (float)Math.Sqrt(m_afAcc[1] * m_afAcc[1] + m_afAcc[2] * m_afAcc[2]));
                afAngle[1] = (float)Ojw.CMath.R2D((double)m_afAcc[1]); //(float)Math.Atan(m_afAcc[1] / (float)Math.Sqrt(m_afAcc[2] * m_afAcc[2] + m_afAcc[0] * m_afAcc[0]));
                afAngle[2] = (float)Ojw.CMath.R2D((double)m_afAcc[2]); //(float)Math.Atan(m_afAcc[2] / (float)Math.Sqrt(m_afAcc[0] * m_afAcc[0] + m_afAcc[1] * m_afAcc[1]));
                Ojw.CMessage.Write("Acc : {0}, {1}, {2}", afAngle[0], afAngle[1], afAngle[2]);
            }
#endif
        }
示例#3
0
 private void AccelerometerDataAcquired(object sender, AccelerometerDataEventArgs e)
 {
     if (streamData == true)
     {
         Acc = /*DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + "," +*/ e.Accelerometer.X.ToString() + "," + e.Accelerometer.Y.ToString() + "," + e.Accelerometer.Z.ToString();
         Publish("/i5/myo/accelerometer", e.Accelerometer.X.ToString() + "," + e.Accelerometer.Y.ToString() + "," + e.Accelerometer.Z.ToString());
     }
 }
示例#4
0
文件: MyoTests.cs 项目: raphaelfp/pyo
        public void ChannelEventReceived_Orientation_TriggersAccelerationDataAcquiredEvent()
        {
            // Setup
            var routeEventArgs = new RouteMyoEventArgs(
                new IntPtr(123),
                new IntPtr(789),
                MyoEventType.Orientation,
                DateTime.UtcNow);

            var acceleration = new Vector3F(10, 20, 30);

            var channelListener = new Mock <IChannelListener>(MockBehavior.Strict);

            var myoDeviceDriver = new Mock <IMyoDeviceDriver>(MockBehavior.Strict);

            myoDeviceDriver
            .SetupGet(x => x.Handle)
            .Returns(new IntPtr(123));
            myoDeviceDriver
            .Setup(x => x.GetEventOrientation(routeEventArgs.Event))
            .Returns(new QuaternionF());
            myoDeviceDriver
            .Setup(x => x.GetEventAccelerometer(routeEventArgs.Event))
            .Returns(acceleration);
            myoDeviceDriver
            .Setup(x => x.GetGyroscope(routeEventArgs.Event))
            .Returns(new Vector3F());

            var myo = Myo.Create(
                channelListener.Object,
                myoDeviceDriver.Object);

            AccelerometerDataEventArgs actualEventArgs = null;
            object actualSender = null;

            myo.AccelerometerDataAcquired += (sender, args) =>
            {
                actualSender    = sender;
                actualEventArgs = args;
            };

            // Execute
            channelListener.Raise(
                x => x.EventReceived += null,
                routeEventArgs);

            // Assert
            Assert.Equal(myo, actualSender);
            Assert.Equal(myo, actualEventArgs.Myo);
            Assert.Equal(routeEventArgs.Timestamp, actualEventArgs.Timestamp);
            Assert.Equal(acceleration, actualEventArgs.Accelerometer);;

            myoDeviceDriver.VerifyGet(x => x.Handle, Times.Once);
            myoDeviceDriver.Verify(x => x.GetEventOrientation(routeEventArgs.Event), Times.Once);
            myoDeviceDriver.Verify(x => x.GetEventAccelerometer(routeEventArgs.Event), Times.Once);
            myoDeviceDriver.Verify(x => x.GetGyroscope(routeEventArgs.Event), Times.Once);
        }
示例#5
0
        public MyoData buildRecordUsing(DataCollector data, DateTime AGOStamp, DateTime EMGStamp)
        {
            AccelerometerDataEventArgs Acc  = data.accelerometerData.First(X => X.Timestamp == AGOStamp);
            EmgDataEventArgs           Emg  = data.emgData.First(X => X.Timestamp == EMGStamp);
            OrientationDataEventArgs   Ori  = data.orientationData.First(X => X.Timestamp == AGOStamp);
            GyroscopeDataEventArgs     Gyro = data.gyroscopeData.First(X => X.Timestamp == AGOStamp);

            return(buildRecordUsing(Emg, Acc, Gyro, Ori));
        }
示例#6
0
        private void Myo_AccelerometerDataAcquired(object sender, AccelerometerDataEventArgs a)
        {
            AccelerometerChangedEventArgs args = new AccelerometerChangedEventArgs();

            args.accelerometerMag = a.Accelerometer.Magnitude();
            args.accelerometerX   = a.Accelerometer.X;
            args.accelerometerY   = a.Accelerometer.Y;
            args.accelerometerZ   = a.Accelerometer.Z;
            OnAccelerometerChanged(args);
        }
示例#7
0
        private void Myo_AccelerometerAcquired(object sender, AccelerometerDataEventArgs e)
        {
            if (_isRecording == true)
            {
                if ((DateTime.Now - lastExecutionAccelerometer).TotalSeconds >= 0.5)
                {
                    CalculateAccelerometer(e);
                    if (MainWindow.isRecordingData == true)
                    {
                        SendData();
                    }

                    lastExecutionAccelerometer = DateTime.Now;
                }
            }
        }
        public void GetTimestamp_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var timestamp = DateTime.UtcNow;

            var args = new AccelerometerDataEventArgs(
                new Mock <IMyo>().Object,
                timestamp,
                new Vector3F());

            // Execute
            var result = args.Timestamp;

            // Assert
            Assert.Equal(timestamp, result);
        }
        public void GetMyo_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var myo = new Mock <IMyo>();

            var args = new AccelerometerDataEventArgs(
                myo.Object,
                DateTime.UtcNow,
                new Vector3F());

            // Execute
            var result = args.Myo;

            // Assert
            Assert.Equal(myo.Object, result);
        }
        public void GetAccelerometer_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var accelerometerData = new Vector3F(1, 2, 3);

            var args = new AccelerometerDataEventArgs(
                new Mock <IMyo>().Object,
                DateTime.UtcNow,
                accelerometerData);

            // Execute
            var result = args.Accelerometer;

            // Assert
            Assert.Equal(accelerometerData, result);
        }
示例#11
0
 public MyoData buildRecordUsing(EmgDataEventArgs Emg, AccelerometerDataEventArgs Acc, GyroscopeDataEventArgs Gyro, OrientationDataEventArgs Ori)
 {
     return(new MyoData()
     {
         Time_stamp = Acc.Timestamp,
         Acc_X = Acc.Accelerometer.X,
         Acc_Y = Acc.Accelerometer.Y,
         Acc_Z = Acc.Accelerometer.Z,
         Gyro_X = Gyro.Gyroscope.X,
         Gyro_Y = Gyro.Gyroscope.Y,
         Gyro_Z = Gyro.Gyroscope.Z,
         Ori_X = Ori.Orientation.X,
         Ori_Y = Ori.Orientation.Y,
         Ori_Z = Ori.Orientation.Z,
         Ori_W = Ori.Orientation.W,
         Emg_1 = Emg.EmgData.GetDataForSensor(0),
         Emg_2 = Emg.EmgData.GetDataForSensor(1),
         Emg_3 = Emg.EmgData.GetDataForSensor(2),
         Emg_4 = Emg.EmgData.GetDataForSensor(3),
         Emg_5 = Emg.EmgData.GetDataForSensor(4),
         Emg_6 = Emg.EmgData.GetDataForSensor(5),
         Emg_7 = Emg.EmgData.GetDataForSensor(6),
         Emg_8 = Emg.EmgData.GetDataForSensor(7),
         EmgMAV = 1.0d / 8.0d * (
             Math.Abs(Emg.EmgData.GetDataForSensor(0)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(1)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(2)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(3)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(4)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(5)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(6)) +
             Math.Abs(Emg.EmgData.GetDataForSensor(7))),
         Pitch = Ori.Pitch,
         Roll = Ori.Roll,
         Yaw = Ori.Yaw,
     });
 }
示例#12
0
文件: Pyo.cs 项目: raphaelfp/pyo
        private void Myo_AccelerometerDataAcquired(object sender, AccelerometerDataEventArgs e)
        {
            MethodInvoker inv = delegate { };

            this.Invoke(inv);
        }
示例#13
0
 void OnAccelerometerData(object sender, AccelerometerDataEventArgs e)
 {
     _myoState.Accel = e.Accelerometer;
 }
示例#14
0
		static void OnAccelerationDataAcquired(object sender, AccelerometerDataEventArgs e)
		{
			var args = new AccelerationChangedEventArgs(MyoDevice.AccelerationChangedEvent, sender, e.Myo, e.TimeStamp, e.Accelerometer);
			RaiseEvent(MyoDevice.AccelerationChangedEvent, args);
		}
示例#15
0
        private void Myo_AccelerometerDataAcquired(object sender, AccelerometerDataEventArgs e)
        {
            MethodInvoker inv = delegate { this.label6.Text = $"X: {e.Accelerometer.X} | Y: {e.Accelerometer.Y} | Z: {e.Accelerometer.Z}"; };

            this.Invoke(inv);
        }
示例#16
0
 protected virtual void OnAccelerometerData(AccelerometerDataEventArgs e)
 {
     var handler = AccelerometerData;
     if (handler != null) handler(this, e);
 }
示例#17
0
        static void OnAccelerationDataAcquired(object sender, AccelerometerDataEventArgs e)
        {
            var args = new AccelerationChangedEventArgs(MyoDevice.AccelerationChangedEvent, sender, e.Myo, e.TimeStamp, e.Accelerometer);

            RaiseEvent(MyoDevice.AccelerationChangedEvent, args);
        }
示例#18
0
 private static void Myo_Accelerometer(object sender, AccelerometerDataEventArgs e)
 { //This function monitors patients movement, writes if he is moving/falling
     //Console.Clear();
     //Console.WriteLine(e.Accelerometer.X + " " + e.Accelerometer.Y + " " + e.Accelerometer.Z);
     if (!isAccelerometerSet)
     {
         previous.Add(e.Accelerometer.X);
         previous.Add(e.Accelerometer.Y);
         previous.Add(e.Accelerometer.Z);
         isAccelerometerSet = true;
     }
     else
     {
         actual.Add(e.Accelerometer.X);
         actual.Add(e.Accelerometer.Y);
         actual.Add(e.Accelerometer.Z);
         for (int i = 0; i < 3; i++)
         {
             if ((actual[i] > 0 && previous[i] > 0) || (actual[i] < 0 && previous[i] < 0))
             {
                 var delta = Math.Abs(actual[i] - previous[i]);
                 deltaList[i].Add(delta);
                 if (criticalSpeed < delta && !fallFlag)
                 {
                     Console.WriteLine("Beware, patient may have fallen!.");
                     fallFlag = true;
                     response = streamFall.UpdateValue(new StreamValue {
                         value = "fall"
                     }).Result;
                 }
             }
             else
             {
                 var delta = Math.Abs(actual[i] + previous[i]);
                 deltaList[i].Add(delta);
                 if (criticalSpeed < delta && !fallFlag)
                 {
                     Console.WriteLine("Beware, patient may have fallen!.");
                     fallFlag = true;
                     response = streamFall.UpdateValue(new StreamValue {
                         value = "fall"
                     }).Result;
                 }
             }
             // Console.WriteLine(actual[i] + " " + previous[i] + " " + deltaList[i][deltaList[i].Count - 1]);
         }
         previous.Clear();
         previous.AddRange(actual);
         actual.Clear();
         if (deltaList[0].Count == 10)
         {
             Boolean isPatientMovingFlag = false;
             foreach (var list in deltaList)
             {
                 var average = list.Average();
                 if (average > 0.02)
                 {
                     isPatientMovingFlag = true;
                 }
                 list.Clear();
             }
             if (isPatientMovingFlag)
             {
                 isPatientMoving = true;
             }
             else
             {
                 isPatientMoving = false;
             }
             Console.WriteLine("Is patient moving? " + isPatientMoving);
             sendingCounter++;
         }
         if (sendingCounter == 15)
         {
             int resultInt;
             if (isPatientMoving)
             {
                 resultInt = 1;
             }
             else
             {
                 resultInt = 0;
             }
             response = movement.UpdateValue(new StreamValue {
                 value = resultInt.ToString()
             }).Result;
             sendingCounter = 0;
         }
     }
     if (fallFlag)
     {
         fallCounter++;
     }
     if (fallCounter == 200)
     {
         fallFlag = false; fallCounter = 0;
     }
 }