Bugs in Gyroscope Data Coming from Corona SDK

Hello!

I am working on an app that makes use of the gyroscope on my iPhone4S (iOS 7.1.1). My code couldn’t be simpler so far, and the data I am receiving from Corona is just not adding up (literally). In my scene’s create function I am calling this:

[lua]

Runtime:addEventListener(“gyroscope”, onGyroscope)

system.setGyroscopeInterval( 100 )

[/lua]

And then in my onGyroscope callback function, I have code like this:

[lua]

local function onGyroscope( event )

    local delta_time = event.deltaTime

    local z_rot_delta = event.zRotation * delta_time * (180 / math.pi)

    zRotation = zRotation - z_rot_delta

    print(zRotation … " " … event.zRotation … " " … delta_time)

end

[/lua]

When I do a ninety degree spin to the right at a medium speed I lose around twenty degrees, but sometimes more, and sometimes less. The print stream that gets generated looks like this:

0.5535479233937 -0.0125738487707 0.019010500000149

0.57637898609856 -0.02434768394994 0.019018416667677

0.5852616895206 -0.011550395963783 0.0190131666659

1.0228101265105 -0.40505029020229 0.019013041666767

2.2347046508187 -1.1106926379063 0.019101708334347

2.2310046508187 -1.1106926379063 0

2.2273046508187 -1.6522754740298 0

2.2236046508187 -2.3304406571868 0

5.4442654923835 -2.9596404279095 0.019014374998733

9.4162560818311 -3.6496058115406 0.019012708333321

14.49728545662 -4.6672111156526 0.019014625000636

19.861691398613 -4.9275457648522 0.019013749999431

25.164308178807 -4.8491497592113 0.019098750000921

25.160608178807 -4.8491497592113 0

25.156908178807 -4.7403479107728 0

29.869537828801 -4.343910816168 0.018949625000459

34.316634828873 -4.0854307923515 0.019014166666238

38.843335492657 -4.1593747915981 0.019010166666703

43.318970275344 -4.1109502671811 0.019017291666387

47.703171112804 -4.0137480831865 0.019080250000115

51.741966026302 -3.7098901912401 0.019018041666641

51.738266026302 -3.7098901912401 0

51.734566026302 -3.4538448292922 0

55.411371961224 -3.3919455087077 0.018938083332614

58.740035952839 -3.0602384086101 0.019005291667781

61.602144755127 -2.6219875543622 0.019076291666352

63.953083559531 -2.1681071403088 0.018954875000418

66.062656348915 -1.9325271060737 0.019085666664978

67.829180348392 -1.6175617018528 0.019100500001514

67.825480348392 -1.6175617018528 0

67.821780348392 -1.3586462511981 0

68.573950534545 -1.3875077268796 0.0095079999991867

69.744968524142 -1.078240422127 0.019014958334083

70.649882788173 -0.83422349355852 0.019009666666534

71.13261148757 -0.44647229884906 0.019015249999939

71.765580709735 -0.58232627132451 0.019082041666479

72.525804615567 -0.7034670777256 0.018953250000777

72.522104615567 -0.7034670777256 0

72.518404615567 -0.60864283026834 0

72.514704615567 -0.35429230403815 0

72.732887453761 -0.20364793381672 0.019016083333554

72.926999530615 -0.1816126726413 0.019010083333342

73.06191666752 -0.12723358634297 0.019014833333131

73.178169464236 -0.11010200368271 0.019014833333131

73.378280582619 -0.18637573625091 0.019086041667833

I understand that the documentation says it is legitimate for event.deltaTime to be ‘0’ sometimes. However, I notice that if I use the last non-zero delta time that came through as the delta time for the times where delta time is ‘0’, while skipping the first one (note the bold bits above - it seemed really fishy that they were always identical to the one from the previous time), my basic code above becomes a lot closer to being accurate. So I am fairly sure that there is a bug somewhere in Corona SDK that is causing this odd behaviour.

My next problem is when I spin the phone much more quickly, everything goes way out of whack. It is definitely not a question of gyroscope drift. I tried programming a Complementary filter and it is not helping. My hunch is that a Kalman filter isn’t going to help either (but I could be wrong?). I think that Corona SDK is not giving me valid information from the gyroscope.

Has anyone had any success doing what I am trying to do? I would love to hear about it if so.

Perhaps someone from Corona could look into this and advise?

Thanks very much!