There are two articles about this topic that is very helpful and I believe it will very helpful to you too. Go and take a loot at them since mine is an abbreviation of those: 31 Days of Windows Phone | Day #11: Accelerometer and Using the Accelerometer on Windows Phone 7 on The Windows Phone Developer Blog.
There are two major usages of the accelerometer:
- Orientation relative to our planet Earth (assuming the device is being held steady)
- Detecting movement of the device relative to the initial point (assuming you know the orientation).
The Accelerometer is in the Microsoft.Devices.Sensors namespace. We can get tree values: X, Y, Z from AccelerometerReadingEventArgs when ReadingChanged even fires.
The articles I've shown you said "Windows Phone devices that measures the acceleration on 3 axes (X, Y, Z), relative to freefall. In addition to a timestamp, the values are expressed in G-forces (1G = 9.81 m/s2)."
- X is positive when the left edge of your phone is face up, on a perfectly flat surface; negative when the right edge of your phone is face up, on a perfectly flat surface. In addition, we assume that Y and Z would be 0 in this circumstance.
- Y is positive when the lower edge of your phone is face up, on a perfectly flat surface; negative when the upper edge of your phone is face up, on a perfectly flat surface.In addition, we assume that X and Z would be 0 in this circumstance.
- Z is positive when your phone is face down, on a perfectly flat surface; negative when your phone is face up, on a perfectly flat surface.In addition, we assume that X and Y would be 0 in this circumstance.
Note:
- Getting a value of 1.0 is not going to happen all the time. Earth’s gravity doesn’t roll that way.
- You will get those events often (Fifty times per second).
- There will be some calibration problems due to the nature of manufacturing tolerances (and users possibly dropping their phones a few times). Some devices will also come with edges that are not exactly flat. This means setting the device on a table may not result in a “level” reading. For applications using orientation, they need to really know that when the X and Y values are 0, the device is “leveled” (if “leveled” means the device is lying flat. If “leveled” means on edge then Z is 0, and either X or Y is 0).
For an example about how to detecting the movement of your device, go ahead take a look at "How do I get values from the WP7 Accelerometer?" in 31 Days of Windows Phone | Day #11: Accelerometer. The method ReadingChanged is obsoleted since Windows Phone 7.1 (Mango). You will get a warning when you compile you application. For a newer example on the new method CurrentValueChanged here: How to: Get Data from the Accelerometer Sensor for Windows Phone
For an example about how orientation, 31 Days of Windows Phone | Day #4: Device Orientation.
No comments:
Post a Comment