机器人动力学——拉格朗日法
引文
机器人动力学所用到的运动学方程是一组具有下列形式的二阶微分方程组
τ
=
M
(
θ
)
θ
¨
+
h
(
θ
,
θ
˙
)
\tau = M ( \theta ) \ddot { \theta } + h ( \theta , \dot { \theta } )
τ=M(θ)θ¨+h(θ,θ˙)
式中,对于所有关节均为驱动关节的开式运动链,广义坐标
θ
∈
R
n
\theta \in \mathbb{R}^{n}
θ∈Rn 表示关节变量;广义力
τ
∈
R
n
\tau \in \mathbb{R}^{n}
τ∈Rn 表示力或力矩,如果
θ
i
\theta_i
θi 是旋转关节,则
τ
i
\tau_i
τi 对应力矩;如果
θ
i
\theta_i
θi 为平动关节,则
τ
i
\tau_i
τi 对应力;
M
(
θ
)
∈
R
n
×
n
M ( \theta )\in \mathbb{R}^{n\times{n}}
M(θ)∈Rn×n 是一个对称且正定的质量矩阵;
h
(
θ
,
θ
˙
)
∈
R
n
h ( \theta , \dot { \theta })\in \mathbb{R}^{n}
h(θ,θ˙)∈Rn 是将向心力、科里奥利力、重力和摩擦力等集合在一起的力向量,该向量取决于
θ
\theta
θ 和 $ \dot { \theta}$ 这两个变量。
运动学同样区分正运动学和逆运动学,正向动力学问题是在给定状态变量
(
θ
,
θ
˙
)
( \theta , \dot { \theta })
(θ,θ˙) 以及关节力和力矩的前提下确定机器人的加速度
θ
¨
\ddot { \theta }
θ¨ ,即
θ
¨
=
M
−
1
(
θ
)
(
τ
−
h
(
θ
,
θ
˙
)
)
\ddot { \theta } = M ^ { - 1 } ( \theta ) ( \tau - h ( \theta , \dot { \theta } ) )
θ¨=M−1(θ)(τ−h(θ,θ˙))
逆动力学问题则是找到对应于机器人状态和期望加速度的关节力和力矩
τ
\tau
τ
机器人的动力学方程通常可以通过牛顿-欧拉公式或拉格朗日动力学公式得到。对于简单结构的机器人,如3自由度或自由度更少的情形,拉格朗日形式不仅在概念上十分优雅,并且在实际中非常有效。但对于自由度数目更多的机器人来讲,其计算可能会很快变得烦琐。
下文将讨论拉格朗日动力学公式
拉格朗日函数
力学系统的拉格朗日函数
L
(
q
,
q
˙
)
{ \mathcal L } ( q , \dot { q } )
L(q,q˙) 定义为整个系统的动能
K
(
q
,
q
˙
)
{ \mathcal K } ( q , \dot { q } )
K(q,q˙) 减去势能
P
(
q
)
{ \mathcal P } ( q )
P(q) ,式中的—组独立坐标
q
∈
R
n
q \in \mathbb{R}^{n}
q∈Rn 用来描述系统的位形(这个坐标
q
q
q 被称为广义坐标)
L
(
q
,
q
˙
)
=
K
(
q
,
q
˙
)
−
P
(
q
)
{ \mathcal L } ( q , \dot { q } ) = { \mathcal K } ( q , \dot { q } ) - { \mathcal P } ( q )
L(q,q˙)=K(q,q˙)−P(q)
运动方程现在可以用拉格朗日函数表示如下(推导过程略,详见动力学教材)
f
=
d
d
t
∂
L
∂
q
˙
−
∂
L
∂
q
f = \frac { d } { d t } \frac { \partial { \mathcal L } } { \partial \dot { q } } - \frac { \partial { \mathcal L } } { \partial q }
f=dtd∂q˙∂L−∂q∂L
这个方程也称为含外力的欧拉-拉格朗日方程(在标准形式的欧拉-拉格朗日方程中,外力
f
f
f 等于零)
2 R 2R 2R 开链机器人举例
下面以在重力作用下的—个 2 R 2R 2R 开链机器人为例推导动力学方程,如下图所示

将关节坐标
θ
=
(
θ
1
,
θ
2
)
\theta =(\theta_{1},\theta_{2})
θ=(θ1,θ2) 选做广义坐标,广义力
τ
=
(
τ
1
,
τ
2
)
\tau =(\tau_{1},\tau_{2})
τ=(τ1,τ2) 则对应于关节力矩(因为
τ
T
θ
˙
\tau^T\dot{\theta}
τTθ˙ 对应于功率)。本例中的拉格朗日函数
L
(
q
,
q
˙
)
{ \mathcal L } ( q , \dot { q } )
L(q,q˙) 可以写成如下分量形式:
L
(
θ
,
θ
˙
)
=
∑
i
=
1
2
(
K
i
−
P
i
)
\mathcal{L}(\theta, \dot{\theta})=\sum_{i=1}^{2}(\mathcal{K}_{i}-\mathcal{P}_{i})
L(θ,θ˙)=i=1∑2(Ki−Pi)
则欧拉-拉格朗日方程可以写成如下分量形式(
τ
\tau
τ 为关节力和力矩向量):
τ
i
=
d
d
t
∂
L
∂
θ
i
˙
−
∂
L
∂
θ
i
i
=
1
,
2
\tau_i = \frac { d } { d t } \frac { \partial { \mathcal L } } { \partial \dot { \theta_i } } - \frac { \partial { \mathcal L } } { \partial \theta_i } \qquad i = 1,2
τi=dtd∂θi˙∂L−∂θi∂Li=1,2
下面我们需要计算两杆的动能和势能(认为两杆各自的质量
m
1
\mathrm { m }1
m1 和
m
2
\mathrm { m }2
m2 均集中于各杆末端)
连杆1质心的位置和速度:
[
x
1
y
1
]
=
[
L
1
cos
θ
1
L
1
sin
θ
1
]
[
x
˙
1
y
˙
1
]
=
[
−
L
1
sin
θ
1
L
1
cos
θ
1
]
θ
˙
1
\begin{array}{l} {\left[\begin{array}{l} x_{1} \\ y_{1} \end{array}\right]=\left[\begin{array}{c} L_{1} \cos \theta_{1} \\ L_{1} \sin \theta_{1} \end{array}\right]} \\ {\left[\begin{array}{c} \dot{x}_{1} \\ \dot{y}_{1} \end{array}\right]=\left[\begin{array}{r} -L_{1} \sin \theta_{1} \\ L_{1} \cos \theta_{1} \end{array}\right] \dot{\theta}_{1}} \end{array}
[x1y1]=[L1cosθ1L1sinθ1][x˙1y˙1]=[−L1sinθ1L1cosθ1]θ˙1
连杆2质心的位置和速度:
[
x
2
y
2
]
=
[
L
1
cos
θ
1
+
L
2
cos
(
θ
1
+
θ
2
)
L
1
sin
θ
1
+
L
2
sin
(
θ
1
+
θ
2
)
]
[
x
˙
2
y
˙
2
]
=
[
−
L
1
sin
θ
1
−
L
2
sin
(
θ
1
+
θ
2
)
−
L
2
sin
(
θ
1
+
θ
2
)
L
1
cos
θ
1
+
L
2
cos
(
θ
1
+
θ
2
)
L
2
cos
(
θ
1
+
θ
2
)
]
[
θ
˙
1
θ
˙
2
]
\begin{array}{l} {\left[\begin{array}{l} x_{2} \\ y_{2} \end{array}\right]=\left[\begin{array}{c} L_{1} \cos \theta_{1}+L_{2} \cos (\theta_{1}+\theta_{2}) \\ L_{1} \sin \theta_{1}+L_{2} \sin (\theta_{1}+\theta_{2}) \end{array}\right]} \\ {\left[\begin{array}{l} \dot{x}_{2} \\ \dot{y}_{2} \end{array}\right]=\left[\begin{array}{rr} -L_{1} \sin \theta_{1}-L_{2} \sin (\theta_{1}+\theta_{2}) & -L_{2} \sin (\theta_{1}+\theta_{2}) \\ L_{1} \cos \theta_{1}+L_{2} \cos (\theta_{1}+\theta_{2}) & L_{2} \cos (\theta_{1}+\theta_{2}) \end{array}\right]\left[\begin{array}{l} \dot{\theta}_{1} \\ \dot{\theta}_{2} \end{array}\right] } \end{array}
[x2y2]=[L1cosθ1+L2cos(θ1+θ2)L1sinθ1+L2sin(θ1+θ2)][x˙2y˙2]=[−L1sinθ1−L2sin(θ1+θ2)L1cosθ1+L2cos(θ1+θ2)−L2sin(θ1+θ2)L2cos(θ1+θ2)][θ˙1θ˙2]
由
K
=
1
2
m
v
2
=
1
2
m
(
x
˙
2
+
y
˙
2
)
\mathcal{K} =\frac{1}{2} \mathfrak{m} v^2 = \frac{1}{2} \mathfrak{m}(\dot{x}^2 + \dot{y}^2)
K=21mv2=21m(x˙2+y˙2) ,连杆的动能项
K
1
{ \mathcal K }_1
K1 和
K
2
{ \mathcal K }_2
K2 分别为
K
1
=
1
2
m
1
(
x
˙
1
2
+
y
˙
1
2
)
=
1
2
m
1
L
1
2
θ
˙
1
2
K
2
=
1
2
m
2
(
x
˙
2
2
+
y
˙
2
2
)
=
1
2
m
2
(
(
L
1
2
+
2
L
1
L
2
cos
θ
2
+
L
2
2
)
θ
˙
1
2
+
2
(
L
2
2
+
L
1
L
2
cos
θ
2
)
θ
˙
1
θ
˙
2
+
L
2
2
θ
˙
2
2
)
\begin{aligned} \mathcal{K}_{1} &=\frac{1}{2} \mathfrak{m}_{1}(\dot{x}_{1}^{2}+\dot{y}_{1}^{2}) \\ &= \frac{1}{2} \mathfrak{m}_{1} L_{1}^{2} \dot{\theta}_{1}^{2} \\ \mathcal{K}_{2} &=\frac{1}{2} \mathfrak{m}_{2}(\dot{x}_{2}^{2}+\dot{y}_{2}^{2}) \\ &= \frac{1}{2} \mathfrak{m}_{2}((L_{1}^{2}+2 L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) \dot{\theta}_{1}^{2}+2(L_{2}^{2}+L_{1} L_{2} \cos \theta_{2}) \dot{\theta}_{1} \dot{\theta}_{2}+L_{2}^{2} \dot{\theta}_{2}^{2}) \end{aligned}
K1K2=21m1(x˙12+y˙12)=21m1L12θ˙12=21m2(x˙22+y˙22)=21m2((L12+2L1L2cosθ2+L22)θ˙12+2(L22+L1L2cosθ2)θ˙1θ˙2+L22θ˙22)
势能只取决于高度,即
y
y
y 坐标。由
P
=
m
g
y
\mathcal{P} = \mathfrak{m} g y
P=mgy ,连杆的势能项
P
1
{ \mathcal P }_1
P1 和
P
2
{ \mathcal P }_2
P2 分别为
P
1
=
m
1
g
y
1
=
m
1
g
L
1
sin
θ
1
P
2
=
m
2
g
y
2
=
m
2
g
(
L
1
sin
θ
1
+
L
2
sin
(
θ
1
+
θ
2
)
)
\begin{array}{l} \mathcal{P}_{1}=\mathfrak{m}_{1} g y_{1}=\mathfrak{m}_{1} g L_{1} \sin \theta_{1} \\ \mathcal{P}_{2}=\mathfrak{m}_{2} g y_{2}=\mathfrak{m}_{2} g(L_{1} \sin \theta_{1}+L_{2} \sin (\theta_{1}+\theta_{2})) \end{array}
P1=m1gy1=m1gL1sinθ1P2=m2gy2=m2g(L1sinθ1+L2sin(θ1+θ2))
将动能项与势能项带入拉格朗日函数即可得到平面
2
R
2R
2R 运动链的动力学方程:
{
τ
1
=
(
m
1
L
1
2
+
m
2
(
L
1
2
+
2
L
1
L
2
cos
θ
2
+
L
2
2
)
)
θ
¨
1
+
m
2
(
L
1
L
2
cos
θ
2
+
L
2
2
)
θ
¨
2
−
m
2
L
1
L
2
sin
θ
2
(
2
θ
˙
1
θ
˙
2
+
θ
˙
2
2
)
+
(
m
1
+
m
2
)
L
1
g
cos
θ
1
+
m
2
g
L
2
cos
(
θ
1
+
θ
2
)
,
τ
2
=
m
2
(
L
1
L
2
cos
θ
2
+
L
2
2
)
θ
¨
1
+
m
2
L
2
2
θ
¨
2
+
m
2
L
1
L
2
θ
˙
1
2
sin
θ
2
+
m
2
g
L
2
cos
(
θ
1
+
θ
2
)
.
\left\{ \begin{aligned} \tau_{1}=&(\mathfrak{m}_{1} L_{1}^{2}+\mathfrak{m}_{2}(L_{1}^{2}+2 L_{1} L_{2} \cos \theta_{2}+L_{2}^{2})) \ddot{\theta}_{1} \\ &+\mathfrak{m}_{2}(L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) \ddot{\theta}_{2}-\mathfrak{m}_{2} L_{1} L_{2} \sin \theta_{2}(2 \dot{\theta}_{1} \dot{\theta}_{2}+\dot{\theta}_{2}^{2}) \\ &+(\mathfrak{m}_{1}+\mathfrak{m}_{2}) L_{1} g \cos \theta_{1}+\mathfrak{m}_{2} g L_{2} \cos (\theta_{1}+\theta_{2}), \\ \tau_{2}=& \mathfrak{m}_{2}(L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) \ddot{\theta}_{1}+\mathfrak{m}_{2} L_{2}^{2} \ddot{\theta}_{2}+\mathfrak{m}_{2} L_{1} L_{2} \dot{\theta}_{1}^{2} \sin \theta_{2} \\ &+\mathfrak{m}_{2} g L_{2} \cos (\theta_{1}+\theta_{2}) . \end{aligned} \right.
⎩⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎧τ1=τ2=(m1L12+m2(L12+2L1L2cosθ2+L22))θ¨1+m2(L1L2cosθ2+L22)θ¨2−m2L1L2sinθ2(2θ˙1θ˙2+θ˙22)+(m1+m2)L1gcosθ1+m2gL2cos(θ1+θ2),m2(L1L2cosθ2+L22)θ¨1+m2L22θ¨2+m2L1L2θ˙12sinθ2+m2gL2cos(θ1+θ2).
可以看到,即使是一个简单的
2
R
2R
2R 机器人,其逆运动学方程也十分复杂。对上述各项进行整理,得到如下形式的方程:
τ
=
M
(
θ
)
θ
¨
+
c
(
θ
,
θ
˙
)
+
g
(
θ
)
⏟
h
(
θ
,
θ
˙
)
\tau=M(\theta) \ddot{\theta}+\underbrace{c(\theta, \dot{\theta})+g(\theta)}_{h(\theta, \dot{\theta})}
τ=M(θ)θ¨+h(θ,θ˙)
c(θ,θ˙)+g(θ)
式中
M
(
θ
)
=
[
m
1
L
1
2
+
m
2
(
L
1
2
+
2
L
1
L
2
cos
θ
2
+
L
2
2
)
m
2
(
L
1
L
2
cos
θ
2
+
L
2
2
)
m
2
(
L
1
L
2
cos
θ
2
+
L
2
2
)
m
2
L
2
2
]
c
(
θ
,
θ
˙
)
=
[
−
m
2
L
1
L
2
sin
θ
2
(
2
θ
˙
1
θ
˙
2
+
θ
˙
2
2
)
m
2
L
1
L
2
θ
˙
1
2
sin
θ
2
]
g
(
θ
)
=
[
(
m
1
+
m
2
)
L
1
g
cos
θ
1
+
m
2
g
L
2
cos
(
θ
1
+
θ
2
)
m
2
g
L
2
cos
(
θ
1
+
θ
2
)
]
\begin{aligned} M(\theta) &=\left[\begin{array}{cc} \mathfrak{m}_{1} L_{1}^{2}+\mathfrak{m}_{2}(L_{1}^{2}+2 L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) & \mathfrak{m}_{2}(L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) \\ \mathfrak{m}_{2}(L_{1} L_{2} \cos \theta_{2}+L_{2}^{2}) & \mathfrak{m}_{2}L_{2}^{2} \\ \end{array}\right] \\ c(\theta, \dot{\theta}) &=\left[\begin{array}{c} -\mathfrak{m}_{2} L_{1} L_{2} \sin \theta_{2}(2 \dot{\theta}_{1} \dot{\theta}_{2}+\dot{\theta}_{2}^{2}) \\ \mathfrak{m}_{2} L_{1} L_{2} \dot{\theta}_{1}^{2} \sin \theta_{2} \end{array}\right] \\ g(\theta) &=\left[\begin{array}{c} (\mathfrak{m}_{1}+\mathfrak{m}_{2}) L_{1} g \cos \theta_{1}+\mathfrak{m}_{2} g L_{2} \cos (\theta_{1}+\theta_{2}) \\ \mathfrak{m}_{2} g L_{2} \cos (\theta_{1}+\theta_{2}) \end{array}\right] \end{aligned}
M(θ)c(θ,θ˙)g(θ)=[m1L12+m2(L12+2L1L2cosθ2+L22)m2(L1L2cosθ2+L22)m2(L1L2cosθ2+L22)m2L22]=[−m2L1L2sinθ2(2θ˙1θ˙2+θ˙22)m2L1L2θ˙12sinθ2]=[(m1+m2)L1gcosθ1+m2gL2cos(θ1+θ2)m2gL2cos(θ1+θ2)]
式中
M
(
θ
)
M(\theta)
M(θ) 为对称正定的质量矩阵,
c
(
θ
,
θ
˙
)
c(\theta, \dot{\theta})
c(θ,θ˙) 为速度乘积项,包含科里奥利和向心力矩的向量,其中包含
θ
˙
2
\dot{\theta}^2
θ˙2 的二次项称为向心项,包含
θ
˙
i
θ
˙
j
(
i
≠
j
)
\dot{\theta}_{i} \dot{\theta}_{j}(i \ne j)
θ˙iθ˙j(i=j) 的二次项则称为科里奥利项。
g
(
θ
)
g(\theta)
g(θ) 为重力项 ,因为此处势能仅来自重力,若末端有弹簧,弹簧也会贡献势能。这些揭示了运动方程是
θ
¨
\ddot{\theta}
θ¨ 的线性函数、
θ
˙
\dot{\theta}
θ˙ 的二次函数、
θ
\theta
θ 的三角函数。上述结论不仅适用于
2
R
2R
2R 型机器人,对于包含转动关节的串联运动链也同样适用。