Academic
  • Introduction
  • Artificial Intelligence
    • Introduction
    • AI Concepts, Terminology, and Application Areas
    • AI: Issues, Concerns and Ethical Considerations
  • Biology
    • Scientific Method
    • Chemistry of Life
    • Water, Acids, Bases
    • Properties of carbon
    • Macromolecules
    • Energy and Enzymes
    • Structure of a cell
    • Membranes and transport
    • Cellular respiration
    • Cell Signaling
    • Cell Division
    • Classical and molecular genetics
    • DNA as the genetic material
    • Central dogma
    • Gene regulation
  • Bioinformatics
    • Bioinformatics Overview
  • Deep Learning
    • Neural Networks and Deep Learning
      • Introduction
      • Logistic Regression as a Neural Network
      • Python and Vectorization
      • Shallow Neural Network
      • Deep Neural Network
    • Improving Deep Neural Networks
      • Setting up your Machine Learning Application
      • Regularizing your Neural Network
      • Setting up your Optimization Problem
      • Optimization algorithms
      • Hyperparameter, Batch Normalization, Softmax
    • Structuring Machine Learning Projects
    • Convolutional Neural Networks
      • Introduction
    • Sequence Models
      • Recurrent Neural Networks
      • Natural Language Processing & Word Embeddings
      • Sequence models & Attention mechanism
  • Linear Algebra
    • Vectors and Spaces
      • Vectors
      • Linear combinations and spans
      • Linear dependence and independence
      • Subspaces and the basis for a subspace
      • Vector dot and cross products
      • Matrices for solving systems by elimination
      • Null space and column space
    • Matrix transformations
      • Functions and linear transformations
      • Linear transformation examples
      • Transformations and matrix multiplication
      • Inverse functions and transformations
      • Finding inverses and determinants
      • More Determinant Depth
  • Machine Learning
    • Introduction
    • Linear Regression
      • Model and Cost Function
      • Parameter Learning
      • Multivariate Linear Regression
      • Computing Parameters Analytically
      • Octave
    • Logistic Regression
      • Classification and Representation
      • Logistic Regression Model
    • Regularization
      • Solving the Problem of Overfitting
    • Neural Networks
      • Introduction of Neural Networks
      • Neural Networks - Learning
    • Improve Learning Algorithm
      • Advice for Applying Machine Learning
      • Machine Learning System Design
    • Support Vector Machine
      • Large Margin Classification
      • Kernels
      • SVM in Practice
  • NCKU - Artificial Intelligence
    • Introduction
    • Intelligent Agents
    • Solving Problems by Searching
    • Beyond Classical Search
    • Learning from Examples
  • NCKU - Computer Architecture
    • First Week
  • NCKU - Data Mining
    • Introduction
    • Association Analysis
    • FP-growth
    • Other Association Rules
    • Sequence Pattern
    • Classification
    • Evaluation
    • Clustering
    • Link Analysis
  • NCKU - Machine Learning
    • Probability
    • Inference
    • Bayesian Inference
    • Introduction
  • NCKU - Robotic Navigation and Exploration
    • Kinetic Model & Vehicle Control
    • Motion Planning
    • SLAM Back-end (I)
    • SLAM Back-end (II)
    • Computer Vision / Multi-view Geometry
    • Lie group & Lie algebra
    • SLAM Front-end
  • Python
    • Numpy
    • Pandas
    • Scikit-learn
      • Introduction
      • Statistic Learning
  • Statstics
    • Quantitative Data
    • Modeling Data Distribution
    • Bivariate Numerical Data
    • Probability
    • Random Variables
    • Sampling Distribution
    • Confidence Intervals
    • Significance tests
Powered by GitBook
On this page
  • State Estimation and SLAM Problem
  • SLAM Problem
  • Probability Graphical Model for SLAM Problem
  • Probability Theory and Bayes Filter
  • Statistical Inference
  • Bayesian Approach
  • Bayes Filter
  • Kalman Filter
  • Kalman Filter
  • Extended Kalman Filter
  • EKF-SLAM

Was this helpful?

  1. NCKU - Robotic Navigation and Exploration

SLAM Back-end (I)

PreviousMotion PlanningNextSLAM Back-end (II)

Last updated 5 years ago

Was this helpful?

State Estimation and SLAM Problem

SLAM Problem

  • SLAM (Simultaneous localization and mapping)

    • 希望能達到同時定位自己並且建構整個地圖

Localization

以下是自走車在不同時間 (tk\mathbf{t}_ktk​) 移動到不同的位置 (xk\mathbf{x}_kxk​)

  • 自走車會透過控制指令 (uk\mathbf{u}_kuk​) 進行移動

  • 當中也會有一些誤差 (wk\mathbf{w}_kwk​)

Mapping

Problem

Probability Graphical Model for SLAM Problem

我們可以將 SLAM problem 轉為 probability graphical model 的樣式

  • 每個變數變成了一個節點

  • 藍色節點為 visible node 代表可以直接被偵測

  • 箭頭代表了因果的關係

可以看到在 SLAM problem 的兩個式子都可以在圖上被表現出來

Front-end

若感測器為視覺感測器,那麼 front-end 又稱 visual odometry

  • Prediction

  • Tracking

  • Mapping

Back-end

上面的觀測、預測通常會有誤差,累積後會產生錯誤,所以需要由 back-end 來修飾

在 back-end 有兩種做法來補償誤差,一種是 filter-based 一種是 graph-based

  • Filter-based error compensation

    • 直接根據最近的誤差來調整

    • 即時 (online) 但整體優化不佳

  • Graph-based error compensation

    • 每個時間點,都使用過去多個時間點的誤差來調整

發現 error 的方法稱為 loop closure detection

  • 檢查自走車是否到達以前到過的位置

  • 確定繞一圈後,將資訊丟給 error compensation

Probability Theory and Bayes Filter

Statistical Inference

Inference 是從 premises 來推測出 consequences 的過程

因為不可能從所有 premises 來推測,所以只拿一些 samples 來測,叫做 statistical inference

  • Hypothesis Testing (Top-down)

    • 是機器學習常用作法

    • 透過不斷假設 parameters 並帶入 samples 來評估結果是否正確

    • 最終得到最棒的 parameters

  • Estimation (Bottom-up)

    • 直接從 samples 去推測 parameters

Maximum Likelihood Estimation

最有名的 estimation 是 MLE

Maximum a Posteriori Estimation

MLE 採樣時可能產生誤差,猜錯真正的 likelihood 分布,所以有了 MAP

MAP 多考量了 prior 的機率,所以可以降低 MLE 採樣錯誤所產生的誤差

Example

MLE

以投硬幣舉例,總共投了五次 (Tail, Tail, Tail, Head, Tail)

MAP

同樣的題目,我們定義 prior 為 Discrete Uniform Distribution,也就是各為 1/11 (0.0 到 1.0)

因為 prior 是 uniform distribution,所以其實 MAP 沒有改變太多

Bayesian Approach

不斷用 prior + likelihood 來計算 posterior 並更新假設

不再是看誰讓 likelihood 或 posterior 最大化,而是直接觀察 parameters 的分布

Bayes Filter

State Prediction

我們也可以應用於 SLAM 的 probability graphical model

我們可以將式子簡寫成以下樣子 (bel 代表 belief)

Measurement Update

一樣可以轉成以下的 belief 表達方式

Bayes Filter Algorithm

Bayes filter 就是上面兩個式子遞迴互相更新所產生

寫成 pseudo code 表示為

Example

Kalman Filter

Kalman Filter

以下是 kalman filter 對狀態的建模

  • x-axis: 時間方向

  • y-axis: 可觀察、不可觀察

  • Noise 的分布 (Q, R) 在假設中皆為高斯分布 (Gaussian distribution)

  • Goal: 用可觀察的東西,對不可觀察的東西做出預測

假設所有變換都是線性的,可以得到以下公式:

Kalman Filter Computation Steps

  1. 預測下一個狀態

  1. 計算預測的 covariance

  1. 計算 Kalman-gain

  1. 預測狀態的 mean

  1. 預測狀態的 covariance

Extended Kalman Filter

Kalman filter 線性以及高斯分布的假設讓所有運算都變得簡單

但在現實中的狀況大多不是這麼簡單

於是在 Kalman filter 上加入"線性近似"的概念,就得到了 extended Kalman filter

也就是在預測狀態的 mean 時,改用 1st order Taylor expansion 來求

可以看到藍色線就是求得的近似線性值

我們可以得到新的公式:

  • Prediction Model \& Observation Model

  • Jacobian Matrix:

  • Linearized System

Extended Kalman Filter Computation Steps

在原本的 Kalman filter 時,計算中的 A, H 都是固定的

而在 EKF 中,每個時間點都須根據前一刻的估計值,重新用第一階的 taylor expansion 求得線性近似

EKF-SLAM

為了將 EKF 應用到 SLAM 問題中,首先要將 pose, landmark 定義成狀態 (state)

而狀態的分布如下,其中 covariance 可以拆成四個部分 (pose 本身關聯、pose 和 map 關聯、map 本身關聯)

Prediction Model

  • Prediction Model

  • Linearized the velocity motion model (對 prediction model 微分)

Observation Model

  • Given observation model

  • Linearized the observation model (對 observation model 微分)

  • 矩陣大小為 2 * 5

    • 2 為某個地標的 x, y 座標

    • 5 為自走車 pose 的 3 個變數 + 地標的 2 個座標 (x, y)

  • 如果今天觀察 l 個地標

    • 那矩陣大小就是 (2l) * (3 + 2l)

Summary

我們可以建構關聯性的轉換矩陣,把上面兩種的局部結果,轉換到全局的整個狀態情況下

  • Prediction model (3*n, n 為狀態數量)

  • Observation model (5*n, 左上角 3 個與 pose 有關, 其餘每 2 個為 landmark)

所以我們可以把移動到新位置的公式寫作 xk=f(xk−1,ukwk)\mathbf{x}_k = f(\mathbf{x}_{k-1}, \mathbf{u}_k \mathbf{w}_k)xk​=f(xk−1​,uk​wk​)

下一個位置 (xk\mathbf{x}_kxk​) 等於以下三者一起計算出來的

前一個位置 (xk−1\mathbf{x}_{k-1}xk−1​)

控制指令 (uk\mathbf{u}_kuk​)

移動的 noise (wk\mathbf{w}_kwk​)

自走車行走中,同時也會用 sensor 來感測周圍的標的物 (mj\mathbf{m}_jmj​),計算測量值 (zk,j\mathbf{z}_{k, j}zk,j​)

在時間 k 測量目標 j 的結果可以寫成 zk,j=h(mj,xk,vk,j)\mathbf{z}_{k, j} = h(\mathbf{m}_j, \mathbf{x}_k, \mathbf{v}_{k, j})zk,j​=h(mj​,xk​,vk,j​)

在時間 k 對目標 j 測量的值 (zk,j\mathbf{z}_{k, j}zk,j​) 等於以下三者所計算出來的

目標物 (mj\mathbf{m}_jmj​)

車子位置 (xk\mathbf{x}_kxk​)

測量的 noise (vk,j\mathbf{v}_{k, j}vk,j​)

可以看到 localize 和 mapping 都會有誤差,分別是 wk\mathbf{w}_kwk​ 和 vk,j\mathbf{v}_{k, j}vk,j​

wk\mathbf{w}_kwk​ 造成粉紅色的 location uncertainty

vk,j\mathbf{v}_{k, j}vk,j​ 造成藍色的 map uncertainty

而 SLAM 問題就是如何利用帶有這些 noise 的資料,也就是 u\mathbf{u}u 和 z\mathbf{z}z,來估計自走車狀態 (x\mathbf{x}x)、和目標物狀態 (m\mathbf{m}m)

Noise (wt,vt\mathbf{w}_t, \mathbf{v}_twt​,vt​) 被自動 model 在這個機率模型裡面

xt=f(xt−1,ut,wt)zt=h(m,xt,vt)\begin{aligned} &\mathbf{x}_{t}=f\left(\mathbf{x}_{t-1}, \mathbf{u}_{t}, \mathbf{w}_{t}\right)\\ &\mathbf{z}_{t}=h\left(\mathbf{m}, \mathbf{x}_{t}, \mathbf{v}_{\mathbf{t}}\right) \end{aligned}​xt​=f(xt−1​,ut​,wt​)zt​=h(m,xt​,vt​)​

SLAM 有三個前端架構,結合在一起可以在特定時間 t 建立車子的位置 (pose, xt\mathbf{x}_txt​) 和環境的地圖 (m\mathbf{m}m)

從前一刻的 xt−1\mathbf{x}_{t-1}xt−1​ 還有同時刻的 ut\mathbf{u}_tut​ 來推測該時刻的 xt\mathbf{x}_txt​

根據目前觀測資訊 zt\mathbf{z}_tzt​ 來推測目前的位置狀態 xt\mathbf{x}_txt​

根據目前觀測資訊 zt\mathbf{z}_tzt​ 來建構地圖 m\mathbf{m}m

MLE 看看哪一個參數 (θk\theta_kθk​) 的 likelihood 分布最有可能產生 samples (xxx)

可以看到在不同 θ\thetaθ 分布下產生 xxx 的機率為 likelihood (p(x∣θ)p(x\mid\theta)p(x∣θ))

而所有不同參數 p(x∣θ)p(x\mid\theta)p(x∣θ) 所連成的線就是 likelihood function (f(θ)f(\theta)f(θ))

我們想知道正面機率 (θ\thetaθ) 是多少,才造成上面的結果 (xxx),也就是要求 likelihood (p(x∣θ)p(x\mid\theta)p(x∣θ))

Find max⁡pθ(1−θ)4dθ(1−θ)4dθ=(1−θ)4+4θ(1−θ)3(−1)=(1−θ)3(5θ−1)=0θ=0.2\begin{aligned} &\text{Find } \max _{p} \theta(1-\theta)^{4}\\\\ &\frac{d \theta(1-\theta)^{4}}{d \theta}=(1-\theta)^{4}+4 \theta(1-\theta)^{3}(-1)=(1-\theta)^{3}(5 \theta-1)=0\\\\ &\theta = 0.2 \end{aligned}​Find pmax​θ(1−θ)4dθdθ(1−θ)4​=(1−θ)4+4θ(1−θ)3(−1)=(1−θ)3(5θ−1)=0θ=0.2​

p(θ)p(x∣θ)p(x)=p(θ∣x)\frac{p(\theta) p(x | \theta)}{p(x)}=p(\theta | x)p(x)p(θ)p(x∣θ)​=p(θ∣x)

[1/111/111/11⋮]×[(0)1(1)4(0.1)1(0.9)4(0.2)1(0.8)4⋮]p(x)=∑θp(x,θ)=∑θp(x∣θ)p(θ)=[0.0000.2130.333⋮]\frac{\begin{bmatrix} 1/11 \\ 1/11 \\ 1/11 \\\vdots \end{bmatrix} \times \begin{bmatrix} (0)^1(1)^4 \\ (0.1)^1(0.9)^4 \\ (0.2)^1(0.8)^4 \\\vdots \end{bmatrix} }{p(x) = \sum_\theta p(x, \theta) = \sum_\theta p(x\mid\theta)p(\theta)} = \begin{bmatrix} 0.000\\0.213\\0.333\\\vdots \end{bmatrix}p(x)=∑θ​p(x,θ)=∑θ​p(x∣θ)p(θ)​1/111/111/11⋮​​×​(0)1(1)4(0.1)1(0.9)4(0.2)1(0.8)4⋮​​​=​0.0000.2130.333⋮​​

Bayesian approach 會將參數 (θ\thetaθ) 帶入 prior、likelihood 計算出 posterior。posterior 再重新做為下一輪的 belief 進行計算,最終找出參數 (θ\thetaθ) 的分布

P(xt∣z1:t−1,u1:t)=∫P(xt∣xt−1,z1:t−1,u1:t)P(xt−1∣z1:t−1,u1:t)dxt−1=∫P(xt∣xt−1,ut)P(xt−1∣z1:t−1,u1:t)dxt−1\begin{aligned} P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) &=\int P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{x}_{t-1}, \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) \mathrm{P}\left(\mathbf{x}_{t-1} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) d x_{t-1} \\ &=\int P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{x}_{t-1}, \mathbf{u}_{t}\right) \mathrm{P}\left(\mathbf{x}_{t-1} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) d x_{t-1} \end{aligned}P(xt​∣z1:t−1​,u1:t​)​=∫P(xt​∣xt−1​,z1:t−1​,u1:t​)P(xt−1​∣z1:t−1​,u1:t​)dxt−1​=∫P(xt​∣xt−1​,ut​)P(xt−1​∣z1:t−1​,u1:t​)dxt−1​​

我們可以用 u1\mathbf{u}_1u1​ 到 ut\mathbf{u}_tut​

以及 z1\mathbf{z}_1z1​ 到 zt\mathbf{z}_tzt​

來估算當前時間點的 xt\mathbf{x}_txt​

化簡中,因為 xt−1\mathbf{x}_{t-1}xt−1​ 為已知

所以 xt−1\mathbf{x}_{t-1}xt−1​ 之前的觀測資訊就都不重要了

bel‾(xt)=∫P(xt∣xt−1,ut)bel(xt)dxt−1\overline{b e l}\left(\mathbf{x}_{\mathrm{t}}\right)=\int P\left(\mathbf{x}_{\mathrm{t}} \mid \mathbf{x}_{t-1}, \mathbf{u}_{t}\right) b e l\left(\mathbf{x}_{\mathrm{t}}\right) d x_{t-1}bel(xt​)=∫P(xt​∣xt−1​,ut​)bel(xt​)dxt−1​

bel‾(xt)\overline{b e l}\left(\mathbf{x}_{\mathrm{t}}\right)bel(xt​) 為當下時刻的估測

當下時刻還沒觀測到同時間的 zt\mathbf{z}_tzt​

bel(xt)b e l\left(\mathbf{x}_{\mathrm{t}}\right)bel(xt​) 為前一時刻的估測

已經觀測到該時間點的 tt−1\mathbf{t}_{t-1}tt−1​

當我們得到了觀測資訊 (zt\mathbf{z}_tzt​) 就可以用來更新位置資訊 (xt\mathbf{x}_txt​)

P(xt∣z1:t,u1:t)=P(zt∣xt,z1:t−1,u1:t)P(xt∣z1:t−1,u1:t)P(zt∣z1:t−1,u1:t)=ηP(zt∣xt,z1:t−1,u1:t)P(xt∣z1:t−1,u1:t)=ηP(zt∣xt)P(xt∣z1:t−1,u1:t)\begin{aligned} P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{z}_{1: t}, \mathbf{u}_{1: t}\right) &=\frac{P\left(\mathbf{z}_{\mathrm{t}} | \mathbf{x}_{\mathrm{t}}, \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right)}{P\left(\mathbf{z}_{\mathrm{t}} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right)} \\ &=\eta P\left(\mathbf{z}_{\mathrm{t}} | \mathbf{x}_{\mathrm{t}}, \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) \\ &=\eta P\left(\mathbf{z}_{\mathrm{t}} | \mathbf{x}_{\mathrm{t}}\right) P\left(\mathbf{x}_{\mathrm{t}} | \mathbf{z}_{1: t-1}, \mathbf{u}_{1: t}\right) \\ \end{aligned}P(xt​∣z1:t​,u1:t​)​=P(zt​∣z1:t−1​,u1:t​)P(zt​∣xt​,z1:t−1​,u1:t​)P(xt​∣z1:t−1​,u1:t​)​=ηP(zt​∣xt​,z1:t−1​,u1:t​)P(xt​∣z1:t−1​,u1:t​)=ηP(zt​∣xt​)P(xt​∣z1:t−1​,u1:t​)​

可以看到左邊的算式中有 z1:t\mathbf{z}_{1:t}z1:t​

但右邊的只有 z1:t−1\mathbf{z}_{1:t-1}z1:t−1​

bel(xt)=ηP(zt∣xt)bel‾(xt)b e l\left(\mathbf{x}_{\mathrm{t}}\right)=\eta P\left(\mathbf{z}_{\mathrm{t}} | \mathbf{x}_{t}\right) \overline{b e l}\left(\mathbf{x}_{\mathrm{t}}\right)bel(xt​)=ηP(zt​∣xt​)bel(xt​)

belbelbel 表示有 zt\mathbf{z}_tzt​ 資訊

bel‾\overline{bel}bel 表示沒有 zt\mathbf{z}_tzt​ 資訊

一開始的 bel(xt)bel(\mathbf{x}_t)bel(xt​) 是 prior distribution

感測到 z1\mathbf{z}_1z1​ 得到 likelihood (P(zt∣xt)P(\mathbf{z}_t\mid\mathbf{x}_t)P(zt​∣xt​)) 後可以更新 bel(x1)bel(\mathbf{x}_1)bel(x1​)

接著有了 u2\mathbf{u}_2u2​ 可以更新運動狀態 bel‾(x2)\overline{bel}(\mathbf{x}_2)bel(x2​)

接著一樣感測到 z2\mathbf{z}_2z2​ 更新回去得到最新的 bel(x2)bel(\mathbf{x}_2)bel(x2​)

機器人透過 prior 分布 (原本就預測的目的地, xkprex_k^{\text{pre}}xkpre​) 和 likelihood 分布 (感應地標後得到的目的地, xkobsx_k^{\text{obs}}xkobs​)

結合兩個分布就能得到 posterior 分布 (最終決定移動的點, xkestx_k^{\text{est}}xkest​)

xk=Axk−1+Buk+wkzk=Hxk+vk\begin{aligned} &x_{k}=A x_{k-1}+B u_{k}+w_{k}\\ &z_{k}=H x_{k}+v_{k} \end{aligned}​xk​=Axk−1​+Buk​+wk​zk​=Hxk​+vk​​

共有四個參數: A,B,Q,RA, B, Q, RA,B,Q,R

xkpre=Axk−1est+Bukx_{k}^{p r e}=A x_{k-1}^{e s t}+B u_{k}xkpre​=Axk−1est​+Buk​
Pkpre=APk−1estAT+QP_{k}^{p r e}=A P_{k-1}^{e s t} A^{T}+QPkpre​=APk−1est​AT+Q
Kk=PkpreHT(HPkpreHT+R)−1K_{k}=P_{k}^{p r e} H^{T}\left(H P_{k}^{p r e} H^{T}+R\right)^{-1}Kk​=Pkpre​HT(HPkpre​HT+R)−1
xkest=xkpre+Kk(zk−Hxkpre)x_{k}^{e s t}=x_{k}^{p r e}+K_{k}\left(z_{k}-H x_{k}^{p r e}\right)xkest​=xkpre​+Kk​(zk​−Hxkpre​)
Pkest=(I−KkH)PkpreP_{k}^{e s t}=\left(I-K_{k} H\right) P_{k}^{p r e}Pkest​=(I−Kk​H)Pkpre​
xk=f(xk−1,uk)+wkzk=h(xk)+vk\begin{aligned} &x_{k}=f\left(x_{k-1}, u_{k}\right)+w_{k}\\ &z_{k}=h\left(x_{k}\right)+v_{k} \end{aligned}​xk​=f(xk−1​,uk​)+wk​zk​=h(xk​)+vk​​
Fk=∂f(x^k−1,uk)∂x,Hk=∂h(x^k)∂xF_{k}=\frac{\partial f\left(\hat{x}_{k-1}, u_{k}\right)}{\partial x}, H_{k}=\frac{\partial h\left(\hat{x}_{k}\right)}{\partial x}Fk​=∂x∂f(x^k−1​,uk​)​,Hk​=∂x∂h(x^k​)​
xk=f(x^k−1,uk)+Fk(xk−1−x^k−1)+wkzk=h(x^k)+Hk(xk−x^k)+vk\begin{aligned} &x_{k}=f\left(\hat{x}_{k-1}, u_{k}\right)+F_{k}\left(x_{k-1}-\hat{x}_{k-1}\right)+w_{k}\\ &z_{k}=h\left(\hat{x}_{k}\right)+H_{k}\left(x_{k}-\hat{x}_{k}\right)+v_{k} \end{aligned}​xk​=f(x^k−1​,uk​)+Fk​(xk−1​−x^k−1​)+wk​zk​=h(x^k​)+Hk​(xk​−x^k​)+vk​​

xkpre=f(xk−1est,uk)Pkpre=FkPk−1preFkT+QKk=PkpreHT(HPkpreHT+R)−1xkest=xkpre+Kk(zk−Hxkpre)Pkest=(I−KkH)Pkpre\begin{aligned} &x_{k}^{p r e}=f\left(x_{k-1}^{e s t}, u_{k}\right)\\ &P_{k}^{\text {pre}}=F_{k} P_{k-1}^{\text {pre}} F_{k}^{T}+Q\\ &K_{k}=P_{k}^{p r e} H^{T}\left(H P_{k}^{p r e} H^{T}+R\right)^{-1}\\ &x_{k}^{e s t}=x_{k}^{p r e}+K_{k}\left(z_{k}-H x_{k}^{p r e}\right)\\ &P_{k}^{e s t}=\left(I-K_{k} H\right) P_{k}^{p r e} \end{aligned}​xkpre​=f(xk−1est​,uk​)Pkpre​=Fk​Pk−1pre​FkT​+QKk​=Pkpre​HT(HPkpre​HT+R)−1xkest​=xkpre​+Kk​(zk​−Hxkpre​)Pkest​=(I−Kk​H)Pkpre​​

sk=(x,y,θ⏟robot’s pose,m1,x,m1,y⏟landmark 1,m2,x,m2,y⏟landmark 2,…,mn,x,mn,y⏟landmark n)Ts_{k}=\left(\underbrace{x, y, \theta}_{\text{robot's pose}}, \underbrace{m_{1, x}, m_{1, y}}_{\text{landmark 1}}, \underbrace{m_{2, x}, m_{2, y}}_{\text{landmark 2}}, \ldots, \underbrace{m_{n, x}, m_{n, y}}_{\text{landmark n}}\right)^{T}sk​=​robot’s posex,y,θ​​,landmark 1m1,x​,m1,y​​​,landmark 2m2,x​,m2,y​​​,…,landmark nmn,x​,mn,y​​​​T

[xyθm1,xm1,y⋮mn,xmn,y]→μ=[xm],Σ=[ΣxxΣxmΣmxΣmm]\left[\begin{array}{c} x \\ y \\ \theta \\ m_{1,x} \\ m_{1,y} \\ \vdots \\ m_{n,x} \\ m_{n,y} \end{array}\right] \rightarrow \mu=\left[\begin{array}{c} \mathbf{x} \\ \mathbf{m} \end{array}\right], \Sigma=\left[\begin{array}{cc} \Sigma_{\mathbf{x x}} & \Sigma_{\mathbf{x m}} \\ \Sigma_{\mathbf{m x}} & \Sigma_{\mathbf{m m}} \end{array}\right]​xyθm1,x​m1,y​⋮mn,x​mn,y​​​→μ=[xm​],Σ=[Σxx​Σmx​​Σxm​Σmm​​]

[x′y′θ′]=[xyθ]+[−vωsin⁡(θ)+vωsin⁡(θ+ωtΔt)vωcos⁡(θ)−vωcos⁡(θ+ωtΔt)ωΔt]\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ \theta^{\prime} \end{array}\right]=\left[\begin{array}{l} x \\ y \\ \theta \end{array}\right]+\left[\begin{array}{c} -\frac{v}{\omega} \sin (\theta)+\frac{v}{\omega} \sin \left(\theta+\omega_{t} \Delta t\right) \\ \frac{v}{\omega} \cos (\theta)-\frac{v}{\omega} \cos \left(\theta+\omega_{t} \Delta t\right) \\ \omega \Delta t \end{array}\right]​x′y′θ′​​=​xyθ​​+​−ωv​sin(θ)+ωv​sin(θ+ωt​Δt)ωv​cos(θ)−ωv​cos(θ+ωt​Δt)ωΔt​​

Ftx=∂f∂(x,y,θ)T[x′y′θ′]=[10−vtωtcos⁡(θ)+vtωtcos⁡(θ+ωtΔt)01−vtωtsin⁡(θ)+vtωtsin⁡(θ+ωtΔt)001]F_t^x = \frac{\partial f}{\partial(x,y,\theta)^T}\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ \theta^{\prime} \end{array}\right] = \left[\begin{array}{ccc} 1 & 0 & -\frac{v_{t}}{\omega_{t}} \cos (\theta)+\frac{v_{t}}{\omega_{t}} \cos \left(\theta+\omega_{t} \Delta t\right) \\ 0 & 1 & -\frac{v_{t}}{\omega_{t}} \sin (\theta)+\frac{v_{t}}{\omega_{t}} \sin \left(\theta+\omega_{t} \Delta t\right) \\ 0 & 0 & 1 \end{array}\right]Ftx​=∂(x,y,θ)T∂f​​x′y′θ′​​=​100​010​−ωt​vt​​cos(θ)+ωt​vt​​cos(θ+ωt​Δt)−ωt​vt​​sin(θ)+ωt​vt​​sin(θ+ωt​Δt)1​​

zi=[qatan⁡2(δx,δy)−θ],δ=[mi,x−xmi,y−y],q=δTδz_{i}=\left[\begin{array}{c} \sqrt{q} \\ \operatorname{atan} 2\left(\delta_{x}, \delta_{y}\right)-\theta \end{array}\right], \delta=\left[\begin{array}{c} m_{i, x}-x \\ m_{i, y}-y \end{array}\right], q=\delta^{T} \deltazi​=[q​atan2(δx​,δy​)−θ​],δ=[mi,x​−xmi,y​−y​],q=δTδ

Hi=∂zi∂(x,y,θ,mi,x,mi,y)=1q[−qδx−qδy0qδxqδyδy−δx−q−δyδx]H^{i}=\frac{\partial z_{i}}{\partial\left(x, y, \theta, m_{i, x}, m_{i, y}\right)}=\frac{1}{q}\left[\begin{array}{ccccc} -\sqrt{q} \delta_{x} & -\sqrt{q} \delta_{y} & 0 & \sqrt{q} \delta_{x} & \sqrt{q} \delta_{y} \\ \delta_{y} & -\delta_{x} & -q & -\delta_{y} & \delta_{x} \end{array}\right]Hi=∂(x,y,θ,mi,x​,mi,y​)∂zi​​=q1​[−q​δx​δy​​−q​δy​−δx​​0−q​q​δx​−δy​​q​δy​δx​​]

Ft=[1000⋯00100⋯00010⋯0]T×FtxF_{t}=\left[\begin{array}{llllll} 1 & 0 & 0 & 0 & \cdots & 0 \\ 0 & 1 & 0 & 0 & \cdots & 0 \\ 0 & 0 & 1 & 0 & \cdots & 0 \end{array}\right]^{T} \times F_{t}^{x}Ft​=​100​010​001​000​⋯⋯⋯​000​​T×Ftx​

Ht=[1000⋯0000⋯00100⋯0000⋯00010⋯0000⋯00000⋯0100⋯00000⋯0010⋯0]×HtiH_{t}=\left[\begin{array}{ccccccccc} 1 & 0 & 0 & 0 & \cdots & 0 & 0 & 0 & 0 & \cdots & 0 \\ 0 & 1 & 0 & 0 & \cdots & 0 & 0 & 0 & 0 & \cdots & 0 \\ 0 & 0 & 1 & 0 & \cdots & 0 & 0 & 0 & 0 & \cdots & 0 \\ 0 & 0 & 0 & 0 & \cdots & 0 & 1 & 0 & 0 & \cdots & 0 \\ 0 & 0 & 0 & 0 & \cdots & 0 & 0 & 1 & 0 & \cdots & 0 \end{array}\right] \times H_{t}^{i}Ht​=​10000​01000​00100​00000​⋯⋯⋯⋯⋯​00000​00010​00001​00000​⋯⋯⋯⋯⋯​00000​​×Hti​

有了全局的 Ft,HtF_{t}, H_{t}Ft​,Ht​ 就可以帶進 EKF 中開始計算

xkpre=f(xk−1est,uk)Pkpre=FkPk−1preFkT+QKk=PkpreHT(HPkpreHT+R)−1xkest=xkpre+Kk(zk−Hxkpre)Pkest=(I−KkH)Pkpre\begin{aligned} &x_{k}^{p r e}=f\left(x_{k-1}^{e s t}, u_{k}\right)\\ &P_{k}^{\text {pre}}={\color{red}F_{k}} P_{k-1}^{\text {pre}} {\color{red}F_{k}^{T}}+Q\\ &K_{k}=P_{k}^{p r e} {\color{red}H^{T}}\left({\color{red}H} P_{k}^{p r e} {\color{red}H^{T}}+R\right)^{-1}\\ &x_{k}^{e s t}=x_{k}^{p r e}+K_{k}\left(z_{k}-{\color{red}H} x_{k}^{p r e}\right)\\ &P_{k}^{e s t}=\left(I-K_{k} {\color{red}H}\right) P_{k}^{p r e} \end{aligned}​xkpre​=f(xk−1est​,uk​)Pkpre​=Fk​Pk−1pre​FkT​+QKk​=Pkpre​HT(HPkpre​HT+R)−1xkest​=xkpre​+Kk​(zk​−Hxkpre​)Pkest​=(I−Kk​H)Pkpre​​