Gyroscope and Accelerometer data from Windows?

Microsoft Surface Pro has a gyroscope and accelerometer, Windows 8 and the full .NET platform.

Most of the articles that I find suggest that the motion API points to the Windows Phone 8 API.

What spaces and classes of the .NET Framework should be used to obtain gyroscope and accelerometer data?

+5
source share
2 answers

I just worked based on the documentation - http://msdn.microsoft.com/en-us/library/ie/windows.devices.sensors

using Windows.Devices.Sensors; private Accelerometer _accelerometer; private void DoStuffWithAccel() { _accelerometer = Accelerometer.GetDefault(); if (_accelerometer != null) { AccelerometerReading reading = _accelerometer.GetCurrentReading(); if (reading != null) double xreading = reading.AccelerationX; ... etc. } } 

Not tested it, but it should work for any Windows Store app. If you are trying to run it as an application for consoles / windows, you need to change the target platform to:

+4
source

For the surface professional, you need to use the Windows 8.1 library instead of the Windows Phone 8.1 library.

It must be in the same Windows.Devices.Sensors namespace.

 using Windows.Devices.Sensors; ... //if you aren't already doing so, and you want the default sensor private void Init() { _accelerometer = Accelerometer.GetDefault(); _gyrometer = Gyrometer.GetDefault(); } ... private void DisplayAccelReading(object sender, object args) { AccelerometerReading reading = _accelerometer.GetCurrentReading(); if (reading == null) return; ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX); ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY); ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ); } ... private void DisplayGyroReading(object sender, object args) { GyrometerReading reading = _gyrometer.GetCurrentReading(); if (reading == null) return; ScenarioOutput_AngVelX.Text = String.Format("{0,5:0.00}", reading.AngularVelocityX); ScenarioOutput_AngVelY.Text = String.Format("{0,5:0.00}", reading.AngularVelocityY); ScenarioOutput_AngVelZ.Text = String.Format("{0,5:0.00}", reading.AngularVelocityZ); } 
+3
source

Source: https://habr.com/ru/post/1200143/


All Articles