日本語 English

Attitude control

This page explains the attitude control library for the OMRON NX/NJ series.
It introduces 3D rotation calculation and coordinate transformation using Euler angles, quaternions and rotation matrices.

What Is Attitude Control?

Attitude control is the technology of controlling the orientation of an object.
It is used in robot arms, AGVs, drones, industrial machinery and more. Euler angles, rotation matrices, quaternions and so on are used to express orientation in 3D space.

Calculating Attitude with Euler Angles

Advantages of Euler angles

  • Easy to understand
  • Angles are easy for people to handle
  • Easy to implement on PLCs

Disadvantages of Euler angles

  • Gimbal lock occurs
  • Interpolation is difficult

Rotation example

Euler angles X axis = 50 degrees, Y axis = 50 degrees, Z axis = 50 degrees
Example of XYZ-type rotation in the body coordinate system
This video explains the calculation steps; the actual calculation computes the final position (red) directly from the initial position

Image of rotating in XYZ order

Euler angles

Consider the nose direction of a paper airplane as the X axis, the wing direction as the Y axis and the vertical fin direction as the Z axis
To change the attitude, each of the X, Y and Z axes is rotated, and the X, Y and Z rotation angles together are called Euler angles

Types of Euler angles

There are 12 types of Euler angles depending on the rotation order, and changing the order changes the result

Euler angle rotation orders
X Y Z X Y X
X Z Y X Z X
Y X Z Y X Y
Y Z X Y Z Y
Z X Y Z X Z
Z Y X Z Y Z

Body coordinate system and fixed coordinate system

The body coordinate system calculates in the object's own coordinates, so that the nose of the paper airplane is always the X axis direction, while the fixed coordinate system calculates around fixed coordinate axes
In this library, the body coordinate system can be calculated with EulerToMatrix and matRotate3D, and the fixed coordinate system with matRotateXYZ

Points to note

Conversion with Euler angles can cause gimbal lock
Gimbal lock is a phenomenon in which two rotation axes point in the same direction during coordinate transformation, reducing three axes to two so that the lost axis can no longer rotate
It is avoided by changing the rotation order

About the paper airplane

About the paper airplane
The paper airplane shape is rotated by calculating the rotation of 5 points

By the way

This video is a recording of graphs made in Python for explanation

Calculating Attitude with Quaternions

Advantages of quaternions

  • No gimbal lock
  • Easy rotation interpolation
  • Fast to calculate
  • Widely used in robot control
Rotation with quaternions
3D rotation with Euler angles

Quaternion

Expresses a rotation with four components made of a rotation axis (3D vector) and a rotation angle
Unlike Euler angles, gimbal lock does not occur
Also, quaternion calculations are simple, reducing computational cost and allowing fast calculation

Concept

To go from the current attitude to the target attitude, you only need to determine the rotation axis and rotation angle to rotate into the target attitude
This works for any target orientation
Considering the rotation of one point gives the following figure

Rotation of one point
Quaternion rotation axis

Rotating each of the 5 points of the paper airplane around the rotation axis gives the following

Rotation of 5 points
Rotation of 5 points

How to find the rotation axis and rotation angle

Quaternion of the initial position \[ Q1= \begin{bmatrix} q_w\\ q_x\\ q_y\\ q_z \end{bmatrix} = \begin{bmatrix} 0\\ point.x\\ point.y\\ point.z \end{bmatrix} \]
Convert the Euler angles of the target position to a quaternion \[ Q2=EulerToQuaternion(th, order) \]
Rotation angle \[ \theta=2\arccos(Q2.real) \]
Rotation axis (unit vector) \[ T= \frac{Q2.img}{norm(Q2.img)} \]
Quaternion representing the rotation \[ \begin{align} R.real&=\cos\frac{\theta}{2} \qquad (rotation angle)\\ R.imag&=T\times\sin\frac{\theta}{2} \qquad (rotation axis) \end{align} \]
Rotation calculation \[ out=R\times Q1\times\bar{R} \]

Relationship between the rotation axis and rotation angle

A quaternion expresses a rotation axis and rotation angle with four values.

FAQ

What is the difference between Euler angles and quaternions?

Euler angles express orientation with angles, while quaternions express it with a rotation axis and rotation amount.

What is gimbal lock?

A loss of a degree of freedom that occurs with Euler angles.

Which is used in industrial robots?

Quaternions and rotation matrices are often used for internal calculations.

Comments