Question

I use Motion API in my application for Windows Phone, but not all devices is support Motion API. However in Windows Phone exists Accelerometer API that supports most devices.

What difference between this APIs for my using? Please see this two code blocks:

Using Motion API:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (motion == null)
    {
        motion = new Motion();
        motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(15);
        motion.CurrentValueChanged += OnSensorReadingChangedMotion;
        motion.Start();
    }         
}

private void OnSensorReadingChangedMotion(object sender, SensorReadingEventArgs<MotionReading> e)
{
    Dispatcher.BeginInvoke(() => CurrentValueChangedMotion(e.Gravity.X, e.Gravity.Y, e.Gravity.Z));
}

And using Accelerometer:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
     if (_accelerometer == null)
     {
        _accelerometer = new Accelerometer();
     }

    _accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(15);
    _accelerometer.CurrentValueChanged += OnSensorReadingChangedAccel;

    _accelerometer.Start();       
}

 private void OnSensorReadingChangedAccel(object sender, SensorReadingEventArgs<AccelerometerReading> sensorReadingEventArgs)
 {
     Dispatcher.BeginInvoke(() => CurrentValueChangedAccelerometer(sensorReadingEventArgs.SensorReading.Acceleration.X, sensorReadingEventArgs.SensorReading.Acceleration.Y, sensorReadingEventArgs.SensorReading.Acceleration.Z));
 }

I found that the accelerometer readings is the more volatile. I need to use a vector {x, y, z} for my app. What is actually the difference between

{.SensorReading.Acceleration.X, .SensorReading.Acceleration.Y,.SensorReading.Acceleration.Z}

and

{e.Gravity.X, e.Gravity.Y, e.Gravity.Z}

?

What difference between Motion API and Accelerometer, if I use a similar vector?

Was it helpful?

Solution

Here is the difference :

Acceleration property from accelerometer includes resultant of gravity force as well as forces caused by phone movements, when Gravity property from Motion API is only gravity force (calculated using multiple sensors then separated from forces caused by phone movements).

According to this MSDN post :

The Accelerometer sensor detects the force of gravity along with any forces resulting from the movement of the phone. The combined motion API, accessed using the Motion class, uses multiple device sensors to separate the gravity vector from the device acceleration and allows you to easily determine the current attitude (yaw, pitch, and roll) of the device.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top