当前位置:网站首页>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 :
边栏推荐
猜你喜欢
What is the Bluetooth chip ble, how to select it, and what is the path of subsequent technology development
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
CRM Customer Relationship Management System
Second hand housing data analysis and prediction system
[real case] trap of program design - beware of large data
CRM客户关系管理系统
Istio deployment: quickly start microservices,
接口测试到底怎么做?看完这篇文章就能清晰明了
KT148A语音芯片ic的硬件设计注意事项
有时候只查询一行语句,执行也慢
随机推荐
通信人的经典语录,第一条就扎心了……
Cron表达式(七子表达式)
【Kubernetes系列】kubeadm reset初始化前后空间、内存使用情况对比
AcWing 1127. Sweet butter solution (shortest path SPFA)
【实习】解决请求参数过长问题
Second hand housing data analysis and prediction system
Refactoring: improving the design of existing code (Part 2)
Educational codeforces round 129 (rated for Div. 2) supplementary problem solution
从20s优化到500ms,我用了这三招
After eight years of test experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
sql-labs
功能、作用、效能、功用、效用、功效
[QT] QPushButton creation
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
After writing 100000 lines of code, I sent a long article roast rust
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
AcWing 181. Turnaround game solution (search ida* search)
自动生成VGG图像注释文件
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
编写完10万行代码,我发了篇长文吐槽Rust