Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gyroscope and accelerometer data from Windows?

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

Most articles I find that talk about the motion API point to the Windows Phone 8 API.

What .NET Framework namespaces and classes should I be using to get gyroscope and accelerometer data from?

like image 855
Jim Avatar asked Aug 12 '14 18:08

Jim


People also ask

What data does a gyroscope output?

A 3D gyroscope measures the angular velocity of its rotation in a reference frame along its three sensitivity axes. For an ideal sensor, these outputs are equal to the projections of the rotation angular velocity on the sensitivity, that is, intrinsic coordinate system axes.

What is sensor data service?

Sensor Data Service - Delivers data from a variety of sensors. Sensor Service - A service for sensors that manages different sensors' functionality. Skype Updater - Enables the detection, download and installation of updates for Skype.

What is the use of Windows sensor?

The Windows Sensor API provides a set of methods, properties, and events to work with connected sensors and sensor data. The Windows Location API, which is built on the Windows Sensor API, provides a set of programming objects, including scripting objects, for working with location information.

How do you detect a gyroscope?

If you want to check if gyroscope is present or not, check the parameters that only gyroscope can measure. For example rotation rate is something only gyroscope measures. Have a look at an example code which says whether gyroscope is present or not: var gyroPresent = false; window.


2 Answers

I just worked based off 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.
   }
}

Haven't tested it, but it should work for any Windows Store App - If you're trying to make it run as a console/windows forms app, you need to change the targetplatform by:

  1. Right Click your project -> Unload Project
  2. Follow the rest of this https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications
like image 196
Levi Fuller Avatar answered Oct 30 '22 06:10

Levi Fuller


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

It should 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);
}
like image 20
wbennett Avatar answered Oct 30 '22 08:10

wbennett