Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to retrieve the seperate rotation values from the gyroscope? — Gideros Forum

How to retrieve the seperate rotation values from the gyroscope?

MikeHartMikeHart Guru
edited December 2011 in General questions
When I read up the documentation of using the gyroscope, i think that there is only one value returned from Gyroscope:getRotationRate().

But there should be seperate values for each axxis, right?


Or do I miss something here?


  • atilimatilim Maintainer
    edited January 2012
    It's not described in documentation but it returns three values (x, y and z).
    require "gyroscope"
    local x, y, z = gyroscope:getRotationRate()
  • Thank you for the quick explanation.

    Maybe this could be added to the docs.
  • Speaking of gyro, I was doing some tests, and data seems to be coming in at a rate (on iOS device) that is not constant. This, by itself, could not be a problem, as long as the frequency is high enough for the purpose (in my case, movement is slow, and even 5 events/sec would be enough), but, being the unit "rad/sec", the returned data should report the timestamp (and it does, on the original doc Mike reported) to allow proper calculation of the rotation. I'm not sure just using os.timer() could help, because data seemed to come in in waves, and I don't know where the bottleneck is...
  • atilimatilim Maintainer
    edited January 2012
    I see.

    After your post, I've done some tests and here is the code that gives the most accurate results:
    require "gyroscope"
    local angx = 0
    local angy = 0
    local angz = 0
    local function onEnterFrame(event)
        local x, y, z = gyroscope:getRotationRate()
        angx = angx + x * event.deltaTime
        angy = angy + y * event.deltaTime
        angz = angz + z * event.deltaTime
        print(angz * 180 / math.pi)
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    But I'm still thinking if a functionality like
    x, y, z, deltaTime = gyroscope:getRotationRate()
    can improve the accuracy.

    Maybe the best way is to internally calculate the exact rotation also and relieve the developers from doing such calculations.

Sign In or Register to comment.