If you use a sixaxis 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 endeffector (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 endeffector, or more precisely of theTCP（tool center point）那is typically defined as theX那yandZ.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 threedimensional 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.
欧拉角的详细定义
到目前为止，最常见的方式将空间中的方向传送给用户，或者允许用户在CAD软件或机器人控制器中定义方向，是使用欧拉角。Because the term Euler angles is often misused, we have prepared this interactive tutorial.
"[…] the term Euler angles is often misused […]"
欧拉角are a set (or rather a sequence) of three angles, which can be denoted for example byα那β那andγ。（Often, Euler angles are denoted by卷那pitch那and偏航。）欧拉角are defined as follows: Consider two Cartesian righthanded 3D reference frames, of which one will be arbitrarily called the fixed frame and the other will be referred to as the mobile frame. The two reference frames coincide initially. To define the orientation of a third frame (all three frames share the same origin), the mobile frame is brought, in the order shown below, to coincide with the third frame by rotating the mobile frame
 about theX那y， 或者Z.固定框架的轴或X'那y'， 或者Z.'of the mobile frame, byαdegrees,
 then about theX那y， 或者Z.固定框架的轴或X'那y'， 或者Z.'of the mobile frame, byβdegrees,
 and finally about theX那y， 或者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 (6^{3.}）possible sequences:X→y→Z.那y→y→Z.那Z.→y→Z.那X'→y→Z.那y'→y→Z.那Z.'→y→Z.等等。然而，三个旋转的序列，其中两个连续旋转围绕相同的轴（例如，y→y→Z.）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.→y→X那X'→y'→Z.'那y→Z.'→Xandy→X→Z.'。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 likey→Z.'→Xandy→X→Z.'）。
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 theX→y→Z.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 sixaxis 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 theX那y那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 doubleclick 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._{X}（0.°)R._{X}（0.°)R._{X}（0.°) = 

通过旋转矩阵计算欧拉角
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}（α）= 

R._{y}（β）= 

R._{Z.}（γ）= 

我们将参考上述矩阵基本旋转矩阵。To obtain the product of basic rotation matrices that corresponds to a sequence of rotations, start by writing the basic rotation matrix corresponding to the first rotation. For example, if the first rotation is about theX（或者X'）axis, then writeR.X（ψ）， 在哪里ψ旋转的角度。对于每一个后续的腐烂ation, postmultiply (right multiply) the current result with the next rotation matrix, if the rotation is about an axis of the mobile reference frame, or premultiply (left multiply) the current result with the next rotation matrix, if the rotation is about an axis of the fixed reference frame. Use our applet to see the resulting product of basic rotation matrices. For example, the rotation sequenceX'→y'→Z.'corresponds to the productR.=R.X（α）R.y（β）R.Z.（γ）。Thus, the rotation matrix that corresponds to the Euler angles used by Mecademic is:
R.（α那β那γ）= 

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}（φ）= 

或者，我们可以直接获得上述旋转矩阵。其第一，第二和第三列代表了单位向量的坐标X那yandZ.axis, respectively, of frameF'，关于框架F。
现在您拥有代表所需方向的旋转矩阵，只需解决九个标量三角式方程的系统R._{期望}=R.（α那β那γ）， 为了α那β那andγ。Fortunately, this problem has a generic solution and we'll simply give you the equations to use.
让框架的预期方向F'with respect to a frameFbe represented by the following rotation matrix:
R._{期望}= 

欧拉角(度),符合mobile XYZ convention used by Mecademic, are then obtained according to the following two cases:
Case 1:R._{1那3.}≠ ±1 (i.e., theZ.'框架轴F'is not parallel to theX框架轴F）。
β=asin(R._{1那3.}）那γ= atan2（R._{1那2}那R._{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那1}那R._{2那2}）那α=0.。
In the general Case 1, we actually have two sets of solutions where all angles are in the halfopen 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）的函数。请注意，在某些科学计算器和大多数电子表格软件中，在某些科学计算器中，此功能的参数倒置。
最后，注意情况2对应于所谓的表示奇点。This singularity is present in any threeparameter representation of orientation in 3D space (not only in Mecademic's choice of Euler angles). It is similar to the problem of representing points on a sphere by only two parameters. For example, longitude is not defined on Earth at the South and North Poles on the Earth. In other words, this singularity has nothing to do the singularities of mechanisms (e.g., the socalledgimbal lock）那which correspond to actual physical problems (e.g., the loss of a degree of freedom).
锻炼
Consider the following reallife situation that occured to us. We wanted to attach a FISNAR dispensing valve to the endeffector 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°.
上图显示了所需的实际安装（左）和工具框架（右）。请注意，使用AxiyseMetric工具时，它是一个常见的做法，可以实现工具Z.axis with the axis of the tool. This is particularly useful with the mobile XYZ Euler angle convention, since the redutant rotation about the axisymmetric tool corresponds to the third Euler angle,γ。因此，前两个欧拉角限定工具的轴线，而第三则可以用于选择机器人的最佳配置（即，远离奇点）。
“当使用axisymmetric工具,它是一种常见的公关actice to allign the tool zaxis 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 frameF和Z.'框架轴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 endeffector in space to several positions. At some positions, because of numerical noise, the controller does not detect the condition r_{1那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 √(ΔX^{2}+Δy^{2}+ΔZ.^{2}），取向误差与欧拉角的变化直接相关，尤其接近表示奇点。为了更好地理解欧拉角的这种所谓的非欧几里德性质，考虑用于表示地球上的位置的球形坐标。在北极，纬度为90°（北），但经验是什么？经度没有在北极定义，或者它可以是任何值。现在想象一下，我们在格林威治的方向上距离北极仅1毫米。在这种情况下，纬度将是89.99999999°，但经度现在将具有0°的值。想象一下，你再次返回到北极并向东京方向移动1毫米。新的经度约为140°。在两个位置之间，经度的错误是140°！但是，实际角度误差约为0.00000002°。
上述情况在所有其他欧拉角惯例中类似。根据欧拉角度惯例，在特定帧轴线时发生不断的表示奇点F'is parallel to another specific axis of frame F. In such a representation singularity, the first and third rotation become dependant.
总之，除非您掌握欧拉角（或使用复杂的离线编程软件），更具体地说是用于编程机器人的惯例，否则您几乎不会能够编程任何简单的挑选和放置操作。因为机器人并不简单，我们尽力帮助您了解基础知识。
©Mexademade在全部或部分地重现本教程，严格禁止。