views:

553

answers:

4

Hello,

Is there a way to detect if an iphone lying down in a table face up is rotating?. I do realize that this kind of movement is not reported by the accelerometer and neither is it reported to the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method.

Is there a way to detect angle variations for the phone rotating this way?. Thank you.

+4  A: 

I guess you could do it if the iPhone has a compass. Other than that I don't think it will be possible or reliable.

Tom Irving
Performance would degrade quickly as you approach magnetic poles; this would exclude several key demographics (penguins, Santa Claus, and toy-building elves, just to name a few).
stack
+8  A: 

The gravity vector will be constant as it rotates on a flat table so you won't see anything on the accelerometers. You could follow compass heading changes to detect this rotation but only on an iPhone 3G S. See the CLLocationManager for details, look at the heading methods.

EDIT - With an iPhone 4 you can detect the rotation using the gyros. There is a new class in iOS 4 called CMMotionManager for getting rotation rate from the gyros.

progrmr
+2  A: 

This would really depend on the location of the accelerometer on the device, i just tested this using the accelerometergraph sample application on a 2g itouch and you can see the initial acceleration on the x and y axis(the 2g does not have the accelerometer in the center of the device I guess). So in a sense you could detect the rotation, however I think the challenge would be differentiating that acceleration from directional acceleration. And I'm sure the values would change if apple placed the accelerometer in different locations on different models. There would definitally not be any way of doing it via shouldAutorotateToInterfaceOrientation, I recommend you load the accelerometergraph sample application in the sdk and experiment with the acceleration vectors to see if you can isolate a rotation vector reliably on multiple devices.

Medran
That is actually what I tried to use the accelerometer graph sample and thats when I realized nothing was reported.
OscarMk
+4  A: 

When the phone is stationary the sum of the acceleration vectors should be +1. When the phone is rotating (assuming the sensor is off-center) the sum of the vectors should be more than 1 and (hopefully) somewhat constant.

If you look at the decay of that curve, I wouldn't be surprised if that shape is distinctive enough to be used to determine whether the phone is rotating or not.

alt text

This is the AccelerometerGraph sample app from Apple.

kubi
Nice graphs. Is there an app for that?
progrmr
There's an Apple example app for it. I edited my post.
kubi
Thank you for your input. I tried using that app and then rotated my iphone but i did not see any changes on the accelerometer. Maybe my sensor is in the center?
OscarMk
How fast were you rotating it? I was putting my phone on the table and giving it a good spin. Do you see the graphs changing when you change the orientation of your phone?
kubi
I was rotating it quite slow. I don't have my phone with me atm, but I will try it again. thank you.
OscarMk