HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
PoseEKF.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <vector>
5#include "Eigen/Core"
6#include "Eigen/Dense"
7
8namespace hololib {
9
10struct TrackingWheelConfig;
11/**
12 * @brief Extended Kalman Filter implementation for maintaining the robot's
13 * pose.
14 *
15 * Fuses IMU heading and tracking wheel (or motor encoder) deltas to estimate
16 * X, Y, and Theta coordinates on the field.
17 */
18class PoseEKF {
19private:
20 Eigen::Vector3f x;
21 Eigen::Matrix3f P;
22 Eigen::Matrix<float, 1, 3> H;
23 float measurementNoise;
24 float xProcessNoise = 0.01f, yProcessNoise = 0.01f, thetaProcessNoise = 0.001f;
25
26public:
27 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
28
29 /**
30 * @brief Construct a new Pose EKF object.
31 *
32 * @param initial_x Starting X position.
33 * @param initial_y Starting Y position.
34 * @param initial_theta Starting heading.
35 */
36 PoseEKF(float initial_x, float initial_y, float initial_theta);
37
38 /**
39 * @brief Set the process noise values for the Kalman filter matrices.
40 *
41 * @param xNoise Process noise in the X direction.
42 * @param yNoise Process noise in the Y direction.
43 * @param thetaNoise Process noise for the heading.
44 * @param measNoise Measurement noise parameter.
45 */
46 void setProcessNoise(float xNoise, float yNoise, float thetaNoise, float measNoise);
47
48 /**
49 * @brief The prediction step of the EKF based on local relative movements.
50 *
51 * @param dx_local Change in local X position.
52 * @param dy_local Change in local Y position.
53 * @param dtheta Change in heading.
54 */
55 void predict(float dx_local, float dy_local, float dtheta);
56
57 /**
58 * @brief Update the state using absolute heading measured by an IMU.
59 *
60 * @param measured_theta Heading read from the IMU.
61 * @param dynamic_R Dynamic measurement noise.
62 */
63 void updateIMU(float measured_theta, float dynamic_R);
64
65 /**
66 * @brief Update the state using unpowered tracking wheels data.
67 *
68 * @param configs Vector of tracking wheel configurations.
69 * @param measured_deltas Measurement differences for each wheel since the
70 * last step.
71 * @param dx_local Estimated local X change.
72 * @param dy_local Estimated local Y change.
73 * @param dtheta Estimated heading change.
74 * @param wheel_noise Sensor noise for the tracking wheels.
75 */
76 void updateTrackingWheels(const std::vector<TrackingWheelConfig>& configs, const Eigen::VectorXf& measured_deltas,
77 float dx_local, float dy_local, float dtheta, float wheel_noise);
78
79 /**
80 * @brief Set specific process noises when using tracking wheels.
81 *
82 * @param xNoise Process noise in X direction.
83 * @param yNoise Process noise in Y direction.
84 * @param thetaNoise Process noise for the heading.
85 */
86 void setTrackingWheelNoise(float xNoise, float yNoise, float thetaNoise);
87
88 /**
89 * @brief Get current X position.
90 * @return float The X position.
91 */
92 float getX() const { return x(0); }
93
94 /**
95 * @brief Get current Y position.
96 * @return float The Y position.
97 */
98 float getY() const { return x(1); }
99
100 /**
101 * @brief Get current heading angle.
102 * @return float The heading in radians.
103 */
104 float getTheta() const { return x(2); }
105
106 /**
107 * @brief Reset the state to a specific pose.
108 *
109 * @param new_x New X position.
110 * @param new_y New Y position.
111 * @param new_theta New heading angle.
112 */
113 void setPose(float new_x, float new_y, float new_theta);
114};
115} // namespace hololib
Extended Kalman Filter implementation for maintaining the robot's pose.
Definition PoseEKF.hpp:18
void predict(float dx_local, float dy_local, float dtheta)
The prediction step of the EKF based on local relative movements.
float getY() const
Get current Y position.
Definition PoseEKF.hpp:98
EIGEN_MAKE_ALIGNED_OPERATOR_NEW PoseEKF(float initial_x, float initial_y, float initial_theta)
Construct a new Pose EKF object.
float getTheta() const
Get current heading angle.
Definition PoseEKF.hpp:104
void updateIMU(float measured_theta, float dynamic_R)
Update the state using absolute heading measured by an IMU.
void updateTrackingWheels(const std::vector< TrackingWheelConfig > &configs, const Eigen::VectorXf &measured_deltas, float dx_local, float dy_local, float dtheta, float wheel_noise)
Update the state using unpowered tracking wheels data.
void setPose(float new_x, float new_y, float new_theta)
Reset the state to a specific pose.
float getX() const
Get current X position.
Definition PoseEKF.hpp:92
void setTrackingWheelNoise(float xNoise, float yNoise, float thetaNoise)
Set specific process noises when using tracking wheels.
void setProcessNoise(float xNoise, float yNoise, float thetaNoise, float measNoise)
Set the process noise values for the Kalman filter matrices.