Accelerometer Coordinate system 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

1 Comment

Are these three values the roll, pitch and yaw angles?

Sign in to comment.

 Accepted Answer

Jim Riggs
Jim Riggs on 24 Jan 2019
Edited: Jim Riggs on 24 Jan 2019
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

8 Comments

Jim Riggs
Jim Riggs on 25 Jan 2019
Edited: Jim Riggs on 27 Jan 2019
Here is an illustration to show why the three planar rotations are not commutative:
Start with reference frame A. Rotate about the A-Frame Z axis through angle Psi to position B-double-prime (B"). From this position, rotate through angle theta about the B" Y axis to get to position B-prime (B'). From this position, rotate about the x axis in the B-prime frame through angle phi to arrive at the final position B (in red). (Each rotation in the illustration is shown in the positive direction)
MatlabAnswers 20190124b.JPG
Note that the first rotation (angle Psi) is defined in the A-frame.
The second rotation (Theta) is defined in the B-double-prime frame
And the third rotation (phi) is defined in the B-prime frame. This explains why the rotation sequence is not commutative, since each rotation angle is implicitly defined in a different frame.
Matrix T, above, embodies these three sequential rotations.
Hi Jim Riggs
I know your answer is a couple of years old, but i would like to ask if this transformation matrix can be used in the same way if you use an IMU with both accelerometer and gyroscope data, to rotate a vector of gyroscope data (rad/s) data into the inertial frame as well? :)
And do you just take a vector of for example acc_x * T, where acc_x is (acc_x_1, acc_x_2, acc_x_3, acc_x_4, n...)?
Hope my question makes sense
The matrix T above is a 3 x 3 transformatiion matrix, also referred to as a "direction cosine matrix" (or DCM). This process applies to any vector quantity. Any vector in frame A can be expressed in frame B by multiplying it by the transformation matrix. The vector can be a position vector, velocity vector, acceleration vector, angular rotation, etc. It's all the same. However, here the "vector", is defined as a 3-vector, and represents a 3-dimentional quantity. E.g. a position vector "P" in frame A might be defined as PA = {Pxi, Pyj, Pzk} where Px represents the quantity of the projection of vector P on the x axis in frame A, and this axis is aligned with unit vector i. Py is the quantity of the projection of P on the Y axis in frame A, which is aligned with unit vector j, etc. We denote it as vector PA to remind us that vector P is being described in the "A" frame, and the A-frame basis vectors (i, j, k) apply.
Now suppose that frame B is defined to have basis vectors of i', j', k' along the B-frame X, Y, and Z axes.
When you multiply vector PA by the transformation matrix, what you are actually doing is exchanging basis vectors (i, j, k) from frame A with the basis vectors from frame B (i', j', k').
PB = [T] * PA. PB is now the same position vector P, but now expressed in frame B (and has basis vectors from frame B) So vector PB might be expressed as {Pai', Pbj', Pck' } where Pa is the quantity of the projection of vector P on the x-axis of frame B, and this axis is aligned with unit vector i'. Likewise Pb is the projection of vector P on the Y-axis of the B frame, which is aligned with unit vector j', etc.
The vector P has not changed - it has simply been distributed into 2 different sets of 3 mutually orthoganal segments - one set aligned with frame A and one set aligned with frame B. The mathematical operation of computing {Pa, Pb, Pc} from {Px, Py, Pz} is called a coordinate transformation.
The point is, this type of 3-dimentional transformation is only defined for a 3-vector. The vector always has 3 components, both before and after the transformation process.
Hi Jim Riggs, thanks a lot for a quick and very well explained answer, thanks a lot! I am now on to the next step in my data analysis script!
/Jens
Hi Jim Riggs
I would like to know how to determine the correct order of the rotation in setting up the transformation matrix. I hope you can expound on that.
Also, suppose I have an accelerometer data from a smartphone whose orientation varied with each sample, do I simply create a loop that determines the transformation matrix for each sample then rotate it to the inertial frame?
Thank you very much.
Jim Riggs
Jim Riggs on 11 Nov 2022
Edited: Jim Riggs on 12 Nov 2022
This is a good question.
In general, there is no "correct" order, but often the problem will suggest a best or a "most intuitive" approach. The rotation sequence might be selected based on some critera such as the user community convention - for example in aerospace community, we like to define a coordinate system for an air vehicle body with the Z-axis pointing "down" and use YAW-PITCH-ROLL (Z-Y-X) sequence to describe the orientation of an air vehicle with respect to the ground. The Z-rotation is the heading of the aircraft and the Y-rotation is the "pitch" angle of the aircraft with respect to the ground, so these are convenient angle conventions for describing the motion of a vehicle in flight.
But other times the problem geometry will dictate the best sequence. In the example in the figure, below, there is a camera system with 2 axes of rotation. Suppose that the coordinate system for the camera is defined with the Z-axis along the boresight of the camera. The camera rotates on an "elevation" axis (up & down) and on an "Azimuth" axis (side to side). These are defined as the X and Y axes, respectively. Notice that the elevation (X) axis is mounted in such a way that it's orientation moves when the azimuth angle is changed. We say that the elevation axis is "inside" the azimuth axis because movement of the azimuth effects the elevation axis. But movement of the elevation axis does not effect the azimuth axis. In this case the azimuth rotation is first, then the elevation rotation. Think of it as matrix pre-multiplication: Azimuth * Elevation. (Azimuth effects elevation) Due to the axis definitions for the camera reference frame this is a Y-X rotation sequence.
Now suppose that the camera can also rotate on a third axis (Roll axis) about the boresight. This is a rotation about its Z-axis. This axis is "inside" the elevation axis and is effected by the elevation rotation and the azimuth rotation. So now the rotation sequence is Azimuth * Elevation * Roll or Y-X-Z
Now suppose that I re-define the camera reference frame such that the X-axis is along the camera boresight, the elevation axis is the Y-axis, and the azimuth rotation is the Z-axis. Now the transformation would be a Z-Y (or Z-Y-X) rotation seqience.
The main requirement is that the reference frame is a right-handed, orthogonal system. You are free to orient it however you like, and the rotation sequence is dictated by the gimbal geometry.
Note: See also my discussion on the direction of the transformation here
@Jim Riggs thank you for the thoughtful answer and comments — it's helped me to better understand coordinate transformations. Does the approach you mention in the accepted answer and comments suffer from gimbal lock?
Jim Riggs
Jim Riggs on 8 Apr 2023
Edited: Jim Riggs on 8 Apr 2023
No, not really. This discussion pertains to how a vector can be represented in one or more reference frames.
Gimbal lock is a phenomenon associated with resolving angular motion. In the days of mechanical gimbals, it was possible for an aircraft to get into an orientation where two of the gimbal axes were parallel with each other. At this point, the system could not determine which of these two axes the motion was to be assigned. It eliminates one degree of freedom from the 3-axis rotation equations and the motion becomes indeterminant.
Modern navigation systems use strapdown sensor suites with sensing axes that always remain orthogonal, so the motion is always resolvable in 3 dimensions. There are no 'gimbals'. The trick is in the mathematics of how the angle changes are resolved. One popular approach is to use a quaternion. This is a mathematical device for expressing angles in 3 dimensions and has no singularities. (=Gimbal lock problem solved using mathematical algorithms)
So the subject of gimbal lock pertains to how a vehicle orientation angles are resolved in 3 dimensions.
Our discussion in this answer involves how a given vector in one reference frame is expressed in a different frame.
[EDIT] OK I see how I may have initiated some confusion in this area. I used an example of a gimballed system, above, to illustrate how some situations have implied relationships between the different axes with respect to rotation. In the most general sense, you may construct a 3-dimentional direction cosine matrix using 3 planar rotations, and you can do this using just about any sequence that you want. But in a system using mechanical gimbals, one axis is attached to another axis and it moves when the axis it is attached to moves. This implies a specific sequence - the outer gimbal motion effects the inner one, but the inner gimbal movement has no effect on the outer one. This is a case where the sequence of rotations used is dictated by the system architecture. The point I am trying to make is that constructing a direction cosine matrix from planar Euler rotations provides many options in the general case and you are free to choose, but sometimes the problem geometry will dictate an appropriate sequence.

Sign in to comment.

More Answers (0)

Asked:

on 24 Jan 2019

Edited:

on 8 Apr 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!