25 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"1 - State: %f %f %f", this->
_state_(0),
27 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"1 - Covariance: \n"
36 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"2 - State: %f %f %f", this->
_state_(0),
38 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"2 - Covariance: \n"
42 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"3 - State: %f %f %f", this->
_state_(0),
44 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"3 - Covariance: \n"
57 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"3 - State: %f %f %f", this->
_state_(0),
59 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"3 - Covariance: \n"
73 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"3 - State: %f %f %f", this->
_state_(0),
75 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"3 - Covariance: \n"
89 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
"3 - State: %f %f %f", this->
_state_(0),
91 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"3 - Covariance: \n"
101 velocities.
timestamp_ = rclcpp::Clock().now();
109 const Eigen::Matrix3d& process_noise_matrix,
const rclcpp::Time last_update,
111 rclcpp::Time current_time_point =
112 rclcpp::Clock().now();
113 double dt = (current_time_point - last_update).seconds();
117 Eigen::Matrix3d actual_process_noise_matrix = process_noise_matrix;
120 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
121 "predict - Process noise matrix: \n"
122 << actual_process_noise_matrix);
124 Eigen::Matrix3d jacobian = this->
process_model->get_jacobian_velocities(state, accelerations, dt);
125 covariance = jacobian * covariance * jacobian.transpose() + actual_process_noise_matrix;
126 state = this->
process_model->get_next_velocities(state, accelerations, dt);
132 double steering_angle) {
133 Eigen::VectorXd predicted_observations = this->
observation_model_->expected_observations(state);
134 Eigen::VectorXd observations = Eigen::VectorXd::Zero(6);
136 steering_angle, motor_rpm;
137 Eigen::VectorXd y = observations - predicted_observations;
138 Eigen::MatrixXd jacobian = this->
observation_model_->expected_observations_jacobian(state);
139 Eigen::MatrixXd kalman_gain =
140 covariance * jacobian.transpose() *
145 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
146 "correct_wheels - Predicted observations: %f %f %f %f %f %f",
147 predicted_observations(0), predicted_observations(1), predicted_observations(2),
148 predicted_observations(3), predicted_observations(4), predicted_observations(5));
149 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
150 "correct_wheels - Observations: %f %f %f %f %f %f", observations(0), observations(1),
151 observations(2), observations(3), observations(4), observations(5));
152 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Covariance: \n"
154 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - y: \n" << y);
155 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Jacobian: \n"
157 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Kalman gain: \n"
159 state += kalman_gain * y;
161 covariance = (Eigen::Matrix3d::Identity() - kalman_gain * jacobian) * covariance;
166 Eigen::VectorXd y = Eigen::VectorXd(1);
168 Eigen::MatrixXd jacobian = Eigen::MatrixXd(1, 3);
172 Eigen::MatrixXd kalman_gain =
173 covariance * jacobian.transpose() *
177 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Covariance: \n"
179 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - y: \n" << y);
180 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Jacobian: \n"
182 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Kalman gain: \n"
184 state += kalman_gain * y;
186 covariance = (Eigen::Matrix3d::Identity() - kalman_gain * jacobian) * covariance;
common_lib::car_parameters::CarParameters car_parameters_
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.
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...
Eigen::Matrix3d _covariance_
Eigen::MatrixXd _wheels_measurement_noise_matrix_
bool _has_made_prediction_
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.
std::shared_ptr< BaseVelocityProcessModel > process_model
common_lib::structures::Velocities get_velocities() override
EKF(const VEParameters ¶ms)
void correct_imu(Eigen::Vector3d &state, Eigen::Matrix3d &covariance, common_lib::sensor_data::ImuData &imu_data)
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.
std::shared_ptr< VEObservationModel > observation_model_
Eigen::Matrix3d _process_noise_matrix_
rclcpp::Time _last_update_
void steering_callback(double steering_angle) override
Callback function for the steering angle data that should be called by adapters when new steering ang...
bool steering_angle_received_
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...
Eigen::MatrixXd _imu_measurement_noise_matrix_
common_lib::sensor_data::WheelEncoderData wss_data_
common_lib::sensor_data::ImuData imu_data_
const std::map< std::string, std::function< std::shared_ptr< BaseVelocityProcessModel >()>, std::less<> > vel_process_models_map
const std::map< std::string, std::function< std::shared_ptr< VEObservationModel >(const common_lib::car_parameters::CarParameters &)>, std::less<> > ve_observation_models_map
double wheel_speed_noise_
std::string _ve_observation_model_name_
double imu_acceleration_noise_
double imu_rotational_noise_
double angular_velocity_process_noise_
std::string _process_model_name_
double steering_angle_noise_
common_lib::car_parameters::CarParameters car_parameters_
double rotational_velocity
Struct for wheel encoder data.
double rotational_velocity_noise_
double rotational_velocity