Jordan Parmer
Jordan Parmer

Reputation: 37184

How do I use the motion sensors on a Windows 8 tablet from a WPF application?

I have a Windows 8 tablet. I am developing a WPF application (i.e. not a Modern, Windows Store application) in .NET 4.5.

The tablet is going to be mounted in a truck, and I need to get the speed at which the tablet is traveling. I am currently using the Windows Location Service (System.Device.Location) but the API doesn't track speed, just lat/lon coordinates. I cannot interpolate the speed from the coordinate change over time because the device does not emit enough readings for an accurate calculation.

I know that if I were developing a Modern app, I could use the System.Device.Sensors framework, but this doesn't seem available to a WPF app.

Does anyone know how I can access the accelerometer sensor in a WPF application? I prefer a .NET solution although I will consider a native solution if I must.

Upvotes: 1

Views: 539

Answers (1)

Tombala
Tombala

Reputation: 1690

You can't use accelerometer readings to accurately calculate speed because you might drift if you miss values or get bad readings or miss equal and opposite forces. E.g. the user kicked the tablet accidentally so you read a huge spike in acceleration but missed the deceleration due to the sampling frequency, so now you think you're speeding down the highway even though you're not. Basically, you can't get reliable speed calculation based on accelerometer readings.

You should continue to use the Windows Location Service and do sampling. Then calculate the moving average of your speed based on the last (x) samples of your location. If you have GPS enabled, location service will use the GPS so over a time period of, say, a few seconds, you might be able to calculate an accurate enough speed. I don't know how many seconds of sampling will give you a good average for your speed calculation but you can try and see what works best.

Upvotes: 2

Related Questions