![eb10ddaaa85b9fd27ab1bce50ccec36d.png](https://img-blog.csdnimg.cn/img_convert/eb10ddaaa85b9fd27ab1bce50ccec36d.png)
Extended Kalman Filter Implementation for Constant Turn Rate and Acceleration(CTRA) Vehicle Model in Python.
![71eb02677b90fa0cb134eef9e06bbec4.png](https://img-blog.csdnimg.cn/img_convert/71eb02677b90fa0cb134eef9e06bbec4.png)
- 扩展的卡尔曼滤波器,其状态转移和观察模型不需要一定是状态的线性函数,而是状态的可微函数;
-
-
- 这里,
和
是过程和观测噪声,假设它们均为零均值多变量高斯噪声,协方差矩阵分别记为
和
-
函数可以根据先前估计值
来计算现在状态的估计值,
函数可以从预测状态中计算出预测测量值。但是,
和
不可以直接应用于协方差矩阵,而是通过一个偏微分矩阵(雅克比矩阵
)
- 在每一个时间增量步,通过当前预估状态评估雅克比行列式,这些Matrix被用在卡尔曼滤波器等式中,该过程基本上使目前估计值周围的非线性函数线性化。
- 情境:Situation coverd...
- 你有一个速度传感器,测量车辆速度(
)以及车头的方向(
)以及一个偏航(Yaw)角速度传感器(
),这些与一个GPS传感器的坐标信息(x&y)进行融合。
- 你有一个速度传感器,测量车辆速度(
必要工具包
![fd4c35e3fb204c6d129fc0815f405e1e.png](https://img-blog.csdnimg.cn/img_convert/fd4c35e3fb204c6d129fc0815f405e1e.png)
状态向量——常转速以及加速度车辆模型(Constant Turn Rate and Acceleration Vehicle Model CTRA)
![63e5070e4dfc4d391a625e9699fc08f8.png](https://img-blog.csdnimg.cn/img_convert/63e5070e4dfc4d391a625e9699fc08f8.png)
![206d5cf03fe497d94666fc786d54cd46.png](https://img-blog.csdnimg.cn/img_convert/206d5cf03fe497d94666fc786d54cd46.png)
- 首先将各个状态变量定义好
![7873e94fca401f62b19a8ba84e229c02.png](https://img-blog.csdnimg.cn/img_convert/7873e94fca401f62b19a8ba84e229c02.png)
- 可以得到:状态向量与动力学矩阵的字符表达(很简单,可以自己推一下):
![493ebf6e57c0ced2b6272a4c03d23275.png](https://img-blog.csdnimg.cn/img_convert/493ebf6e57c0ced2b6272a4c03d23275.png)
![b38cc6475307f1f75c370311903d45dc.png](https://img-blog.csdnimg.cn/img_convert/b38cc6475307f1f75c370311903d45dc.png)
- 同时,利用如下语句,可以得到该模型的雅克比矩阵
![4bc5a31d295a6e5ddc2c819a89b8febf.png](https://img-blog.csdnimg.cn/img_convert/4bc5a31d295a6e5ddc2c819a89b8febf.png)
![49fcb37a573bd4c47c92ba241adb0950.png](https://img-blog.csdnimg.cn/img_convert/49fcb37a573bd4c47c92ba241adb0950.png)
- 这个雅克比矩阵,在每一个过滤器step进行计算,因为其包含了各个状态变量;
- P.S. A.topython 和 .to_c 或者.to_matlab可以生成相应格式的代码;
初始化不确定矩阵
- 注意,如果以0来初始这个矩阵
,这就代表着,你非常确定该车辆的启动位置;
![67630db8bb1f7bb9cb74dc837e87e502.png](https://img-blog.csdnimg.cn/img_convert/67630db8bb1f7bb9cb74dc837e87e502.png)
![b5578427b2ee5774086fb66c2394efa1.png](https://img-blog.csdnimg.cn/img_convert/b5578427b2ee5774086fb66c2394efa1.png)
处理噪声协方差矩阵Q
- 按照论文里面进行模型的处理,该论文指出,状态不确定性模型激发线性系统的扰动,从概念上来说,其评估了当系统在给定时间段内开环运行时会有多糟糕。
![986f8afe8bd8d59d71d8092b071f6245.png](https://img-blog.csdnimg.cn/img_convert/986f8afe8bd8d59d71d8092b071f6245.png)
![b99f8e0143d7d06bc9f8744b6c590215.png](https://img-blog.csdnimg.cn/img_convert/b99f8e0143d7d06bc9f8744b6c590215.png)
读取测量数据
![8a955ef80ca33955770b29f1fa0fe6b3.png](https://img-blog.csdnimg.cn/img_convert/8a955ef80ca33955770b29f1fa0fe6b3.png)
其中注意,对于course要做如下处理:course = -course + 90°,原因很简单,航向为0°,意味着这两车在成向整备方向行驶,90°意味着这辆车正在沿者正东方向行驶。后面的计算,我们 规定正东方向是0°,而正北方向是90°,这需要统一(参考坐标系)。
测量函数H
- 矩阵
是测量函数H关于各个状态变量的雅克比矩阵,
- 如果有可用的GPS测量值,下面的函数将状态变量映射到测量值。
- 如果没有可用的GPS测量值,简单的设置
为0矩阵。
![955f990f19393382d5da47f9e4743a02.png](https://img-blog.csdnimg.cn/img_convert/955f990f19393382d5da47f9e4743a02.png)
![3e438f8fd118307049a1896fb547d6f9.png](https://img-blog.csdnimg.cn/img_convert/3e438f8fd118307049a1896fb547d6f9.png)
测量噪声协方差矩阵R
- 实际使用时,不确定性估计采用状态估计和测量的相对权重的重要性大小,也就是说R大,则状态估计值占比会比较大,R小则观测值(测量值)的占比较大,所以,不确定性估计是否绝对正确不是那么重要,因为其在每一种模型中的占比相对一致。
![f79bc0ed725293f9eea10003d1cef4c9.png](https://img-blog.csdnimg.cn/img_convert/f79bc0ed725293f9eea10003d1cef4c9.png)
![07c12e6f654fc7a1f69cbbae4cc3d03d.png](https://img-blog.csdnimg.cn/img_convert/07c12e6f654fc7a1f69cbbae4cc3d03d.png)
将经纬度信息转化为m为单位的坐标信息
![d132f6598c4adf88636282c2793ee812.png](https://img-blog.csdnimg.cn/img_convert/d132f6598c4adf88636282c2793ee812.png)
初始化State
- 利用下段代码,就可以初始化车辆的初始坐标以及方向;
![5b862822d78e89bfea9c1d1108862fac.png](https://img-blog.csdnimg.cn/img_convert/5b862822d78e89bfea9c1d1108862fac.png)
![93f0036f8f095c60177661c58ca8c410.png](https://img-blog.csdnimg.cn/img_convert/93f0036f8f095c60177661c58ca8c410.png)
将所有观测量几何成一个vector
![2b6abef588e0c70b9f485f5a05036f90.png](https://img-blog.csdnimg.cn/img_convert/2b6abef588e0c70b9f485f5a05036f90.png)
进行EKF扩展卡尔曼滤波算法
- 按照Dynamic Equation对每个状态变量进行预测
- 计算Jacobin矩阵
- 预测误差协方差
- 计算卡尔曼增益K
- 根据观测值来更新预测值
- 更新误差协方差矩阵P
for
![ea3fb20c1517cb3b336271931fac79d7.png](https://img-blog.csdnimg.cn/img_convert/ea3fb20c1517cb3b336271931fac79d7.png)
Plot结果
- 不确定性
![07260bf709bbacd212e66ce2cfb9c64f.png](https://img-blog.csdnimg.cn/img_convert/07260bf709bbacd212e66ce2cfb9c64f.png)
- 卡尔曼增益
![98002e71b7b071a39dbfae770228047e.png](https://img-blog.csdnimg.cn/img_convert/98002e71b7b071a39dbfae770228047e.png)
- 各个状态变量的跟踪情况
![de67c449a8d72e8c192740dc352fe0fb.png](https://img-blog.csdnimg.cn/img_convert/de67c449a8d72e8c192740dc352fe0fb.png)
- 位置X/Y的跟踪详情
![721445d82d5593ef6da87a346a3667c9.png](https://img-blog.csdnimg.cn/img_convert/721445d82d5593ef6da87a346a3667c9.png)
![2de7449a8744bfc9d28f56539a2ae9fe.png](https://img-blog.csdnimg.cn/img_convert/2de7449a8744bfc9d28f56539a2ae9fe.png)
通过使用EKF,达到很好的预测跟踪效果~