【Optimal Control (CMU 16-745)】Lecture 2 Dynamics Discretization and Stability

Review:

  • Controlled dynamics (continuous-time)
  • Manipulator dynamics
  • Equilibrium
  • Stability (local)

Lecture 2 Dynamics Discretization and Stability

Overview

  • Continuous ODEs -> Discrete-time Simulations
  • More on stability

1. Motivation

  • In general, we cannot solve x ˙ = f ( x ) \dot{\mathrm{x}} = \mathbf{f}(\mathrm{x}) x˙=f(x) for x ( t ) \mathrm{x}(t) x(t) analytically. We need to use numerical methods to solve it.
  • We need to represent x ( t ) \mathrm{x}(t) x(t) with discrete values on computers.
  • Discrete-time models can capture some effects that continuous-time ODEs cannot.

2. Discrete-time Dynamics

(1) Explicit Form

x n + 1 = f d ( x n , u n ) \mathrm{x}_{n+1} = \mathbf{f}_d(\mathrm{x}_n, \mathbf{u}_n) xn+1=fd(xn,un)

f d \mathbf{f}_d fd is called discrete-time dynamics.

The simplest discretization:
x n + 1 = x n + h f ( x n , u n ) , \mathrm{x}_{n+1} = \mathrm{x}_n + h\mathbf{f}(\mathrm{x}_n, \mathbf{u}_n), xn+1=xn+hf(xn,un), where h h h is the time step. The right hand side is f d ( x n , u n ) \mathbf{f}_d(\mathrm{x}_n, \mathbf{u}_n) fd(xn,un). We call this Forward Euler Integration.

Example: Pendulum Simulation

Parameters: m = 1 , l = 1 , g = 9.81 m = 1, l = 1, g = 9.81 m=1,l=1,g=9.81

(a) time step h = 0.1 h = 0.1 h=0.1
在这里插入图片描述
The angle diverges due to the accumulation of error.

(b) time step h = 0.01 h = 0.01 h=0.01
在这里插入图片描述

Seems better, but still diverges.

The divergence is inevitable.
This is because the natural dynamics of this system is oscillation, and the linear approximation of the dynamics is not accurate.
(imagin the linear approximation of a sine function, it will always overshoot)

3. Stability of Discrete-time Systems

(1) Recall: In continuous-time, we can use eigenvalues to determine the stability of a system.
R e [ e i g ( ∂ f d ∂ x ) ] < 0 ⇒ stable \mathrm{Re}\left[\mathrm{eig}\left(\frac{\partial \mathbf{f}_d}{\partial \mathrm{x}}\right)\right] < 0 \Rightarrow \text{stable} Re[eig(xfd)]<0stable

(2) Derivation:
In discrete-time, dynamics is an iterated map:
x N = f d ( f d ( f d ( ⋯ f d ( x 0 ) ) ) ) \mathrm{x}_{N} = \mathbf{f}_d \left(\mathbf{f}_d \left(\mathbf{f}_d \left(\cdots \mathbf{f}_d \left(\mathrm{x}_0\right)\right)\right)\right) xN=fd(fd(fd(fd(x0))))

Linearize the dynamics (apply the chain rule):
∂ x N ∂ x 0 = ∂ f d ∂ x ∂ f d ∂ x ⋯ ∂ f d ∂ x ∣ x = x 0 = A d N \frac{\partial \mathrm{x}_N}{\partial \mathrm{x}_0} = \left.\frac{\partial \mathbf{f}_d}{\partial \mathrm{x}} \frac{\partial \mathbf{f}_d}{\partial \mathrm{x}} \cdots \frac{\partial \mathbf{f}_d}{\partial \mathrm{x}}\right|_{\mathrm{x} = \mathrm{x}_0}= A_d^N x0xN=xfdxfdxfd x=x0=AdN( x 0 \mathrm{x}_0 x0 is an equilibrium point)

Assume we setup coordinate system such that x 0 = 0 \mathrm{x}_0 = 0 x0=0 is an equilibrium point.

(3) Conclusion:
A discrete-time system is stable
⇔ \Leftrightarrow lim ⁡ n → ∞ A d n x 0 = 0 , ∀ x 0 \lim_{n \to \infty} A_d^n\mathrm{x}_0 = 0, \forall \mathrm{x}_0 limnAdnx0=0,x0
⇔ \Leftrightarrow lim ⁡ n → ∞ A d n = 0 \lim_{n \to \infty} A_d^n = 0 limnAdn=0
⇔ \Leftrightarrow ∣ e i g ( A d ) ∣ < 1 \left|\mathrm{eig}\left(A_d\right)\right| < 1 eig(Ad)<1 (all eigenvalues are inside the unit circle)

(4) Example: Forward Euler Integration of Pendulum
x k + 1 = x k + h f ( x k ) = f d ( x k ) \mathrm{x}_{k+1} = \mathrm{x}_k + h\mathbf{f}(\mathrm{x}_k) = \mathbf{f}_d(\mathrm{x}_k) xk+1=xk+hf(xk)=fd(xk)

Compute the A d A_d Ad:
A d = ∂ f d ∂ x k = I + h A = I + h [ 0 1 − g l cos ⁡ θ 0 ] = [ 1 h − g h l cos ⁡ θ 1 ] \begin{align*} A_d &= \frac{\partial \mathbf{f}_d}{\partial \mathrm{x}_k}\\ &= I + hA\\ &= I + h\begin{bmatrix} 0 & 1 \\ -\frac{g}{l\cos\theta} & 0 \end{bmatrix}\\ &= \begin{bmatrix} 1 & h \\ -\frac{gh}{l\cos\theta} & 1 \end{bmatrix} \end{align*} Ad=xkfd=I+hA=I+h[0lcosθg10]=[1lcosθghh1]

Let θ = 0 \theta = 0 θ=0, we have:
A d = [ 1 h − g h l 1 ] A_d = \begin{bmatrix} 1 & h \\ -\frac{gh}{l} & 1 \end{bmatrix} Ad=[1lghh1]

Compute the eigenvalues (take h = 0.1 h = 0.1 h=0.1):
e i g ( A d ∣ θ = 0 ) = 1 ± 0.313 i \mathrm{eig}(\left.A_d\right|_{\theta=0}) = 1 \pm 0.313i eig(Adθ=0)=1±0.313i

The eigenvalues are not inside the unit circle, so the system is unstable.

Plot the relationship between h h h and the eigenvalues:
在这里插入图片描述
We find that whatever h h h is, the norm of the eigenvalues is always larger than 1. So the system is always unstable.

Intuition of the overshoot:
在这里插入图片描述
Tips

  • Be careful when discretizing ODEs.
  • Sanity check based on energy, momentum, behavior of the system.
  • Don’t use Forward Euler Integration.

4. A better explicit integrator

  • 4th order Runge-Kutta (RK4) method (industry standard)
  • Intuition:
    • Euler fiits a line sequent over each time step.
    • RK4 fits a cubic polynomial over each time step ⇒ \Rightarrow much better accuracy.
  • Pseudo code:
    x k + 1 = f R K 4 ( x k ) h 1 = f ( x k ) h 2 = f ( x k + h / 2 h 1 ) h 3 = f ( x k + h / 2 h 2 ) h 4 = f ( x k + h h 3 ) x k + 1 = x k + h 6 ( h 1 + 2 h 2 + 2 h 3 + h 4 ) \begin{align*} \mathrm{x}_{k+1} &= f_{RK4}(\mathrm{x}_k)\\ h_1 &= f(\mathrm{x}_k)\\ h_2 &= f(\mathrm{x}_k + h/2 h_1)\\ h_3 &= f(\mathrm{x}_k + h/2 h_2)\\ h_4 &= f(\mathrm{x}_k + h h_3)\\ \mathrm{x}_{k+1} &= \mathrm{x}_k + \frac{h}{6}(h_1 + 2h_2 + 2h_3 + h_4) \end{align*} xk+1h1h2h3h4xk+1=fRK4(xk)=f(xk)=f(xk+h/2h1)=f(xk+h/2h2)=f(xk+hh3)=xk+6h(h1+2h2+2h3+h4)

在这里插入图片描述
Looks more stable than Forward Euler Integration.

The eigenvalues plot:
在这里插入图片描述
It is worthwhile to take more computation time to get a more accurate result.Even sophisticated integrators have issues, so we always need to do sanity check.

5. Implicit Form (Backward Euler Integration)

(1) Its basic form can be written as:
f d ( x n + 1 , x n , u n ) = 0 \mathrm{f}_d(\mathrm{x}_{n+1}, \mathrm{x}_n, \mathbf{u}_n) = 0 fd(xn+1,xn,un)=0

The simplest discretization:
x n + 1 = x n + h f ( x n + 1 ) \mathrm{x}_{n+1} = \mathrm{x}_n + h\mathbf{f}(\mathrm{x}_{n+1}) xn+1=xn+hf(xn+1)

The term f ( x n + 1 ) \mathbf{f}(\mathrm{x}_{n+1}) f(xn+1) evaluates the dynamics at the next time step (in the future). This is called Backward Euler Integration.

(2) How do we simulate (solve this equation)?
We rewrite the equation as:
f d ( x n + 1 , x n , u n ) = x n + h f ( x n + 1 ) − x n + 1 = 0 \mathrm{f}_d\left(\mathrm{x}_{n+1}, \mathrm{x}_n, \mathbf{u}_n\right) = \mathrm{x}_{n} + h\mathbf{f}(\mathrm{x}_{n+1}) - \mathrm{x}_{n+1} = 0 fd(xn+1,xn,un)=xn+hf(xn+1)xn+1=0
and solve its root for x n + 1 \mathrm{x}_{n+1} xn+1 (will be discussed in the next lecture).

(3) Example: Pendulum Simulation
在这里插入图片描述

  • It seems that the energy is lossing, though it is stable.
  • Discretization adds damping to the system.
  • While unphysical, this effect allows simulators to take big steps and is often convenient.
    (Most of the robotics simulators have this issue. It is acceptable)

(4) Takeaway:

  • Implicit methods are often “more stable” than explicit methods.
  • For forward simulations, solving implicit methods is more expensive than explicit methods.
  • In many “direct” trajectory optimization methods, implicit methods are not more expensive than explicit methods.

6. Discretizing Controls

So far we have discretized the state x \mathrm{x} x, but not the control u \mathbf{u} u.

(1) Simplest option - Zero-order hold:
u ( t ) = u k , ∀ t ∈ [ t k , t k + 1 ) \mathbf{u}\left(t\right) = \mathbf{u}_k, \forall t \in [t_k, t_{k+1}) u(t)=uk,t[tk,tk+1)
在这里插入图片描述

  • It’s easy to implement.
  • May require lots of knot points to accurately capture a continuous u ( t ) \mathbf{u}(t) u(t).

(2) (Possibly) Better option - First-order hold:
u ( t ) = u k + ( u k + 1 − u k h ) ( t − t k ) , ∀ t ∈ [ t k , t k + 1 ) \mathbf{u}\left(t\right) = \mathbf{u}_k + \left(\frac{\mathbf{u}_{k+1} - \mathbf{u}_k}{h}\right)(t - t_k), \forall t \in [t_k, t_{k+1}) u(t)=uk+(huk+1uk)(ttk),t[tk,tk+1)
在这里插入图片描述

  • Can approximate u ( t ) \mathbf{u}(t) u(t) with fewer knot points.
  • Not much extra work over zero-order hold.
  • Super common (e.g. classic DIRCOL).

(3) Other options:

  • We can keep playing this game with higher order polynomials.
  • In many control applications, u ( t ) \mathbf{u}(t) u(t) is not smooth (e.g. bang-bang control). Therefore, higher order polynomials are not good approximations.
  • Zero-order hold and first-order hold are the most common in practice.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值