107 const Eigen::Matrix3d& process_noise_matrix,
108 const rclcpp::Time last_update,
110 rclcpp::Time current_time_point =
111 rclcpp::Clock().now();
112 double dt = (current_time_point - last_update).seconds();
115 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
116 "predict - Process noise matrix: \n"
117 << process_noise_matrix);
119 Eigen::Matrix3d jacobian = this->
process_model->get_jacobian_velocities(state, accelerations, dt);
120 covariance = jacobian * covariance * jacobian.transpose() + process_noise_matrix;
121 state = this->
process_model->get_next_velocities(state, accelerations, dt);
127 double motor_rpm,
double steering_angle) {
128 Eigen::VectorXd predicted_observations = this->
observation_model_->expected_observations(state);
129 Eigen::VectorXd used_predicted_observations(4);
130 used_predicted_observations << predicted_observations(0), predicted_observations(1),
131 predicted_observations(4), predicted_observations(5);
132 Eigen::VectorXd observations = Eigen::VectorXd::Zero(4);
133 observations << wss_data.
fl_rpm, wss_data.
fr_rpm, steering_angle, motor_rpm;
134 Eigen::VectorXd y = observations - used_predicted_observations;
135 Eigen::MatrixXd jacobian = this->
observation_model_->expected_observations_jacobian(state);
136 Eigen::MatrixXd used_jacobian = Eigen::MatrixXd::Zero(4, 3);
137 used_jacobian.block(0, 0, 2, 3) = jacobian.block(0, 0, 2, 3);
138 used_jacobian.block(2, 0, 2, 3) = jacobian.block(4, 0, 2, 3);
139 double steering_to_vy = used_jacobian(2, 1);
140 used_jacobian.col(1).setZero();
141 used_jacobian(2, 1) = steering_to_vy;
142 Eigen::MatrixXd kalman_gain = covariance * used_jacobian.transpose() *
143 (used_jacobian * covariance * used_jacobian.transpose() +
148 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
149 "correct_wheels - Predicted observations: %f %f %f %f",
150 used_predicted_observations(0), used_predicted_observations(1),
151 used_predicted_observations(2), used_predicted_observations(3));
152 RCLCPP_DEBUG(rclcpp::get_logger(
"velocity_estimation"),
153 "correct_wheels - Observations: %f %f %f %f %f %f", observations(0), observations(1),
154 observations(2), observations(3), observations(4), observations(5));
155 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Covariance: \n"
157 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - y: \n" << y);
158 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Jacobian: \n"
160 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_wheels - Kalman gain: \n"
162 double prev_omega = state(2);
163 state += kalman_gain * y;
164 state(2) = prev_omega;
166 covariance = (Eigen::Matrix3d::Identity() - kalman_gain * used_jacobian) * covariance;
171 Eigen::VectorXd y = Eigen::VectorXd(1);
173 Eigen::MatrixXd jacobian = Eigen::MatrixXd(1, 3);
177 Eigen::MatrixXd kalman_gain =
178 covariance * jacobian.transpose() *
182 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Covariance: \n"
184 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - y: \n" << y);
185 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Jacobian: \n"
187 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"velocity_estimation"),
"correct_imu - Kalman gain: \n"
189 state += kalman_gain * y;
191 covariance = (Eigen::Matrix3d::Identity() - kalman_gain * jacobian) * covariance;
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.
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.