Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
ekf.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <math.h>
4
5#include <Eigen/Dense>
6#include <Eigen/Sparse>
7#include <chrono>
8#include <memory>
9
11#include "config/parameters.hpp"
12#include "custom_interfaces/msg/velocities.hpp"
16
17class EKF : public VelocityEstimator {
18 rclcpp::Time _last_update_;
19 Eigen::Vector3d _state_ = Eigen::Vector3d::Zero();
20 Eigen::Matrix3d _covariance_ = Eigen::Matrix3d::Identity();
21 Eigen::Matrix3d _process_noise_matrix_;
24
27 double motor_rpm_;
29
31
32 // The following flags are used to keep track of which sensors have provided at least one
33 // measurement. This is necessary to ensure that the estimator is not used before all sensors have
34 // provided at least one measurement.
35 bool imu_data_received_ = false;
36 bool wss_data_received_ = false;
37 bool motor_rpm_received_ = false;
39
41 std::shared_ptr<VEObservationModel> observation_model_;
42 std::shared_ptr<BaseVelocityProcessModel> process_model;
43
54 void predict(Eigen::Vector3d& state, Eigen::Matrix3d& covariance,
55 const Eigen::Matrix3d& process_noise_matrix, const rclcpp::Time last_update,
57
71 void correct_wheels(Eigen::Vector3d& state, Eigen::Matrix3d& covariance,
72 common_lib::sensor_data::WheelEncoderData& wss_data, double motor_rpm,
73 double steering_angle);
74
75 void correct_imu(Eigen::Vector3d& state, Eigen::Matrix3d& covariance,
77
78public:
79 EKF(const VEParameters& params);
84 void imu_callback(const common_lib::sensor_data::ImuData& imu_data) override;
89 void wss_callback(const common_lib::sensor_data::WheelEncoderData& wss_data) override;
94 void motor_rpm_callback(double motor_rpm) override;
99 void steering_callback(double steering_angle) override;
101};
Definition ekf.hpp:17
common_lib::car_parameters::CarParameters car_parameters_
Definition ekf.hpp:40
Eigen::Vector3d _state_
Definition ekf.hpp:19
void correct_wheels(Eigen::Vector3d &state, Eigen::Matrix3d &covariance, common_lib::sensor_data::WheelEncoderData &wss_data, double motor_rpm, double steering_angle)
Correct the state estimate based on wheel speed sensor, resolver, and steering data.
Definition ekf.cpp:130
void motor_rpm_callback(double motor_rpm) override
Callback function for the motor RPM data that should be called by adapters when new motor RPM data is...
Definition ekf.cpp:64
bool wss_data_received_
Definition ekf.hpp:36
double steering_angle_
Definition ekf.hpp:28
Eigen::Matrix3d _covariance_
Definition ekf.hpp:20
Eigen::MatrixXd _wheels_measurement_noise_matrix_
Definition ekf.hpp:22
bool motor_rpm_received_
Definition ekf.hpp:37
bool _has_made_prediction_
Definition ekf.hpp:30
void predict(Eigen::Vector3d &state, Eigen::Matrix3d &covariance, const Eigen::Matrix3d &process_noise_matrix, const rclcpp::Time last_update, common_lib::sensor_data::ImuData &imu_data)
Predict velocities at the next index based on IMU measurements and current state.
Definition ekf.cpp:108
std::shared_ptr< BaseVelocityProcessModel > process_model
Definition ekf.hpp:42
double motor_rpm_
Definition ekf.hpp:27
common_lib::structures::Velocities get_velocities() override
Definition ekf.cpp:96
bool imu_data_received_
Definition ekf.hpp:35
void correct_imu(Eigen::Vector3d &state, Eigen::Matrix3d &covariance, common_lib::sensor_data::ImuData &imu_data)
Definition ekf.cpp:164
void imu_callback(const common_lib::sensor_data::ImuData &imu_data) override
Callback function for the IMU data that should be called by adapters when new IMU data is available.
Definition ekf.cpp:23
std::shared_ptr< VEObservationModel > observation_model_
Definition ekf.hpp:41
Eigen::Matrix3d _process_noise_matrix_
Definition ekf.hpp:21
rclcpp::Time _last_update_
Definition ekf.hpp:18
void steering_callback(double steering_angle) override
Callback function for the steering angle data that should be called by adapters when new steering ang...
Definition ekf.cpp:80
bool steering_angle_received_
Definition ekf.hpp:38
void wss_callback(const common_lib::sensor_data::WheelEncoderData &wss_data) override
Callback function for the wheel speed sensor data that should be called by adapters when new wheel sp...
Definition ekf.cpp:48
Eigen::MatrixXd _imu_measurement_noise_matrix_
Definition ekf.hpp:23
common_lib::sensor_data::WheelEncoderData wss_data_
Definition ekf.hpp:26
common_lib::sensor_data::ImuData imu_data_
Definition ekf.hpp:25
Interface for velocity estimators.
Definition estimator.hpp:12