Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Accelerometer calibration

How do I properly calibrate the accelerometer for my iPhone game? Currently, when the phone is on a flat surface, the paddle drifts to the left. High or Low Pass filters are not an acceptable solution as I need complete control over the paddle even at low & high values. I know Apple has the BubbleLevel sample but I find it difficult to follow... could someone simplify the process?

My accelerometer code looks like this:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

float acelx = -acceleration.y;
float x = acelx*40;

Board *board = [Board sharedBoard];
AtlasSprite *paddle = (AtlasSprite *)[board.spriteManager getChildByTag:10];

if ( paddle.position.x > 0 && paddle.position.x < 480) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}

if ( paddle.position.x < 55 ) {
    paddle.position = ccp(56, paddle.position.y);
}

if ( paddle.position.x > 435 ) {
    paddle.position = ccp(434, paddle.position.y);
}

if ( paddle.position.x < 55 && x > 1 ) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}

if ( paddle.position.x > 435 && x < 0) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}
}

Thank you!

like image 708
user2393462435 Avatar asked Jan 21 '10 22:01

user2393462435


People also ask

Can you calibrate accelerometer?

Simple Calibrator for Accelerometers The most convenient means of performing a periodic calibration check is by using a B&K battery-powered calibrated vibration source. This has a small built-in shaker table which generates precisely 10 m/s2 at 159.15 Hz.

Does iPhone have calibration?

Open Settings. Turn on the Location Services toggle switch, then scroll down and tap System Services. Turn on the Compass Calibration and Motion Calibration & Distance toggle switches. The iPhone uses your location data to ensure the gyroscope, GPS, compass, and accelerometer work properly.

How do I adjust the calibration on my iPhone?

Go to Settings > Accessibility > Touch, then tap Haptic Touch or 3D & Haptic Touch. Choose the touch duration—Fast or Slow. On an iPhone with 3D Touch, you can also choose the pressure needed—Light, Medium, or Firm. Test the new setting on the image at the bottom of the screen.


1 Answers

Okay, problem SOLVED and the solution is so simple I'm actually embarrassed I didn't come up with it sooner. It's as simple as this:

In a "Calibration Button":

//store the current offset for a "neutral" position
calibration = -currentAccelX * accelerationFactor;

In the game time accelerometer function:

//add the offset to the accel value
float x = (-acceleration.y * accelerationFactor) + calibration;

It's as simple as adding the offset. * hides his head *

like image 160
user2393462435 Avatar answered Sep 18 '22 11:09

user2393462435