【Matlab 六自由度机器人】关于旋转的参数化(欧拉角、姿态角、四元数)的相关问题(附MATLAB代码辅助理解)

往期回顾

【主线】

  1. 建立机器人模型
  2. 运动学正解
  3. 基于蒙特卡洛法(Monte Carlo Method)构建工作空间

【补充说明】

  1. 关于灵活工作空间与可达工作空间的理解
  2. 关于改进型D-H参数(modified Denavit-Hartenberg)的详细建立步骤

前言

在本文中,将推导三种方式来表达任意旋转,其中每种方式仅需三个独立变量:欧拉角表示法姿态角表示法(滚动-俯仰-偏航)四元数表示法(转轴/角度)


以下是本篇文章正文内容,包含对欧拉角表示法、滚动-俯仰-偏航表示法及转轴/角度表示法定义的理解和相关代码的分步解析。

正文

一、欧拉角(Euler-angle)表示法

1. 定义

表示旋转矩阵的一种常用方法是使用欧拉角,其中有三个独立变量。考虑固定坐标系 o 0 x 0 y 0 z 0 o_0x_0y_0z_0 o0x0y0z0,以及旋转后的坐标系 o 1 x 1 y 1 z 1 o_1x_1y_1z_1 o1x1y1z1
我们可以使用三个欧拉角( ϕ , θ , ψ \phi,\theta,\psi ϕ,θ,ψ)来表示坐标系 o 1 x 1 y 1 z 1 o_1x_1y_1z_1 o1x1y1z1相对于坐标系 o 0 x 0 y 0 z 0 o_0x_0y_0z_0 o0x0y0z0的姿态,它们通过下列三个连续旋转得到。首先,绕当前 z z z轴旋转角度 ϕ \phi ϕ。然后,绕当前 y y y轴旋转角度 θ \theta θ。最后,绕当前 z z z轴旋转角度 ψ \psi ψ
注意!这里的旋转均是绕旋转后的坐标系来进行旋转
根据上述描述的旋转,列出以下旋转的对应矩阵。
R z , ϕ = [ c o s ϕ − s i n ϕ 0 s i n ϕ c o s ϕ 0 0 0 1 ] R_{z,\phi}= \left[ \begin{matrix} cos\phi& -sin\phi & 0 \\ sin\phi & cos\phi & 0\\ 0 & 0& 1\\ \end{matrix} \right] \\ Rz,ϕ=cosϕsinϕ0sinϕcosϕ0001 R y , θ = [ c o s θ 0 s i n θ 0 1 0 − s i n θ 0 c o s θ ] R_{y,\theta}= \left[ \begin{matrix} cos\theta & 0 & sin\theta \\ 0 & 1& 0\\ -sin\theta & 0& cos\theta \\ \end{matrix} \right] \\ Ry,θ=cosθ0sinθ010sinθ0cosθ R z , ψ = [ c o s ψ − s i n ψ 0 s i n ψ c o s ψ 0 0 0 1 ] R_{z,\psi}= \left[ \begin{matrix} cos\psi& -sin\psi & 0 \\ sin\psi & cos\psi & 0\\ 0 & 0& 1\\ \end{matrix} \right] \\ Rz,ψ=cosψsinψ0sinψcosψ0001通过上述的矩阵按右乘的顺序来进行乘积,得到旋转变换后的旋转矩阵为: R Z Y Z = R z , ϕ R y , θ R z , ψ = [ c o s ϕ ∗ c o s ψ ∗ c o s θ − s i n ϕ ∗ s i n ψ − c o s ψ ∗ s i n ϕ − c o s ϕ ∗ c o s θ ∗ s i n ψ c o s ϕ ∗ s i n θ c o s ϕ ∗ s i n ψ + c o s ψ ∗ c o s θ ∗ s i n ϕ c o s ϕ ∗ c o s ψ − c o s θ ∗ s i n ϕ ∗ s i n ψ s i n ϕ ∗ s i n θ − c o s ψ ∗ s i n θ s i n ψ ∗ s i n θ c o s θ ] R_{ZYZ}=R_{z,\phi}R_{y,\theta}R_{z,\psi}= \left[ \begin{matrix} cos\phi*cos\psi*cos\theta - sin\phi*sin\psi& - cos\psi*sin\phi - cos\phi*cos\theta*sin\psi& cos\phi*sin\theta \\ cos\phi*sin\psi + cos\psi*cos\theta*sin\phi& cos\phi*cos\psi - cos\theta*sin\phi*sin\psi& sin\phi*sin\theta \\ -cos\psi*sin\theta&sin\psi*sin\theta&cos\theta \\ \end{matrix} \right] \\ RZYZ=Rz,ϕRy,θRz,ψ=cosϕcosψcosθsinϕsinψcosϕsinψ+cosψcosθsinϕcosψsinθcosψsinϕcosϕcosθsinψcosϕcosψcosθsinϕsinψsinψsinθcosϕsinθsinϕsinθcosθ
方程中的矩阵 R Z Y Z R_{ZYZ} RZYZ被称为 Z Y Z ZYZ ZYZ欧拉角变换

2. 代码解析(含实例)

代码如下:

syms phi theta psi
R1 = rotz(phi)*roty(theta)*rotz(psi);

由于需要使用 t r p l o t trplot trplot 函数来将旋转可视化,因此在这里设欧拉角 ϕ θ ψ \phi\theta\psi ϕθψ的角度均为 p i / 6 pi/6 pi/6
R 0 R_0 R0为参考系矩阵, R 1 R_1 R1 R 0 R_0 R0为参考系矩阵,做 R z , π / 6 R y , π / 6 R z , π / 6 R_{z,\pi/6}R_{y,\pi/6}R_{z,\pi/6} Rz,π/6Ry,π/6Rz,π/6的旋转。

syms phi theta psi
R0 = rotz(0);
R1 = rotz(pi/6)*roty(pi/6)*rotz(pi/6);
trplot(R0,'color','r','frame','0')
hold on
trplot(R1,'color','b','frame','1')

得到结果如下:
Alt

二、姿态角(RPY)表示法

滚动(roll)-俯仰(pitch)-偏航(yaw)表示法

1. 定义

旋转矩阵 R R R也可以被描述为按特定次序进行的一系列关于主坐标轴 x 0 、 y 0 和 z 0 x_0、y_0和z_0 x0y0z0轴旋转的产物。这些旋转决定了滚动(roll)、俯仰(pitch)、偏航(yaw) 角度,在这里我们将定义以下规则。

  • z 0 z_0 z0 轴旋转的 ϕ \phi ϕ角度的动作称为滚动(roll)
  • y 0 y_0 y0 轴旋转的 θ \theta θ角度的动作称为俯仰(pitch)
  • x 0 x_0 x0 轴旋转的 ψ \psi ψ角度的动作称为偏航(yaw))

我们指定旋转按照 x − y − z x-y-z xyz的顺序进行,换言之,首先绕 x 0 x_0 x0轴旋转角度 ψ \psi ψ,然后绕 y 0 y_0 y0 轴旋转角度 θ \theta θ。最后,绕 z 0 z_0 z0 轴旋转角度 ϕ \phi ϕ
注意!这里的旋转均是绕固定坐标系 o 0 x 0 y 0 z 0 o_0x_0y_0z_0 o0x0y0z0来进行旋转
根据上述描述的旋转,列出以下旋转的对应矩阵。
R z , ϕ = [ c o s ϕ − s i n ϕ 0 s i n ϕ c o s ϕ 0 0 0 1 ] R_{z,\phi}= \left[ \begin{matrix} cos\phi& -sin\phi & 0 \\ sin\phi & cos\phi & 0\\ 0 & 0& 1\\ \end{matrix} \right] \\ Rz,ϕ=cosϕsinϕ0sinϕcosϕ0001 R y , θ = [ c o s θ 0 s i n θ 0 1 0 − s i n θ 0 c o s θ ] R_{y,\theta}= \left[ \begin{matrix} cos\theta & 0 & sin\theta \\ 0 & 1& 0\\ -sin\theta & 0& cos\theta \\ \end{matrix} \right] \\ Ry,θ=cosθ0sinθ010sinθ0cosθ R x , ψ = [ 1 0 0 0 c o s ψ − s i n ψ 0 s i n ψ c o s ψ ] R_{x,\psi}= \left[ \begin{matrix} 1& 0 & 0 \\ 0 & cos\psi & -sin\psi\\ 0 & sin\psi& cos\psi\\ \end{matrix} \right] \\ Rx,ψ=1000cosψsinψ0sinψcosψ通过上述的矩阵按左乘的顺序来进行乘积,得到旋转变换后的旋转矩阵为: R = R z , ϕ R y , θ R x , ψ = [ c o s ϕ ∗ c o s θ c o s ϕ ∗ s i n ψ ∗ s i n θ − c o s ψ ∗ s i n ϕ s i n ϕ ∗ s i n ψ + c o s ϕ ∗ c o s ψ ∗ s i n θ c o s θ ∗ s i n ϕ c o s ϕ ∗ c o s ψ + s i n ϕ ∗ s i n ψ ∗ s i n θ c o s ψ ∗ s i n ϕ ∗ s i n θ − c o s ϕ ∗ s i n ψ − s i n θ c o s θ ∗ s i n ψ c o s ψ ∗ c o s θ ] R=R_{z,\phi}R_{y,\theta}R_{x,\psi}= \left[ \begin{matrix} cos\phi*cos\theta& cos\phi*sin\psi*sin\theta - cos\psi*sin\phi& sin\phi*sin\psi + cos\phi*cos\psi*sin\theta \\ cos\theta*sin\phi& cos\phi*cos\psi + sin\phi*sin\psi*sin\theta& cos\psi*sin\phi*sin\theta - cos\phi*sin\psi \\ -sin\theta&cos\theta*sin\psi&cos\psi*cos\theta \\ \end{matrix} \right] \\ R=Rz,ϕRy,θRx,ψ=cosϕcosθcosθsinϕsinθcosϕsinψsinθcosψsinϕcosϕcosψ+sinϕsinψsinθcosθsinψsinϕsinψ+cosϕcosψsinθcosψsinϕsinθcosϕsinψcosψcosθ

2. 代码解析(含实例)

代码如下:

syms phi theta psi
R2 = rotz(phi)*roty(theta)*rotx(psi);

三、四元数(axis/angle)表示法(未完待续)

转轴/角度(axis/angle)表示法

1. 定义

旋转并不总是关于主坐标轴而进行的。我们通常感兴趣的是关于空间中某任意轴线的旋转,这不仅提供了一种描述旋转的简便方法,并且提供了对于旋转矩阵的另一种参数化方法。
k = [ k x , k y , k z ] T k=[k_x,k_y,k_z]^{T} k=[kxkykz]T表示坐标系 o 0 x 0 y 0 z 0 o_0x_0y_0z_0 o0x0y0z0内的一个单位向量,它定义了一个转轴,在此推导旋转矩阵 R k , θ R_{k,\theta} Rk,θ来表示关于次轴线的转角为 θ \theta θ的旋转。

2. 代码解析(含实例)

在MATLAB中使用 q u a t e r n i o n quaternion quaternion 函数来实现坐标系绕任意轴线旋转。
代码如下:
参考Quaternion


总结

以上就是关于旋转的参数化(欧拉角、姿态角、四元数)的内容,本文详细介绍了如何理解欧拉角、姿态角、四元数,提供了代码辅助理解旋转的参数化的特性。

参考文献

  1. 旋转矩阵、欧拉角、四元数理论及其转换关系
  2. Rodrigues’ Rotation Formula

猜你喜欢

转载自blog.csdn.net/AlbertDS/article/details/123924143