コード例 #1
0
        /// <summary>
        /// Update Gyrometer readings event and update UI
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="object"/> instance containing the event data.</param>
        private void UpdateGyrometer(object sender, EventArgs e)
        {
            try
            {
                Gyrometer gyrometer = Gyrometer.GetDefault();
                if (gyrometer != null)
                {
                    XPanel.Text = LocRM.GetString("XAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityX) + "(°)/s";
                    YPanel.Text = LocRM.GetString("YAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityY) + "(°)/s";
                    ZPanel.Text = LocRM.GetString("ZAxis") + ": " +
                                  String.Format("{0,5:0.00}", gyrometer.GetCurrentReading().AngularVelocityZ) + "(°)/s";

                    pictureBoxX.Image = Rotate(imageX, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityX)));
                    pictureBoxY.Image = Rotate(imageY, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityY)));
                    pictureBoxZ.Image = Rotate(imageZ, Math.Max(-135, Math.Min(135, gyrometer.GetCurrentReading().AngularVelocityZ)));
                }
                else
                {
                    XPanel.Text = LocRM.GetString("NotFound");
                    _timer.Stop();
                }
            }
            catch (Exception ex)
            {
                Log.LogError(ex.ToString());
                XPanel.Text = LocRM.GetString("Error");
                _timer.Stop();
            }
        }
コード例 #2
0
 async void gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         gyrometerReading = args.Reading;
     });
 }
コード例 #3
0
 private void _gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     OnSensorReadingChanged(new SensorReadingChangedEventArgs(SensorEventReason.Gyrometer)
     {
         GyrometerReading = args.Reading
     });
 }
コード例 #4
0
        private void OnGetGyrometer(object sender, RoutedEventArgs e)
        {
            Gyrometer        gyrometer = Gyrometer.GetDefault();
            GyrometerReading reading   = gyrometer.GetCurrentReading();

            this.DefaultViewModel["GyrometerResult"] = GetGyrometerResult(reading);
        }
コード例 #5
0
        public Scenario3_Porting()
        {
            this.InitializeComponent();

            // Get two instances of the gyrometer:
            // One that returns the raw gyrometer data
            gyrometerWindows = Gyrometer.GetDefault();
            // Other on which the 'ReadingTransform' is updated so that data returned aligns with the native WP orientation (portrait)
            gyrometerWP = Gyrometer.GetDefault();

            if (gyrometerWP == null || gyrometerWindows == null)
            {
                rootPage.NotifyUser("No gyrometer found", NotifyType.ErrorMessage);
            }
            else
            {
                // Assumption is that this app has been developed for Windows Phone 8.1 (or earlier)
                // and hence assumes that the sensor returns readings in Portrait Mode, which may
                // not be true when the app or sensor logic is being ported over to a
                // Landscape-First Windows device
                // While we encourage you to re-design your app as a universal app to gain access
                // to many other advantages of developing a universal app, this scenario demonstrates
                // a simple approach to let the runtime honor your assumption on the
                // "native orientation" of the sensor.
                gyrometerWP.ReadingTransform = Windows.Graphics.Display.DisplayOrientations.Portrait;
                // If you were to go the route of universal app, make no assumptions about the
                // native orientation of the device. Instead rely on using a display orientation
                // (absolute or current) to enforce the reference frame for the sensor readings.
                // (which is done by updating 'ReadingTransform' property with the appropriate orientation)
            }
        }
コード例 #6
0
        public async void NewGyro(Gyrometer sender, GyrometerReadingChangedEventArgs args)
        {
            var reading = args == null?sender?.GetCurrentReading() : args.Reading;

            await this.dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                () =>
            {
                this[GYROSCOPE] = reading == null
                                              ? this[GYROSCOPE].New(0, 0, 0, 0)
                                              : this[GYROSCOPE].New(
                    reading.AngularVelocityX,
                    reading.AngularVelocityY,
                    reading.AngularVelocityZ,
                    0);
                if (this[GYROSCOPE].IsChanged)
                {
                    this.OnPropertyChanged(new PropertyChangedEventArgs("ItemsList"));
                    this.OnSensorUpdated?.Invoke(this[GYROSCOPE]);
                }
            });

            if (this.SensorSwitches.G.HasValue && (this.SensorSwitches.G.Value == 1 || this.SensorSwitches.G.Value == 3))
            {
                this.SensorSwitches.G = 0;
            }
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the DeviceMotionImplementation class.
        /// </summary>
        public DeviceMotionImplementation()
        {
            try
            {
                accelerometer = Accelerometer.GetDefault();
                gyrometer     = Gyrometer.GetDefault();
                compass       = Compass.GetDefault();

#if WINDOWS_PHONE_APP
                magnetometer = Magnetometer.GetDefault();
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            sensorStatus = new Dictionary <MotionSensorType, bool>()
            {
                { MotionSensorType.Accelerometer, false },
                { MotionSensorType.Gyroscope, false },
                { MotionSensorType.Magnetometer, false },
                { MotionSensorType.Compass, false }
            };
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Accelerometer _accelerometer = Accelerometer.GetDefault(AccelerometerReadingType.Standard);;

            _gyrometer = Gyrometer.GetDefault();
            uint _acclDesiredReportInterval = _accelerometer.MinimumReportInterval;
            uint _gyroDesiredReportInterval = _gyrometer.MinimumReportInterval;

            // make timestamped folder for this record session
            string pathParent = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            string folderPath = System.IO.Path.Combine(pathParent, "IMUData");

            System.IO.Directory.CreateDirectory(new Uri(folderPath).LocalPath);

            // create csv file for this record session
            String fileName = nanoTime() + ".csv";
            String filePath = System.IO.Path.Combine(folderPath, fileName);

            writerCSV = new StreamWriter(new FileStream(new Uri(filePath).LocalPath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true));
            writerCSV.WriteLine("timestamp" + "," + "omega_x" + "," + "omega_y" + "," + "omega_z" + "," + "alpha_x" + "," + "alpha_y" + "," + "alpha_z");
            //writerCSV.WriteLine("timestamp" + "," +  "alpha_x" + "," + "alpha_y" + "," + "alpha_z");


            // Establish the report interval
            _accelerometer.ReportInterval = _acclDesiredReportInterval;
            _gyrometer.ReportInterval     = _gyroDesiredReportInterval;


            _accelerometer.ReadingChanged += AcclReadingChanged;
            _gyrometer.ReadingChanged     += GyroReadingChanged;
            Console.WriteLine("Data Collecting ...");
            Console.ReadLine();
            writerCSV.Close();
        }
コード例 #9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            foreach (FilterInfo device in videoDevices)
            {
                comboBox1.Items.Add(device.Name);
            }
            comboBox1.SelectedIndex = 0;

            videoSource = new VideoCaptureDevice();
            //Accelerometer defaultAcc = Accelerometer.GetDefault();
            _accelerometer = Accelerometer.GetDefault(AccelerometerReadingType.Standard); // set to standard instead of linear acceleration!!!
            //Accelerometer tmp = Accelerometer.GetDefault(AccelerometerReadingType.Linear);
            _gyrometer = Gyrometer.GetDefault();
            textBox1.Clear();
            if (_accelerometer != null)
            {
                _acclDesiredReportInterval = _accelerometer.MinimumReportInterval;
                textBox1.Text      = "IMUs are available on this device!";
                textBox1.BackColor = Color.Green;
                //InitializeTimer();
            }
            else
            {
                textBox1.Text      = "No IMU available on this device!";
                textBox1.BackColor = Color.Red;
            }
            if (_gyrometer != null)
            {
                _gyroDesiredReportInterval = _gyrometer.MinimumReportInterval;
            }
            //if (DEBUG) InitializeTimer();
        }
コード例 #10
0
ファイル: MainPage.xaml.cs プロジェクト: arkiq/LabFebruary24
 private async void Gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         updateUIGyro(args.Reading);  // update the UI with that reading
     });
 }
コード例 #11
0
 private void OnGetGyrometer2(object sender, RoutedEventArgs e)
 {
     gyrometer = Gyrometer.GetDefault();
     gyrometer.ReportInterval  = gyrometer.MinimumReportInterval;
     gyrometer.ReadingChanged += (sender1, e1) =>
     {
         this.DefaultViewModel["GyrometerResult"] = GetGyrometerResult(e1.Reading);
     };
 }
コード例 #12
0
        /// <summary>
        /// Stops this instance.
        /// </summary>
        partial void Stop()
        {
            var gyroscope = Gyrometer.GetDefault();

            if (gyroscope != null)
            {
                gyroscope.ReadingChanged -= GyroscopeReadingChanged;
            }
        }
コード例 #13
0
        void Sensor_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
        {
            var reading = args.Reading;

            OnChanged(new MotionVector(
                          reading.AngularVelocityX * MULTIPLIER,
                          reading.AngularVelocityY * MULTIPLIER,
                          reading.AngularVelocityZ * MULTIPLIER));
        }
コード例 #14
0
        private void Disable()
        {
            if (sensor == null)
            {
                return;
            }

            sensor.ReadingChanged -= Sensor_ReadingChangedAsync;
            sensor = null;
        }
コード例 #15
0
 async void MainPage_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         TextGyrometer.Text = string.Format(@"Gyrometer : X={0} Y={1} Z={2}",
                                            args.Reading.AngularVelocityX.ToString(),
                                            args.Reading.AngularVelocityY.ToString(),
                                            args.Reading.AngularVelocityZ.ToString());
     });
 }
コード例 #16
0
 void MainPage_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         TextGyrometer.Text = string.Format(@"Gyrometer : X={0} Y={1} Z={2}",
                                            args.Reading.AngularVelocityX.ToString(),
                                            args.Reading.AngularVelocityY.ToString(),
                                            args.Reading.AngularVelocityZ.ToString());
     }));
 }
コード例 #17
0
 private async void gyrometer_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     GyrometerReading reading = args.Reading;
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         gyrometerX.Text = string.Format("{0,5:0.00}", reading.AngularVelocityX);
         gyrometerY.Text = string.Format("{0,5:0.00}", reading.AngularVelocityX);
         gyrometerZ.Text = string.Format("{0,5:0.00}", reading.AngularVelocityZ);
     });
 }
コード例 #18
0
ファイル: SensorManager.cs プロジェクト: csuffyy/Sumerics
 public SensorManager(Grid grid)
 {
     _accelerometer = new Accelerometer();
     _gyrometer     = new Gyrometer();
     _inclinometer  = new Inclinometer();
     _light         = new AmbientLight();
     _compass       = new Compass();
     _updaters      = new List <Action>();
     _grid          = grid;
 }
コード例 #19
0
        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}

        private async void Start()
        {
            if (!timer.IsEnabled)
            {
                string runningMessage = "Reading: ";

                accelSensor = Accelerometer.GetDefault();
                if (accelSensor != null)
                {
                    accelSensor.ReportInterval = 66;
                    runningMessage            += "Accelerometer ";
                }

                // while not shown in the chapter, get the current location so that
                // true heading is more accurate.
                Geolocator locator = new Geolocator();
                await locator.GetGeopositionAsync();

                compassSensor = Compass.GetDefault();
                if (compassSensor != null)
                {
                    compassSensor.ReportInterval = 66;
                    runningMessage += "Compass ";
                }

                try
                {
                    gyroSensor = Gyrometer.GetDefault();
                }
                catch (FileNotFoundException) { }

                if (gyroSensor != null)
                {
                    gyroSensor.ReportInterval = 66;
                    runningMessage           += "Gyroscope ";
                }

                inclineSensor = Inclinometer.GetDefault();
                if (inclineSensor != null)
                {
                    inclineSensor.ReportInterval = 66;
                    runningMessage += "Inclinometer ";
                }

                orientationSensor = OrientationSensor.GetDefault();
                if (orientationSensor != null)
                {
                    orientationSensor.ReportInterval = 66;
                    runningMessage += "Orientation ";
                }

                timer.Start();
                messageBlock.Text = runningMessage;
            }
        }
コード例 #20
0
        private async Task EnableAsync(string deviceId)
        {
            if (sensor != null)
            {
                Disable();
            }

            sensor = await Gyrometer.FromIdAsync(deviceId);

            sensor.ReadingChanged += Sensor_ReadingChangedAsync;
        }
コード例 #21
0
ファイル: DeviceMotionService.cs プロジェクト: Redth/f50
 void GyrometerReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
 {
     OnSensorValueChanged(new SensorValueChangedEventArgs
     {
         ValueType  = MotionSensorValueType.Vector,
         SensorType = MotionSensorType.Gyroscope,
         Value      = new MotionVector {
             X = args.Reading.AngularVelocityX, Y = args.Reading.AngularVelocityY, Z = args.Reading.AngularVelocityZ
         }
     });
 }
コード例 #22
0
        private async void gyrometerSensor_ReadingChanged(Gyrometer sender, GyrometerReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                GyrometerReading reading = args.Reading;

                xAxisVel.Text = String.Format("{0,2:0.00}", reading.AngularVelocityX.ToString());
                yAxisVel.Text = String.Format("{0,2:0.00}", reading.AngularVelocityY.ToString());
                zAxisVel.Text = String.Format("{0,2:0.00}", reading.AngularVelocityZ.ToString());
            });
        }
 public UWPDeviceInformationService()
 {
     easDevice     = new EasClientDeviceInformation();
     accelerometer = Accelerometer.GetDefault();
     gyrometer     = Gyrometer.GetDefault();
     magnetometer  = Magnetometer.GetDefault();
     try
     {
         vibrationDevice = VibrationDevice.GetDefaultAsync().GetResults();
     }
     catch { }
 }
コード例 #24
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     gyrometer = Gyrometer.GetDefault();
     if (gyrometer != null)
     {
         gyrometer.ReadingChanged += gyrometer_ReadingChanged;
         Data.Visibility           = Visibility.Visible;
     }
     else
     {
         NoSensorMessage.Visibility = Visibility.Visible;
     }
 }
コード例 #25
0
        /// <summary>
        /// Starts this instance.
        /// </summary>
        partial void Start()
        {
            var gyroscope = Gyrometer.GetDefault();

            if (gyroscope == null)
            {
                return;
            }

            gyroscope.ReportInterval = (uint)Interval;

            gyroscope.ReadingChanged += GyroscopeReadingChanged;
        }
コード例 #26
0
        private void Initsensor()
        {
            //Accelerometer 相關
            _accelerometer = Windows.Devices.Sensors.Accelerometer.GetDefault();

            //Gyromete 相關
            _gyrometer = Gyrometer.GetDefault();

            //Create log file
            Alog = new TestLog("TestAccelerometer.txt");
            Glog = new TestLog("TestGyrometer.txt");
            Hlog = new TestLog("TestAS7000HRM.txt");
        }
コード例 #27
0
        private void ResolveSensorInfo()
        {
            if (Windows.Devices.Sensors.Accelerometer.GetDefault() != null)
            {
                HasAccelerometerSensor = true;
            }

            if (Compass.GetDefault() != null)
            {
                HasCompass = true;
            }

            try
            {
                if (Gyrometer.GetDefault() != null)
                {
                    HasGyroscopeSensor = true;
                }
            }
            catch (Exception e)
            {
                /* Older phone software had a bug causing the
                 * Gyrometer.GetDefault() to throw a file operation
                 * exception.
                 */
                System.Diagnostics.Debug.WriteLine(e.ToString());
                HasGyroscopeSensor = Microsoft.Devices.Sensors.Gyroscope.IsSupported;
            }

            if (Windows.Devices.Sensors.Inclinometer.GetDefault() != null)
            {
                HasInclinometerSensor = true;
            }

            /* Motion API requires both magnetometer (compass) and
             * accelerometer sensors. Gyroscope sensor is used for more
             * accurate results but is not mandatory.
             */
            MotionApiAvailable = Microsoft.Devices.Sensors.Motion.IsSupported;

            if (Windows.Devices.Sensors.OrientationSensor.GetDefault() != null)
            {
                HasOrientationSensor = true;
            }

            // ProximityDevice is NFC
            if (ProximityDevice.GetDefault() != null)
            {
                HasProximitySensor = true;
            }
        }
コード例 #28
0
        public void OnGetGyrometer()
        {
            Gyrometer sensor = Gyrometer.GetDefault();

            if (sensor != null)
            {
                GyrometerReading reading = sensor.GetCurrentReading();
                GyrometerInfo = $"X: {reading.AngularVelocityX} Y: {reading.AngularVelocityY} Z: {reading.AngularVelocityZ}";
            }
            else
            {
                GyrometerInfo = "Gyrometer not found";
            }
        }
コード例 #29
0
        public override void Init()
        {
            if (!SystemInfo.supportsGyroscope)
            {
                Debug.Log("No Gyro Detected, tracking may not work properly");
            }

            sensor = OrientationSensor.GetDefault();
            gyro   = Gyrometer.GetDefault();
            gyro.ReportInterval = gyro.MinimumReportInterval;
            acro = Accelerometer.GetDefault();

            trackingNodes[TrackingNode.HEAD] = new TrackingNode();
        }
コード例 #30
0
ファイル: MainPage.xaml.cs プロジェクト: arkiq/LabFebruary24
        private async void checkForGyro()
        {
            MessageDialog msgDialog = new MessageDialog("");

            gyrometer = Gyrometer.GetDefault();
            if (gyrometer == null)
            {
                msgDialog.Content = "No gyro present";
                await msgDialog.ShowAsync();
            }
            else
            {
                gyrometer.ReadingChanged += Gyrometer_ReadingChanged;
            }
        }