public void AddMeasurement(IBandGyroscopeReading reading)
        {
            var calibratedXReading = reading.AngularVelocityX - 0.0232528209480614;
            var calibratedYReading = reading.AngularVelocityY + 0.648518794348248;
            var calibratedZReading = reading.AngularVelocityZ - 0.162816270729729;

            if (_lastGyroStamp == default(DateTimeOffset))
            {
                _lastVelocity = new Vector(calibratedXReading, calibratedYReading, calibratedZReading);
                _lastGyroStamp = reading.Timestamp;
                return;
            }

            var msSinceLast = (reading.Timestamp - _lastGyroStamp).TotalMilliseconds;
            _lastGyroStamp = reading.Timestamp;
            if (msSinceLast < 0.01)
                return;

            var orientationX = (calibratedXReading + (calibratedXReading - _lastVelocity.X) / 2.0) * msSinceLast / 1000.0;
            var orientationY = (calibratedYReading + (calibratedYReading - _lastVelocity.Y) / 2.0) * msSinceLast / 1000.0;
            var orientationZ = (calibratedZReading + (calibratedZReading - _lastVelocity.Z) / 2.0) * msSinceLast / 1000.0;

            _orientation = _orientation.Add(orientationX, orientationY, orientationZ);
            _lastVelocity = new Vector(calibratedXReading, calibratedYReading, calibratedZReading);
        }
        public void AddMeasurement(IBandGyroscopeReading reading)
        {
            var calibratedXReading = reading.AngularVelocityX - 0.0232528209480614;
            var calibratedYReading = reading.AngularVelocityY + 0.648518794348248;
            var calibratedZReading = reading.AngularVelocityZ - 0.162816270729729;

            if (_lastGyroStamp == default(DateTimeOffset))
            {
                _lastVelocity  = new Vector(calibratedXReading, calibratedYReading, calibratedZReading);
                _lastGyroStamp = reading.Timestamp;
                return;
            }

            var msSinceLast = (reading.Timestamp - _lastGyroStamp).TotalMilliseconds;

            _lastGyroStamp = reading.Timestamp;
            if (msSinceLast < 0.01)
            {
                return;
            }

            var orientationX = (calibratedXReading + (calibratedXReading - _lastVelocity.X) / 2.0) * msSinceLast / 1000.0;
            var orientationY = (calibratedYReading + (calibratedYReading - _lastVelocity.Y) / 2.0) * msSinceLast / 1000.0;
            var orientationZ = (calibratedZReading + (calibratedZReading - _lastVelocity.Z) / 2.0) * msSinceLast / 1000.0;

            _orientation  = _orientation.Add(orientationX, orientationY, orientationZ);
            _lastVelocity = new Vector(calibratedXReading, calibratedYReading, calibratedZReading);
        }
Exemple #3
0
        public BandGyroscopeSensorReadingChangedEventArgs(IBandGyroscopeReading sensorReading)
        {
            if (sensorReading == null)
            {
                throw new ArgumentNullException("sensorReading");
            }

            this.SensorReading = sensorReading;
        }
 public static GyrosocpeReading FromBandSensor(IBandGyroscopeReading reading)
 {
     return new GyrosocpeReading
     {
         AngularVelocityX = reading.AngularVelocityX,
         AngularVelocityY = reading.AngularVelocityY,
         AngularVelocityZ = reading.AngularVelocityZ,
         Timestamp = reading.Timestamp
     };
 }
Exemple #5
0
        private void Gyroscope_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandGyroscopeReading> e)
        {
            IBandGyroscopeReading gyroscropeRead = e.SensorReading;

            data.gyroscopeAngVel = new VectorData3D <double>()
            {
                X = gyroscropeRead.AngularVelocityX,
                Y = gyroscropeRead.AngularVelocityY,
                Z = gyroscropeRead.AngularVelocityZ
            };
        }
Exemple #6
0
        private void Gyroscope_ReadingChanged(object sender, BandSensorReadingEventArgs <IBandGyroscopeReading> e)
        {
            IBandGyroscopeReading s = e.SensorReading;

            _gyroscopeHandler.AddMeasurement(s);

            if (e.SensorReading.AccelerationX > 1.2)
            {
                GotGyroHighXAcceleration?.Invoke();
            }

            GotGyroReading?.Invoke();
        }
Exemple #7
0
 string FormatGyroscope(IBandGyroscopeReading reading) =>
 $"XYZ:{reading.AccelerationX:F2},{reading.AccelerationY:F2},{reading.AccelerationZ:F2}. AVXYZ:{reading.AngularVelocityX:F2}, {reading.AngularVelocityY:F2}, {reading.AngularVelocityZ:F2}";
Exemple #8
0
        private async void Start_Click(object sender, RoutedEventArgs e)
        {
            this.Stop.IsEnabled  = true;
            this.Start.IsEnabled = false;
            StatusMessage.Text   = "";
            // load list point stored in previous collections
            //ListPoint = store.LoadDataPoint(FileName);
            unknown.Clear();
            try
            {
                IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();

                if (pairedBands.Length < 1)
                {
                    this.StatusMessage.Text = "This app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app.";
                    return;
                }

                // Connect to Microsoft Band.
                using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
                {
                    int       samplesReceivedAcc  = 0; // the number of Accelerometer samples received
                    int       samplesReceivedGyro = 0; // the number of Gyroscope samples received
                    Stopwatch myWatch             = Stopwatch.StartNew();
                    // Subscribe to Accelerometer data.
                    bandClient.SensorManager.Accelerometer.ReadingChanged += (s, args) =>
                                                                             bandClient.SensorManager.Gyroscope.ReadingChanged += (s1, args1) =>
                    {
                        Point point = new Point();
                        samplesReceivedAcc++;
                        if ((samplesReceivedAcc % 50) == 0)
                        {
                            // Only report occasional Accelerometer data
                            IBandAccelerometerReading readings = args.SensorReading;
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                this.Accx.Text = readings.AccelerationX.ToString();
                                this.Accy.Text = readings.AccelerationY.ToString();
                                this.Accz.Text = readings.AccelerationZ.ToString();

                                point.setAccelerometter(readings.AccelerationX, readings.AccelerationY, readings.AccelerationZ);
                            });
                        }
                        samplesReceivedGyro++;
                        if ((samplesReceivedGyro % 50) == 0)
                        {
                            // Only report occasional Gyroscope data
                            IBandGyroscopeReading readings = args1.SensorReading;
                            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                this.Gyx.Text = readings.AccelerationX.ToString();
                                this.Gyy.Text = readings.AccelerationY.ToString();
                                this.Gyz.Text = readings.AccelerationZ.ToString();
                                Clock.Text    = myWatch.Elapsed.ToString();
                                point.setGyroscope(readings.AccelerationX, readings.AccelerationY, readings.AccelerationZ);
                                // point.SampleName = samplename;
                                unknown.Add(point);
                            });
                        }
                    };
                    await bandClient.SensorManager.Accelerometer.StartReadingsAsync();

                    await bandClient.SensorManager.Gyroscope.StartReadingsAsync();

                    // Receive sensor data for a while
                    await Task.Delay(TimeSpan.FromSeconds(2));

                    // Stop the sensor subscriptions

                    await bandClient.SensorManager.Accelerometer.StopReadingsAsync();

                    await bandClient.SensorManager.Gyroscope.StopReadingsAsync();
                }
            }
            catch (Exception ex)
            {
                this.StatusMessage.Text = ex.ToString();
            }
        }