If you use a six-axis robot arm, like Mecademic's Meca500 used in this tutorial as an example, you are most probably interested in positioning its tool (结束效应）以各种方向。换句话说，您需要能够将其机器人编程以将其末端效应器移动到所需位置和所需的方向（即，到所需的位置姿势）。当然，您可以随时慢慢慢跑您的机器人的末端效应器或将其手指导到大约所需的姿势，但是这所谓的online programming method是乏味的，非常不精确。计算和定义所需的姿势更有效。此外，为了定义tool reference frameassociated with your end-effector (as in the figure shown below), you would need to calculate the pose of that tool reference frame with respect to theflange reference frame

In 3D space, you need a minimum of six parameters to define a pose. For example, the position of the robot's end-effector, or more precisely of theTCPtool center point）那is typically defined as theXyandZ.coordinates of the origin of the tool reference frame with respect to the世界参考框架。But how do you then define orientation in space?

"The representation of orientation in space is a complex issue."

The representation of orientation in space is a complex issue.Euler's rotation theoremstates that, in (3D) space, any displacement of a rigid body in such way that a point on the rigid body remains fixed is equivalent to a single rotation about an axis that passes through the fixed point. Accordingly, such rotation can be described by three independent parameters: two for describing the axis and one for the rotation angle. Orientation in space, however, can be represented in several other ways, each with its own advantages and disadvantages. Some of these representations use more than the necessary minimum of three parameters.

The most common way of transforming position coordinates from one Cartesian (3D) reference frame,F，另一个，F'那is the rotation matrix. This 3×3 matrix can therefore be used to represent the orientation of reference frameF'with respect to reference frameF。However, this representation, while often necessary as we will discover later, is not a compact and intuitive way to define orientation.

Another much more compact way of defining orientation is the quaternion. This form of representation consists of a normalized vector of four scalars. The quaternion is generally used in robot controllers, as it is not only more compact than the rotation matrix, but also less susceptible to approximation errors. Moreover, during an interpolation between two different orientations, the elements of the quaternion continuously change, avoiding the discontinuities inherent in three-dimensional parameterizations such as Euler angles. Nevertheless, the quaternion is rarely used as a means of communication between a user and the controller of the robot because it is unintuitive.

## 欧拉角的详细定义

"[…] the term Euler angles is often misused […]"

1. about theXy， 或者Z.固定框架的轴或X'y'， 或者Z.'of the mobile frame, byαdegrees,
2. then about theXy， 或者Z.固定框架的轴或X'y'， 或者Z.'of the mobile frame, byβdegrees,
3. and finally about theXy， 或者Z.固定框架的轴或X'y'， 或者Z.'of the mobile frame, byγdegrees.

The order in which the three rotations is done is important. Thus, we have a total of 216 (63.）possible sequences:XyZ.yyZ.Z.yZ.X'yZ.y'yZ.Z.'yZ.等等。然而，三个旋转的序列，其中两个连续旋转围绕相同的轴（例如，yyZ.）cannot describe a general orientation. In addition, prior to the first rotation,Xcoincides withX'ycoincides withy'那andZ.coincides withZ.'。Consequently, of all these 216 combinations, there exist only twelve unique meaningful ordered sequences of rotations, or twelve Euler angle conventions: XYX, XYZ, XZX, XZY, YXY, YXZ, YZX, YZY, ZXY, ZXZ, ZYX, ZYZ.

That said, each of the twelve combinations is equivalent to three other sequences. In other words, each Euler angle convention can be described in four different ways. For example, the ZYX convention is equivalent to the sequencesZ.yXX'y'Z.'yZ.'XandyXZ.'。Fortunately, no one describes Euler angles with sequences in which some rotations are about the mobile frame axes and others are about the fixed axes (e.g., sequences likeyZ.'XandyXZ.'）。

Thus, while there are twelve different Euler angle conventions, each is typically described in two different ways: either as a sequence of rotations about the axes of the fixed frame or as a sequence of rotations about the axes of the mobile frame. Therefore, it can be convenient to talk about fixed and mobile conventions, although they are equivalent. For example, the fixed XYZ Euler angle convention is described by theXyZ.sequence, while the mobile ZYX Euler angle convention is described by theZ.'y'X'sequence, but both are equivalent, as we will see later.

In robotics, FANUC and KUKA use the fixed XYZ Euler angle convention, while ABB uses the mobile ZYX Euler angle convention. Furthermore, Kawasaki, Omron Adept Technologies and Stäubli use the mobile ZYZ Euler angle convention. Finally, the Euler angles used in CATIA and SolidWorks are described by the mobile ZYZ Euler angle convention.

“在熟悉的情况下，我们使用移动XYZ欧拉角度约定。”

At Mecademic, we use the mobile XYZ Euler angle convention, and therefore describe Euler angles as the sequenceX'y'Z.'。Why be different? The reason is that we used to offer a mechanical gripper for handling axisymmetric workpieces (see video）那which was actuated by the motor of joint 6. A six-axis robot equipped with such a gripper can only control two rotational degrees of freedom, or more specifically the direction of the axis of joint 6, that is to say the direction of the axis of symmetry of the workpiece. In the chosen Euler angle convention, anglesαandβdefine this direction, while angleγis ignored because it corresponds to a parasitic rotation that is uncontrollable.

Our applet below will help you understand Euler angles. You can select one of the twelve possible Euler angle conventions by clicking on theXy那andZ.boxes of the first, second and third rotation. (The default Euler angle sequence is the one used by Mecademic.) To switch between rotations about the axes of the fixed or mobile frames, you need to double-click on any of these nine boxes. The axes of the fixed frame are drawn in gray while the axes of the mobile frame are in black. AxesXandX'are drawn in red,yandy'in green, andZ.andZ.'in blue. Gliding along any of the three blue horizontal arrows with your mouse changes the corresponding Euler angle. Alternatively, you can directly set the Euler angle value (in degrees) in the corresponding textbox below the arrow. Finally, you can drag your mouse over the reference frame to change the viewpoint.

 α： β： γ：
R.=R.X0.°)R.X0.°)R.X0.°) =
 n/a n/a n/a n/a n/a n/a n/a n/a n/a

## 通过旋转矩阵计算欧拉角

With the above applet, you will see the orientation of the mobile frame with respect to the fixed frame, for a given set of Euler angles, in the far right subfigure. Unfortunately, however, in practice, the situation is usually the opposite. You frequently have two reference frames, and you want to find the Euler angles that describe the orientation of one frame with respect to the other.

For orientations in which at least two axes are parallel, you could attempt to guess the Euler angles by trial and error. For example, look back at the image at the beginning of this tutorial and try to find the Euler angles used by Mecademic that define the orientation of the tool reference frame associated with the gripper, with respect to the flange reference frame. The answer isα= -90°那β= 0°，γ= -90°。Not so easy to get, is it? To be more efficient therefore, you must learn about rotation matrices after all.

As we have already mentioned, any orientation in space can be represented with a 3×3 rotation matrix. For example, a rotation ofα关于轴X那a rotation ofβ关于轴y和旋转γ关于轴Z.，分别对应于以下三个旋转矩阵：

R.Xα）=
 1 0. 0. 0 cos(α） -罪（α） 0 罪（α） cos(α）
R.yβ）=
 cos(β） 0 罪（β） 0. 1 0. -罪（β） 0 cos(β）
R.Z.γ）=
 cos(γ） -罪（γ） 0 罪（γ） cos(γ） 0 0. 0. 1

R.αβγ）=
 cos(β）cos(γ） -cos(β）罪（γ） 罪（β） cos(α）罪（γ）+罪（α）罪（β）cos(γ） cos(α）cos(γ） - 罪（α）罪（β）罪（γ） -罪（α）cos(β） 罪（α）罪（γ）-cos(α）罪（β）cos(γ） 罪（α）cos(γ）+cos(α）罪（β）罪（γ） cos(α）cos(β）

Therefore, for a given orientation, you will need to do two things: First, you need to find the rotation matrix that corresponds to your orientation. Second, you need to extract the Euler angles using a couple of simple equations. Let us first show you two ways to find your rotation matrix.

Consider the example shown in the figure below where we need to find the rotation matrix representing the orientation of frameF'with respect to frameF。（R.ecall that we always represent theXaxis in red, theyaxis in green, and theZ.轴是蓝色的。）

Here, it is easy to see that if we align a third reference frame with theF，这将充当移动帧，然后旋转此框架Z.'轴at.θ-90°, and then rotate it about itsy'轴at.φdegrees, we will obtain the orientation ofF'。Thus, the rotation matrix we are looking for is:

R.期望=R.Z.θ-90°)R.yφ）=
 罪（θ）cos(φ） cos(θ） 罪（θ）罪（φ） -cos(θ）cos(φ） 罪（θ） -cos(θ）罪（φ） -罪（φ） 0. cos(φ）

R.期望=
 R.1那1 R.1那2 R.1那3. R.2那1 R.2那2 R.2那3. R.3.那1 R.3.那2 R.3.那3.

Case 1:R.1那3.≠ ±1 (i.e., theZ.'框架轴F'is not parallel to theX框架轴F）。

β=asin(R.1那3.）那γ= atan2（-R.1那2R.1那1）那α= atan2（-R.2那3.R.3.那3.）。

Case 2:R.1那3.=±1 (i.e., theZ.'框架轴F'is parallel to theX框架轴F）。

β=R.1那3.90°,γ= atan2（R.2那1R.2那2）那α=0.。

In the general Case 1, we actually have two sets of solutions where all angles are in the half-open range (−180°, 180°]. However, it is useless to calculate both sets of solutions, so only the first is presented, in which −90° <β<90°。另请注意，我们在我们的解决方案中使用Atan2（y，x）的函数。请注意，在某些科学计算器和大多数电子表格软件中，在某些科学计算器中，此功能的参数倒置。

## 锻炼

Consider the following real-life situation that occured to us. We wanted to attach a FISNAR dispensing valve to the end-effector of ourMECA500.R.obot arm. Naturally, the engineer who designed and machined the adapter didn't care about Euler angles and was only concerned with machinability and reachability. In his design, there were essentially two rotations of 45°. Firstly, he used two diametrically oposite threaded holes on the robot flange to attach the adapter, which caused the first rotation of 45°. Secondly, the angle between the flange interface plane and the axis of the dispenser was 45°.

“当使用axi-symmetric工具,它是一种常见的公关actice to allign the tool z-axis with the axis of the tool."

R.eturning to our example, we will show now that it is impossible to come up with the Euler angles according to the mobile XYZ convention by trial and error. Indeed, for this choice of tool reference frame, we can represent the final orientation as a sequence of the following two rotations:R.=R.Z.（45°)R.y（45°). From here, we can extract the Euler angles according to the mobile XYZ convention using the equations previously described and obtain:α=-3.5.264°,β=3.0.。0.0.0.°,γ= 54.735°。你现在确信你是否需要掌握这样的情况的欧拉角？

## 代表奇点和定向误差

In the case of the mobile XYZ Euler angle convention, if theZ.'框架轴F'is parallel to theX框架轴F，有无限的对αandγthat will define the same orientation. Obviously, you only need one to define your desired orientation, so we have arbitrarily setαto be equal to zero. More specifically, ifβ=90°, then any combination ofαandγ那such thanα+γ=φ那whereφ是任何值，将对应于相同的方向，并由Mexmade的控制器输出为{0,90°，φ}。同样，如果β= -90°那then any combination ofαandγ那such thatα-γ=φ那whereφis any value, will correspond to the same orientation, and be output by Mecademic's controller as {0, −90°, −φ}。但请注意，如果您尝试代表帧的方向F'with respect to a frameFZ.'框架轴F'几乎平行于X框架轴F（i.e.,βis very close to ±90°), the Euler angles will be very sensitive to numerical errors. In such a case, you should enter as many digits after the decimal point as possible when defining the orientation using Euler angles.

Consider the following situation which has caused worries to several users of our Meca500. You set the orientation of the tool reference frame with respect to the world reference frame to {0°, 90°, 0°}, which is a representation singularity. Then you keep this orientation and move the end-effector in space to several positions. At some positions, because of numerical noise, the controller does not detect the condition r1那3.=±1 (Case 2, as mentioned above) and calculates the Euler angles as if the orientation did not correspond to a representation singularity. Thus, the controller returns something like {41.345°, 90.001°, −41.345°}, which seems totally wrong and very far away from {0°, 90°, 0°}. Well it's not.

Unlike position errors, which are measured as √(ΔX2y2Z.2），取向误差与欧拉角的变化直接相关，尤其接近表示奇点。为了更好地理解欧拉角的这种所谓的非欧几里德性质，考虑用于表示地球上的位置的球形坐标。在北极，纬度为90°（北），但经验是什么？经度没有在北极定义，或者它可以是任何值。现在想象一下，我们在格林威治的方向上距离北极仅1毫米。在这种情况下，纬度将是89.99999999°，但经度现在将具有0°的值。想象一下，你再次返回到北极并向东京方向移动1毫米。新的经度约为140°。在两个位置之间，经度的错误是140°！但是，实际角度误差约为0.00000002°。