interpreting and converting accelerometer data

Hi,

I am playing with the accelerometer event and I am trying to make sense of the 6 properties that are accessible:
xInstant, yInstant, zInstant & xGravity, yGravity, zGravity.

Could someone point me where there is any doc allowing to translate those metrics in angles and x/y/z translations ?

Cheers,

Romain.
http://blog.thecodingfrog.com [import]uid: 4570 topic_id: 498 reply_id: 300498[/import]

Reude,

I am trying to capture acceloremeter events to see what it does, but I don’t get any value. Here is my code:

local updateScreen = function (event)
– Get x,y,z gravity and instant
local xG = event.xGravity
local yG = event.yGravity
local zG = event.zGravity
local xI = event.xInstant
local yI = event.yInstant
local zI = event.zInstant
local v_xG = string.format(’%.0f’, xG)
local v_yG = string.format(’%.0f’, yG)
local v_zG = string.format(’%.0f’, zG)
local v_xI = string.format(’%.0f’, xI)
local v_yI = string.format(’%.0f’, yI)
local v_zI = string.format(’%.0f’, zI)

– update texts
xx= “X=”… v_xG … " G" … v_xI " I"
yy= “Y=”… v_yG … " G" … v_yI " I"
zz= “Z=”… v_zG … " G" … v_zI " I"
tt.text=xx,yy,zz – where tt is display.newText.
end

Runtime:addEventListener( “accelerometer”, updateScreen)

The thing is when I run this app on device, tt always return 0, even if I directly use tt.text=string.format(’%d’,event.xGravity). So I don’t see any accelerometer response on device.

Finally I was trying to setup system.setAccelerometerInterval(50) and no matter what I put as value, like 10, .01 or 10Hz it always get an error, saying value must be a range between [10,100].

So if you already are getting some response of accelerometer on your test, could you point me where I wrong?

Regards,

Flavio. [import]uid: 3022 topic_id: 498 reply_id: 1027[/import]

This code only works on shake, but it does output a value for event.yGravity if that is any help. I am also trying to figure out how to get this code to work without the need to shake the device, but at least it is a step in the right direction. By the way, changing the orientation and hitting shake will allow you to test in the simulator.

– The code

Holder = display.newImage( “cube01.png”, 240, 240 )

local function shakeme(event)
Holder.y = Holder.y - event.yGravity
end

Runtime:addEventListener(“accelerometer”,shakeme)
[import]uid: 4871 topic_id: 498 reply_id: 1039[/import]

– This code should work for you

local Holder = display.newImage( “cube01.png”, 240, 240 )
local Movement = 0

local function shakeme(event)
Movement = event.yGravity
end

local function onEnter(event)
Holder.y = Holder.y - Movement
end

Runtime:addEventListener(“enterFrame”,onEnter)
Runtime:addEventListener(“accelerometer”,shakeme)
[import]uid: 4871 topic_id: 498 reply_id: 1042[/import]

werinteractive,

Thanks for your response. I will check that code today.

On the other hand, do you know what value is accepted in this call: system.setAccelerometerInterval( xxx ), because I tried to put 10, .1, 100 and no matters what I put, it always give me a warning message, saying parameter should be between the range of [10,100].

Flavio. [import]uid: 3022 topic_id: 498 reply_id: 1074[/import]