HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
odometry.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Eigen/Core" // IWYU pragma: export
5#include "pros/imu.hpp"
6#include "pros/motors.hpp"
7#include "pros/rotation.hpp"
8#include <cmath>
9#include <optional>
10#include <vector>
11
12namespace hololib {
13
14class PoseEKF;
15
16/**
17 * @brief Defines the orientation of an unpowered tracking wheel.
18 */
20
21/**
22 * @brief Configuration parameters for a tracking wheel.
23 */
25 int8_t port; /**< Sensor port number */
26 TrackingWheelOrientation orientation; /**< Orientation (horizontal or vertical) */
27 float xOffset; /**< Offset from tracking center on the X axis */
28 float yOffset; /**< Offset from tracking center on the Y axis */
29 float wheelDiameter; /**< Diameter of the tracking wheel */
30 float gearRatio; /**< Gear ratio between the wheel and the sensor */
31};
32/**
33 * @brief Core constants to configure the chassis dimensions and hardware.
34 */
36 float trackWidth = 0; /**< Distance between left and right wheels */
37 float drivetrainWidth = 0.0f; /**< Physical width of the drivetrain */
38 float drivetrainLength = 0.0f; /**< Physical length of the drivetrain */
39 float wheelDiameter; /**< Diameter of the drive wheels */
40 float gearRatio; /**< Gear ratio (motor rotations / wheel rotations) */
41};
42
44 float vx, vy, w;
45};
46
47struct Pose {
48 float x = 0, y = 0, theta = 0;
50};
51
53
54public:
55 /**
56 * @brief Constructor initializing the EKF Odometry system.
57 */
59 pros::Motor& fl, pros::Motor& fr, pros::Motor& bl, pros::Motor& br, pros::IMU& imu_sensor, ChassisConfig cfg);
60
61 /**
62 * @brief Main loop running the processing pipeline.
63 * @param period Task execution period in milliseconds.
64 */
65 void update(uint32_t period_ms);
66
67 /**
68 * @brief Spawns the processing task thread if not already running.
69 */
70 void startTask(uint32_t period_ms = 10);
71
72 /**
73 * @brief Adds a tracking wheel configuration to the pipeline.
74 */
76
77 /**
78 * @brief Clears tracking wheels and falls back to motor layout.
79 */
81
82 /**
83 * @brief Sets the pose of the robot.
84 */
85 void setPose(float x, float y, float theta);
86
87 /**
88 * @brief Sets the pose of the robot.
89 */
90 void setPose(Pose pose);
91
92 /**
93 * @brief Gets the pose of the robot.
94 */
95 Pose getPose(bool radians = false);
96
97 void setVelocityCalculations(bool state);
98 /**
99 * @brief Enable or disable the internal Extended Kalman Filter.
100 */
101 void setKalmanFilterEnabled(bool enabled);
102
103private:
104 // Core hardware connections
105 pros::Motor& frontLeft;
106 pros::Motor& frontRight;
107 pros::Motor& backLeft;
108 pros::Motor& backRight;
109 pros::IMU& imu;
110 ChassisConfig config;
111
112 // Previous iteration tracking metrics
113 float prev_fl;
114 float prev_fr;
115 float prev_bl;
116 float prev_br;
117 float prev_heading;
118
119 // Internal pipeline flags and state trackers
120 bool useTrackingWheels = false;
121 bool kfEnabled = true;
122 float trackingWheelMeasNoise = 0.0005f;
123 float measurementNoise = 0.001f; // Assumed baseline variant
124 bool velocityCalculationsOn = true;
125 float motionDistTraveled = 0.0f;
126
127 // Tracking sensor vectors
128 std::vector<TrackingWheelConfig> trackingWheelConfigs;
129 std::vector<pros::Rotation> trackingWheelSensors; // Matches explicit construction type (.port)
130 std::vector<float> prevTrackingPositions;
131
132 // Mutex, underlying filter system, and runtime task handles
133 pros::Mutex poseMutex;
134 std::optional<pros::Task> m_task = std::nullopt;
135
136 PoseEKF ekf;
137 Pose currentPose;
138};
139} // namespace hololib
void setPose(float x, float y, float theta)
Sets the pose of the robot.
void addTrackingWheel(TrackingWheelConfig config)
Adds a tracking wheel configuration to the pipeline.
Pose getPose(bool radians=false)
Gets the pose of the robot.
void clearTrackingWheels()
Clears tracking wheels and falls back to motor layout.
void startTask(uint32_t period_ms=10)
Spawns the processing task thread if not already running.
void setPose(Pose pose)
Sets the pose of the robot.
void setVelocityCalculations(bool state)
void setKalmanFilterEnabled(bool enabled)
Enable or disable the internal Extended Kalman Filter.
void update(uint32_t period_ms)
Main loop running the processing pipeline.
EncoderEKFOdometry(pros::Motor &fl, pros::Motor &fr, pros::Motor &bl, pros::Motor &br, pros::IMU &imu_sensor, ChassisConfig cfg)
Constructor initializing the EKF Odometry system.
Extended Kalman Filter implementation for maintaining the robot's pose.
Definition PoseEKF.hpp:18
TrackingWheelOrientation
Defines the orientation of an unpowered tracking wheel.
Definition odometry.hpp:19
Core constants to configure the chassis dimensions and hardware.
Definition odometry.hpp:35
float drivetrainLength
Physical length of the drivetrain.
Definition odometry.hpp:38
float drivetrainWidth
Physical width of the drivetrain.
Definition odometry.hpp:37
float trackWidth
Distance between left and right wheels.
Definition odometry.hpp:36
float gearRatio
Gear ratio (motor rotations / wheel rotations)
Definition odometry.hpp:40
float wheelDiameter
Diameter of the drive wheels.
Definition odometry.hpp:39
VelocityComponents velocity
Definition odometry.hpp:49
Configuration parameters for a tracking wheel.
Definition odometry.hpp:24
float xOffset
Offset from tracking center on the X axis.
Definition odometry.hpp:27
float gearRatio
Gear ratio between the wheel and the sensor.
Definition odometry.hpp:30
TrackingWheelOrientation orientation
Orientation (horizontal or vertical)
Definition odometry.hpp:26
float wheelDiameter
Diameter of the tracking wheel.
Definition odometry.hpp:29
float yOffset
Offset from tracking center on the Y axis.
Definition odometry.hpp:28
int8_t port
Sensor port number.
Definition odometry.hpp:25