ios accelerometer values at any orientation

大城市里の小女人 提交于 2019-12-04 04:48:59

问题


Accelerometer values are provided with respect to the device orientation..

My goal is to get these values irrespective of the device position.

In a considered scenario, if the device is placed in a vehicle, placed face up or horizontally, the accelerometer values along y would indicate the vehicles acceleration.

What if the device is placed in the glove box with random orientation? We can get the roll pitch and yaw values, and convert them into degrees to get the angular displacement of device from the normal face up orientation position but at that random orientation moment, can I get/convert the acceleration values into the the normal face up orientation position values?

Basically what I am following is: get the angular displacement of device -> convert the accelerometer values received at the distorted position to a normal face up orientation position -> get the Y to see the actual acceleration of vehicle irrespective of the device position.

Reference (Point 3.1): http://www.itsasiapacificforum2014.co.nz/files/3314/0194/4873/Abstract_-_Automatic_Accelerometer_Reorientation_for_Driving_Event_Detection_Using_Smartphone_by_Passakon_Prathombutr.pdf


回答1:


Its quite simple actually, just start generating device motion updates using a reference frame:

- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)referenceFrame

Depending on what you want to achieve you can select one of the different options

typedef enum {
   CMAttitudeReferenceFrameXArbitraryZVertical = 1 << 0,
   CMAttitudeReferenceFrameXArbitraryCorrectedZVertical = 1 << 1,
   CMAttitudeReferenceFrameXMagneticNorthZVertical = 1 << 2,
   CMAttitudeReferenceFrameXTrueNorthZVertical = 1 << 3
} CMAttitudeReferenceFrame;

For example, by using "CMAttitudeReferenceFrameXMagneticNorthZVertical" the readings you get from the acceleration would be constant regardless of the device position (they get aligned with "gravity" bellow" and "north" in front). I don't remember the exact reference position but i believe the "top of the phone" points north while the "screen of the phone" points up.



来源:https://stackoverflow.com/questions/28959943/ios-accelerometer-values-at-any-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!