8

While GPS works for long distance changes, I would like to measure a shorter distance by using the iPhone's accelerometer.

Say I want to measure a height of a box using an iPhone application. You'd start the application, press a button to start measurement at the bottom of a box, move your iPhone from to the top of the box, then press a button to stop measurement. The application would then calculate and display the height of the box.

How would I use the accelerometer to perform this kind of measurement?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Matrix
  • 7,477
  • 14
  • 66
  • 97

5 Answers5

14

It is possible to do this, as I have implemented a more complex system on a sparkfun IMU.

There are a few components to do what you require accurately.

1) You need to filter the accellerometers signal using a low pass filter. This removes any noise that is not caused by your slow moving arm.

2) Integrate the 3 seperate acceleration values twice to go from acceleration to velocity, and then from velocity to distance.

3) The above method must be performed by keeing the phone in the same plane when you move it from the bottom of the box to the top. Any pitch/roll/yaw will disrupt the measurement(hint)

4) From above, to compensate for the pitch/roll/yaw, you can then include the built in gyro =]. Use this to map the vector obtained from the accellerometer to the starting point. Using this methodology you can measure the distance "through and object" by walking around it. (remember this gyro needs filtering too).

The final result depends on many factors such as, the effectiveness of your filter, the accuracy and sampling rates of your accellerometer and gyro, and the awsomeness of your mathematics and linnear algebra skills.

dmon
  • 30,048
  • 8
  • 87
  • 96
Dbag
  • 141
  • 1
  • 2
  • @Demon, Do you have any more details about the specifics of calculations? Also, I have multiple values for acceleration available to me (lines 84-116 of https://github.com/jrowberg/i2cdevlib/blob/b6836bb46e248574816356a6a0a589718b6949fa/Arduino/MPU6050/Examples/MPU6050_DMP6/MPU6050_DMP6.ino) Would you have a recommendation of which one would be best to use? Thanks a lot! – Greg R Apr 06 '14 at 00:43
5

Try photographing an object of a known size at the distance of interest.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • I liked the idea of photographing an object of known size. I have tried a lot to implement using accelerometer. But the result was always much smaller than the actual value. How can I proceed with your idea? Will it require a lot of image processing concepts? – Ashwin Oct 22 '12 at 06:13
  • I lol'd. It's like the old puzzle about how do you measure the height of a building using just a barometer. The answers are all things like "measure the height of the barometer, the length of the barometer's shadow, and the length of the building's shadow" or "drop the barometer from the top of the building and time how long it takes to hit" or "tell the architect you'll give him this nice barometer if they'll tell you how tall the building is." Bottom line: it's just not the right tool for the job. – Edward Falk Jun 14 '16 at 15:03
3

Depending on the application, and how much accuracy you need, you may be able to use the new 6-axis gyro accelerometers in the iPhone 4 and iPod Touch 4th Gen. You could get the total displacement by integrating the acceleration vector.

When integrating acceleration to get displacement, any errors will be cumulative, so this may not be appropriate, but may be worth considering.

Nick Forge
  • 21,344
  • 7
  • 55
  • 78
0

GPS is currently not accurate enough to measure a box. Take into account that there may be an error of about 10 meters to a mile. You can get back the accuracy of the measure with CLLocation.

Daniel
  • 20,420
  • 10
  • 92
  • 149
-1

Pythagorean Theorem: c^2 = a^2 + b^2 (http://en.wikipedia.org/wiki/Pythagorean_theorem)

In your case, if point A = (Ax, Ay) and B = (Bx, By), then you can compute the distance C by:

C = sqrt( (Bx-Ax)^2 + (By-Ay)^2 )
mkoistinen
  • 7,724
  • 3
  • 41
  • 56
  • Hey all, before you downvote this into oblivion, you should know that the original question is significantly different than it is now. When I answered it, 10 years ago, the question was simply: "How to measure distance between two points ?? (In IPhone SDK) How to measure distance between two points in iPhone SDK..?? GPS works for long distance point but haw can i measure short distance point...? for example: say length of a room." – mkoistinen Jul 23 '20 at 15:49