Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calibration of a 3-Axis Accelerometer for fixing effect of gravity

  1. Jan 15, 2010 #1
    Hi all,

    I've been trying to develop this excel macro for mapping out a train track and locating kinks.
    It's been going well so far except that when the accelerometer is not exactly level with the ground, the acceleration due to gravity (9.8 m/s^2) is not only effective in the z-direction, but in the x and y as well since the whole co-ordinate system of the accelerometer is tilted.

    Now, I have the x-tilt and the y-tilt angles and am trying to fix this problem.
    Please have a look at the excel sheets I have attached. Starting from row 13 in B, C and D, I have the acceleration values in g (with 1g = 9.8m/s^w) and the tilt angles are in columns G and H.

    I've thought about this for a while and came up with the following formulas for acceleration.

    new_x_acceleration = old_x_acceleration + sin(x_tilt)
    new_y_acceleration = old_y_acceleration + sin(y_tilt)
    new_z_acceleration = sqrt (1 - (new_x_acceleration)^2 - (new_y_acceleration)^2)

    These seem right but when I apply these formulas (run the calibrator macro i programmed replaces the originals) the values seem very implausible. They are on the order of 10^-16 or less.

    Any thoughts on what I'm doing wrong?

    Attached Files:

  2. jcsd
  3. Jan 18, 2010 #2
  4. Jan 18, 2010 #3
    The reason no one has helped is because it a difficult problem to be sure we got it right.
    Your right angle trig is royally messed up.

    Problem repeat and simplification:
    x,y,z vector in rotated vector
    x,y angle from true x and y
    Find: x,y,z in true vertical

    VM (g) in column G is total acceleration or rho.

    It is going to take a lot of thought to figure out new_x and new_y. I can tell you yours are wrong because you are adding an acceleration and a unitless ratio. You can multiply mismatched units together, but you can't add them.
  5. Jan 19, 2010 #4
    Thank you for your response.
    Yes, I realized the solution couldn't be that simple.

    I think the solution can be given using a rotation matrix. However, this is not my area of expertise. I was wondering if anyone here could suggest a possible solution.

    So far, what I'm thinking is, I should find the rotation matrix according to the x and y tilts. Take the inverse of it and multiply it by the matrix of xyz accelerations I have to find the original axis value (before the rotation). I've tried this but it's still not working out as I'm getting values that are even farther from 0 for x and y acceleration.
  6. Jan 19, 2010 #5
    How far off? Let's what else you have come up with. We may say that the "off" numbers are in fact correct. Or we might realize what the correct solution is because you can so close.
  7. Jan 19, 2010 #6

    Okay, they are very far off. I have attached the excel sheet containing the rotation matrices and the final calibrated answers.

    P1:R3 (yellow cells) contain the Rz matrix since (x-tilt is the rotation about the z-axis). T1:V3 (green cells) contain the Rx matrix (y-tilt is the rotation about the x-axis). X1:Z3 (red cells) contain the multiplication of the two (Rx * Ry). X4:Z6 (blue) contain the inverse of this multiplication and AD1:AD3 (purple) contain the final calibrated answers (inverse*xyz).

    These values are calculated for the row 13 values. I have written a VBA code for this calculation [Sub pitchroll2()]

    Please get back to me with your thoughts on this.

    Attached Files:

    Last edited: Jan 19, 2010
  8. Jan 19, 2010 #7
    You need a course in linear algebra or matrix algebra. That matrix in red is a singular matrix, it has no inverse. But that is a correct multiplication of matrices.
    X-tilt is rotation about the y-axis. Rotation about the z-axis is yaw. x-axis goes right and y-axis goes up on the plane of the paper with the z-axis coming out of the paper. If you wish to draw the three axis on the paper, you must maintain this relationship. The two common ways to do are y right, z up, x down and left; and x right, y up, z down and left.

    I didn't poke your algorithm real hard but it looks like you are calculating roll and pitch and then multiplying them together. The problem with this is that that playing with roll and pitch in this manner works best when there is only roll or only pitch.
    The rotation matrix for 2 dimensions is as follows:
    It certainly looks like you used it in your algorithm.
    That looks a lot like the conversion matrix for going from Cartesian [tex]\hat{x}, \hat{y}, \hat{z}[/tex] to cylindrical [tex]\hat{s}, \hat{\phi}, \hat{z}[/tex] which is as follows:
    The conversion matrix for going from Cartesian [tex]\hat{x}, \hat{y}, \hat{z}[/tex] to cylindrical [tex]\hat{r}, \hat{\theta}, \hat{\phi}[/tex] is as follows:
    Theta is the angle from the z axis to the vector. Phi is the angle from the x axis to the projection of the vector onto the xy-plane. The trick to using this as a conversion matrix for this case is figuring out what theta and phi is, neither of which you posses, but you can find them.
  9. Jan 19, 2010 #8
    I can do this because the two angles produce a unitless ratio which is what arc trig functions take as arguments.
    Make sure that the angle is in the right quadrant as arctangent is rather ambiguous.
    Last edited: Jan 20, 2010
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Calibration of a 3-Axis Accelerometer for fixing effect of gravity
  1. Gravity Effects (Replies: 1)