How to calibrate accelerometer?

I would like to know if anyone can post an example of how to calibrate the accelerometer to support different user positions in landscape mode. More or less, I need to know how to calculate and apply the offset after taking the initial readings. I have tried a few tutorials for other languages but haven’t been able to figure out the correct way using LUA.

Thanks,

Andre [import]uid: 10048 topic_id: 14690 reply_id: 314690[/import]

I would like to know this as well!
Basically, reset the accelerometer right before game start like in games that use tilt control. [import]uid: 39031 topic_id: 14690 reply_id: 54776[/import]

Can anyone from Ansca chime in and let us know whether this is possible or not?
Thanks. [import]uid: 39031 topic_id: 14690 reply_id: 54984[/import]

Ohhh, I would love to know. I want to be able to make it so that the acceleration is at 0 when the phone is tilted at a 90 degree angle towards you. That would be awesome if you could calibrate it :slight_smile:

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 14690 reply_id: 55007[/import]

anyone more info on this ? [import]uid: 225288 topic_id: 14690 reply_id: 143242[/import]

So here’s my idea - instead of “really” calibrating it, couldn’t you just store some values from it?

Like so:
[lua]
local calibX=0
local calibY=0
local accelXGravity
local accelYGravity

local function calibrate(event)
if event.numTaps==2 then
calibX, calibY=accelXGravity, accelYGravity
end
end
Runtime:addEventListener(“tap”, calibrate)

local function accelerometerEvent(event)
accelXGravity, accelYGravity=event.xGravity, event.yGravity – The default gravity, without any calibration control

physics.setGravity(event.xGravity-calibX, event.yGravity-calibY) – Subtract calibX and calibY
end
Runtime:addEventListener(“accelerometer”, accelerometerEvent)
[/lua]
Now I just wrote that code sitting here at the reply form - not to mention I’ve never really done much with the accelerometer - so it might not work, but it seems like it should.

Caleb [import]uid: 147322 topic_id: 14690 reply_id: 143312[/import]

or [code]
local delta = -30/180*math.pi – 30 degrees
local cos_delta, sin_delta = math.cos(delta), math.sin(delta)

local function onTilt(event)
– Its for the new position of the bird
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
[/code] [import]uid: 225288 topic_id: 14690 reply_id: 143450[/import]

anyone more info on this ? [import]uid: 225288 topic_id: 14690 reply_id: 143242[/import]

So here’s my idea - instead of “really” calibrating it, couldn’t you just store some values from it?

Like so:
[lua]
local calibX=0
local calibY=0
local accelXGravity
local accelYGravity

local function calibrate(event)
if event.numTaps==2 then
calibX, calibY=accelXGravity, accelYGravity
end
end
Runtime:addEventListener(“tap”, calibrate)

local function accelerometerEvent(event)
accelXGravity, accelYGravity=event.xGravity, event.yGravity – The default gravity, without any calibration control

physics.setGravity(event.xGravity-calibX, event.yGravity-calibY) – Subtract calibX and calibY
end
Runtime:addEventListener(“accelerometer”, accelerometerEvent)
[/lua]
Now I just wrote that code sitting here at the reply form - not to mention I’ve never really done much with the accelerometer - so it might not work, but it seems like it should.

Caleb [import]uid: 147322 topic_id: 14690 reply_id: 143312[/import]

or [code]
local delta = -30/180*math.pi – 30 degrees
local cos_delta, sin_delta = math.cos(delta), math.sin(delta)

local function onTilt(event)
– Its for the new position of the bird
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
[/code] [import]uid: 225288 topic_id: 14690 reply_id: 143450[/import]

anyone more info on this ? [import]uid: 225288 topic_id: 14690 reply_id: 143242[/import]

So here’s my idea - instead of “really” calibrating it, couldn’t you just store some values from it?

Like so:
[lua]
local calibX=0
local calibY=0
local accelXGravity
local accelYGravity

local function calibrate(event)
if event.numTaps==2 then
calibX, calibY=accelXGravity, accelYGravity
end
end
Runtime:addEventListener(“tap”, calibrate)

local function accelerometerEvent(event)
accelXGravity, accelYGravity=event.xGravity, event.yGravity – The default gravity, without any calibration control

physics.setGravity(event.xGravity-calibX, event.yGravity-calibY) – Subtract calibX and calibY
end
Runtime:addEventListener(“accelerometer”, accelerometerEvent)
[/lua]
Now I just wrote that code sitting here at the reply form - not to mention I’ve never really done much with the accelerometer - so it might not work, but it seems like it should.

Caleb [import]uid: 147322 topic_id: 14690 reply_id: 143312[/import]

or [code]
local delta = -30/180*math.pi – 30 degrees
local cos_delta, sin_delta = math.cos(delta), math.sin(delta)

local function onTilt(event)
– Its for the new position of the bird
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
[/code] [import]uid: 225288 topic_id: 14690 reply_id: 143450[/import]

anyone more info on this ? [import]uid: 225288 topic_id: 14690 reply_id: 143242[/import]

So here’s my idea - instead of “really” calibrating it, couldn’t you just store some values from it?

Like so:
[lua]
local calibX=0
local calibY=0
local accelXGravity
local accelYGravity

local function calibrate(event)
if event.numTaps==2 then
calibX, calibY=accelXGravity, accelYGravity
end
end
Runtime:addEventListener(“tap”, calibrate)

local function accelerometerEvent(event)
accelXGravity, accelYGravity=event.xGravity, event.yGravity – The default gravity, without any calibration control

physics.setGravity(event.xGravity-calibX, event.yGravity-calibY) – Subtract calibX and calibY
end
Runtime:addEventListener(“accelerometer”, accelerometerEvent)
[/lua]
Now I just wrote that code sitting here at the reply form - not to mention I’ve never really done much with the accelerometer - so it might not work, but it seems like it should.

Caleb [import]uid: 147322 topic_id: 14690 reply_id: 143312[/import]

or [code]
local delta = -30/180*math.pi – 30 degrees
local cos_delta, sin_delta = math.cos(delta), math.sin(delta)

local function onTilt(event)
– Its for the new position of the bird
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
[/code] [import]uid: 225288 topic_id: 14690 reply_id: 143450[/import]