当前位置:网站首页>Driverless learning (III): Kalman filter
Driverless learning (III): Kalman filter
2022-07-02 20:04:00 【biter0088】
1、 Write Kalman filter
Refer to the link below , Give comments on the basis of links , Write the Kalman filter as :kalmanfilter.h
#ifndef KALMAN_FILTER_H
#define KALMAN_FILTER_H
#include "Eigen/Dense"
using namespace std;
class KalmanFilter{// Define a Kalman filter class
public:
//constructor: Is a method for creating and initializing “class Objects created ” Special method
KalmanFilter(){
is_initalized_= false;
};
//destructor Destructor , Contrary to constructors ;
// When an object ends its life cycle , When the function of the object has been called , The system automatically performs the destructor
//~KalmanFilter();
void Initalization(Eigen::VectorXd x_in){
x_= x_in;
is_initalized_= true;
//cout<<"intialized"<<endl;
}
bool IsInitalized(){
return is_initalized_;
}
Eigen::VectorXd GetX(){
return x_;
}
// State transition matrix F_( Set function ):state transistion matrix
// You can give it first F_in assignment , And then call SetF() Function pair state transition matrix F_ Assign a value
void SetF(Eigen::MatrixXd F_in){
F_ = F_in;
}
// State covariance matrix ( Set function ):state covariance matrix
void SetP(Eigen::MatrixXd P_in){
P_ = P_in;
}
// Process noise matrix ( Set function ):process covariance matrix
void SetQ(Eigen::MatrixXd Q_in){
Q_ = Q_in;
}
//x'= Fx + u. Next u Set to 0, That is, the external influence is ignored ( Simplify the model )
//P' = F*P*Ft + Q
void Prediction(){
//cout<<"prediction"<<endl;
x_ = F_ * x_;
//cout<<" Predictive value "<<x_<<endl;
//cout<<" Predictive value F "<<F_<<endl;
Eigen::MatrixXd Ft = F_.transpose();
P_ = F_ * P_ * Ft + Q_;
}
// Measurement matrix :Measurement Matrix
void SetH(Eigen::MatrixXd H_in){
H_ = H_in;
}
// Measurement noise matrix :measurement covariance matrix
void SetR(Eigen::MatrixXd R_in){
R_ = R_in;
}
// forecast -- to update
// y=z-Hx' Actual observations z And the forecast x' Difference between y
// S=H*P*Ht+R S It's a temporary variable
// K=P'*Ht*S.inverse() K: Kalman gain , yes y The weight of the value
void Update(const Eigen::VectorXd &z){
// forecast
Eigen::VectorXd y = z - H_ * x_;
Eigen::MatrixXd S = H_ * P_ * H_.transpose() + R_;
Eigen::MatrixXd K = P_ * H_.transpose()*S.inverse(); // Kalman gain
// to update
x_ = x_+(K*y);// Update the current state vector
//cout<<" Update or get value "<<x_<<endl;
int size = x_.size();// Used to construct identity matrix
Eigen::MatrixXd I = Eigen::MatrixXd::Identity(size, size);
P_ = (I - K*H_)*P_;// Update the uncertainty of the system
}
// Defining parameters
private:
bool is_initalized_;// Whether to initialize
Eigen::VectorXd x_; //state vector State vector
Eigen::MatrixXd F_; // State transition matrix
Eigen::MatrixXd P_; // State covariance
Eigen::MatrixXd Q_; // noise
Eigen::MatrixXd H_; // Measurement matrix
Eigen::MatrixXd R_; // noise
};
#endif
Reference link :
边栏推荐
- After writing 100000 lines of code, I sent a long article roast rust
- Notes on hardware design of kt148a voice chip IC
- AcWing 1135. Happy New Year (shortest path + search)
- 【实习】解决请求参数过长问题
- 自动生成VGG图像注释文件
- HDL design peripheral tools to reduce errors and help you take off!
- How to realize the function of detecting browser type in Web System
- Kt148a voice chip IC software reference code c language, first-line serial port
- What are the benefits of multi terminal applet development? Covering Baidu applet, Tiktok applet, wechat applet development, and seizing the multi platform traffic dividend
- 开始练习书法
猜你喜欢
Attack and defense world PWN question: Echo
SQLite 3.39.0 release supports right external connection and all external connection
KS004 基于SSH通讯录系统设计与实现
Overview of browser caching mechanism
In depth understanding of modern web browsers (I)
【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
JASMINER X4 1U深度拆解,揭开高效省电背后的秘密
How to realize the function of detecting browser type in Web System
[译]深入了解现代web浏览器(一)
upload-labs
随机推荐
KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
Kt148a voice chip IC software reference code c language, first-line serial port
【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
API documentation tool knife4j usage details
KT148A语音芯片ic的用户端自己更换语音的方法,上位机
Attack and defense world PWN question: Echo
自動生成VGG圖像注釋文件
自动生成VGG图像注释文件
Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
笔记本安装TIA博途V17后出现蓝屏的解决办法
Codeforces Round #771 (Div. 2)(A-C)
台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片
Exemple complet d'enregistrement du modèle pytoch + enregistrement du modèle pytoch seuls les paramètres d'entraînement sont - ils enregistrés? Oui (+ Solution)
有时候只查询一行语句,执行也慢
KT148A语音芯片ic的开发常见问题以及描述
Google Earth engine (GEE) - Landsat 9 image full band image download (Beijing as an example)
Génération automatique de fichiers d'annotation d'images vgg
RPD product: super power squad nanny strategy
for(auto a : b)和for(auto &a : b)用法