Detecting Acceleration in a car (iPhone Accelerometer)

后端 未结 5 692
一整个雨季
一整个雨季 2020-12-07 17:55

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 18:36

    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.

    Calibration

    1. Find a surface such that its degree of inclement is not appreciably changing.
    2. Find the acceleration vector when the car isn't moving with respect to the road. Record this full vector (x,y, and z components) as v1. g = |v1| is the magnitude of gravity which should stay the same throughout.
    3. Start to drive straight forward on the slope (up or down it, not to the side and of course a flat surface is great too).
    4. Record this full acceleration vector as v2.
    5. Find v3, the vector indicating forward motion, by taking v2 - v1 (subtracting off gravity).
    6. Find v4 = v3 x (v1 x v3) where x is the vector cross product.
    7. Find the unit vector of v4, v5 = v4 / |v4|

    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:

    1. Record the current acceleration vector, a.
    2. Find the dot product of a and v1, c = a . v1
    3. If c is less than g (as opposed to being equal to g), the car is on a slope. The angle of the slope is theta = arccos(c/g).

    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!

提交回复
热议问题