I am working on an iPhone app where we are trying to calculate the acceleration of a moving car. Similar apps have accomplished this (Dynolicious), but the difference is tha
This doesn't solve your problem completely, but hopefully it clears up what you've been trying to do. I do believe that ultimately you will need some other instrument to be able to fully do this. GPS as tom10 suggested sounds like the best option to me (since there isn't a gyro available), but I foresee problems with that such as lag time and inaccuracy in the GPS coordinates (I don't know how accurate the iPhone GPS is).
First, I assume that the iPhone is firmly attached to the car throughout. For a slope that is up or down with no curve left or right, you can do the following for calibration.
v5 points in the direction that gravity will point when the car is on a perfectly flat surface. You can now at least tell if you are on a slope of some sort and what the angle is of that slope. This can be done in the following manner:
However, this is where we run into problems. Even if we limit ourselves to slopes that are up and down rather than curving/banking left or right, we still can't tell for sure if the slope is going down or up - just the angle of it. We can find initially if the car is going up or down a slope by taking the dot product of v1 and v3 (a positive value indicates a downward slope, and a negative value an upward slope).
You might however be able to use the fact of whether the magnitude of the total acceleration vector is decreasing or increasing as the slope increases or decreases to make a guess at this, but it won't be for sure. For instance, if the angle (theta) of the slope has been 0 degrees (or close enough to it) and now it isn't, and the projection (dot product) of the overall acceleration onto the unit vector of v3 is decreasing, then we might infer that the car is going up a slope. Again, this would just be a guess which could very well be wrong. I say could, but what I mean is that it will be wrong sometimes.
That's about as much information as I can envision getting out of a system that just uses the accelerometer. Good luck!
Some thoughts:
If it were me, I'd write up a disclaimer that says "This doesn't work on hills, use a straight, level road for testing."
P.S.: I like the cash reward for answers, I'll be sure and post that as a suggestion on meta.stackoverflow.com :P
To solve this, if possible, you would need to reference something external to the car. Probably using the GPS to measure elevation gain is the most direct approach. That is, calculate the slope of the hill using the measured elevation gain, and use this to compensate the acceleration measurement.
As others have mentioned, at a very deep level, there's no way to distinguish between gravity and acceleration; this is known as the Equivalence Principle (and was one of Einstein's most important insights). So one would need to know more than the accelerometer's output to solve this problem, and this makes the problem difficult. For various approaches to the problem, see here.
Your best hope is to reference something external to the car, like a GPS signal, or pictures to measure the change in the location of something outside the car, or the earth's magnetic field, etc. Since this will take place near a lot of metal (the car) the earth's field will likely be difficult to measure, and continuous photos of some reference object (like the sun) is obviously difficult, so it seems that the GPS is your best bet.
More on why you need an external reference:
It's worth considering whether you could use the unique features of gravity that 1) it's always “on”, 2) it always has the same magnitude (for this situation). But when all you know is the total acceleration, you can't reliably separate the two contributions. As the picture below shows, just knowing the magnitude of gravity isn't enough... the picture below is drawn in the phone's frame of reference where it measures the resultant acceleration (black vector), and the larger colored arrows are possible gravity vectors, while the matching color smaller arrows are the corresponding acceleration vectors. So you can see, without knowing and angle, you don't have enough information to solve the problem.
The other thing you might be able to do is integrate the output from a gyro to find the angle of the gravity vector. That is, assuming that you start on the flat, and then you always keep track of the where you think gravity would be based on the accumulated small changes. But this is highly error prone, and your error in the calculation will accumulate quickly with time; and it also assumes that you have access to a gyro.
Therefore, the only good solution is to use external information.
You need a gyro. Otherwise there are multiple configurations of an accelerating car on a hill that can give rise to exactly the same readings on an accelerometer. They will be completely impossible to distinguish. That's why inertial navigation systems combine a gyro and accelerometer.
The reason you can't do this was given by Einstein! Using a local measurement, you can't distinguish between gravity and acceleration. You do have some useful non-local information - the assumption that gravity here, and gravity a few yards over there, have the same value. But you can't compare gravity in two different locations without a means to carry out what's called "parallel transport". This is what a gyro does.
Forget the $250, but I think you should give me a beer for the amount of R&D time I'm saving you. :-)
@The Gazzardian,
So your essential problem as I understand is to detect the forward vector. You can opt these:
Consult this figure to detect the angle: Angles and Hills http://lh6.ggpht.com/_p7FIkTnaSc4/S9kkKF7oECI/AAAAAAAABYg/D1tbxNQXo0E/s288/Hill.png
Another possible method, is to find the extra force during the climbing of the hill. Given the extra force, you might be able to find the angle. The vertical component of the extra force is to counter, the vertical component in opposite direction, g.