MATLAB: Accelerometer Coordinate system rotation

accelerometercoordinate rotation

I am using accelerometers to measure body accelerations and am trying to rotate them to the global coordinate sysyem. As they are placed on the body they are slightly rotated. How do I rotate it to the global coordinate system so that all of the acc takes place in the Y(-9.81) and none in the x or z? I am able to calucate the roll and pitch angles using the Following values below:
x (ML)= 1.2332
y(SI)= -7.6718
z(AP)= 5.3360

Best Answer

In general, you can construct a 3-dimensional transformation matrix using a sequence of three 2-dimensional planar rotations. First, we have to define our terms.
We define Phi as the rotation angle about the X-axis
Theta is the rotation angle about the Y axis.
Psi is the rotation angle about the Z axis.
All rotations are performed according to the right-hand rule (positive rotation is a positive right-hand curl)
Reference frame A is fixed and used to observe the motion of frame B, so frame B is said to be displaced from frame A. Let's assume frame A is the inertial frame and B is the body frame.
(NOTE that the angles are defined as the displacement of B from A . Think about it as if B starts out in alignment with A, and the three rotation angles are used to describe how B moves from A)
Now you can define the 2 dimensional transformations that will rotatre a set of coordinates from the displaced frame (B) to the fixed reference frame (A).
ROLL = [1, 0, 0; 0, cos(Phi),-sin(Phi); 0, sin(Phi), cos(Phi)];
PITCH = [cos(Theta), 0, sin(Theta); 0, 1, 0; -sin(Theta), 0, cos(Theta)];
YAW = [cos(Psi), -sin(Psi), 0; sin(Psi), cos(Psi) 0; 0, 0, 1];
Now the three dimentional transformation matrix may be constructed by providing the appropriate sequence of the three planar rotations. Note that the order of the rotations is not commutative, so the problem geometry will dictate what order must be used. In aerospace systems, we usually construct the attitude of an aircraft using the Z-Y-X or YAW-PITCH-ROLL sequence. In this case, the transformation matrix T = YAW * PITCH * ROLL. This is usually accompanied by a frame where Z is the "down" axis. Then any vector in the displaced frame (V_measured) can be rotated into the Inertial frame by multiplying it by T:
V_inertial = T * V_measured.
If your system is using Y as the "down" axis, you might need to alter the rotation sequence. I can't tell without being able to visualize how you move the sensor to align with the inertial frame.
Also, to rotate a vector from the inertial frame to the sensor frame (i.e. the inverse rotation) simply use the transpose of T:
V_measured = T' * V_inertial