HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
distanceReset.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "hololib/config.hpp"
4#include "pros/distance.hpp"
5#include <vector>
6
7namespace hololib {
8/**
9 * @brief Configuration for a single distance sensor used in odometry reset.
10 */
12 pros::Distance& device; /**< Pointer to the PROS Distance sensor object */
13 double forward_offset; /**< Offset of the sensor from the center of rotation (forward direction) */
14 double strafe_offset; /**< Offset of the sensor from the center of rotation (strafe direction) */
15 double mounting_angle; /**< Mounting angle of the sensor in degrees relative to the robot heading */
16};
17
18/**
19 * @brief The resultant position calculated by distance sensors.
20 */
22 double x; /**< X coordinate of the robot */
23 double y; /**< Y coordinate of the robot */
24 bool using_odom_x; /**< True if the X coordinate is from odometry (sensor couldn't read X) */
25 bool using_odom_y; /**< True if the Y coordinate is from odometry (sensor couldn't read Y) */
26};
27
28/**
29 * @brief Handles resetting the robot's odometry using distance sensors.
30 *
31 * It calculates the absolute position on the field using distance to walls.
32 */
34private:
35 static constexpr double MM_TO_IN = 0.0393701;
36 static constexpr double FIELD_WIDTH = 3566.668 * MM_TO_IN;
37 static constexpr double FIELD_HEIGHT = 3566.668 * MM_TO_IN;
38 static constexpr double HALF_WIDTH = FIELD_WIDTH / 2.0;
39 static constexpr double HALF_HEIGHT = FIELD_HEIGHT / 2.0;
40 static constexpr double MAX_SENSOR_RANGE = 2000 * MM_TO_IN;
41 static constexpr double MIN_SENSOR_RANGE = 0 * MM_TO_IN;
42
43 std::vector<DistanceSensor> sensors;
44 float default_heading_tolerance;
45 float default_filter_range;
47
48 distancePose calculateGlobalPosition(const std::vector<DistanceSensor>& active_sensors,
49 double heading_deg,
50 double current_x,
51 double current_y);
52
53public:
54 /**
55 * @brief Construct a DistanceReset handler.
56 *
57 * @param robot_sensors Vector of DistanceSensor configurations.
58 * @param odom Reference to the encoder EKF odometry object.
59 * @param heading_tolerance Tolerance in degrees for the sensor to be considered perpendicular to the wall.
60 * @param filter_range Maximum acceptable deviation from the current odometry reading.
61 */
62 DistanceReset(const std::vector<DistanceSensor>& robot_sensors,
63 EncoderEKFOdometry& odom = ::odom,
64 float heading_tolerance = 40.0,
65 float filter_range = 3.5);
66
67 /**
68 * @brief Updates position using all configured sensors.
69 *
70 * @param setPose If true, automatically updates the chassis odometry with the calculated position.
71 * @param filter If true, applies filtering based on `filter_range`.
72 * @return distancePose The newly calculated position.
73 */
74 distancePose update(bool setPose = false, bool filter = true);
75
76 /**
77 * @brief Updates position using a specific set of sensors by flags.
78 *
79 * @param use_flags Boolean flags corresponding to each configured sensor (true to use).
80 * @param setPose If true, automatically updates the chassis odometry.
81 * @param filter If true, applies filtering.
82 * @return distancePose The newly calculated position.
83 */
84 distancePose update(const std::vector<bool>& use_flags, bool setPose = false, bool filter = true);
85
86 /**
87 * @brief Updates position using an explicitly provided list of active sensors.
88 *
89 * @param active_sensors Vector of sensors to use for this update.
90 * @param setPose If true, automatically updates the chassis odometry.
91 * @param filter If true, applies filtering.
92 * @return distancePose The newly calculated position.
93 */
94 distancePose updateSpecific(const std::vector<DistanceSensor>& active_sensors, bool setPose, bool filter);
95};
96} // namespace hololib
Handles resetting the robot's odometry using distance sensors.
distancePose updateSpecific(const std::vector< DistanceSensor > &active_sensors, bool setPose, bool filter)
Updates position using an explicitly provided list of active sensors.
DistanceReset(const std::vector< DistanceSensor > &robot_sensors, EncoderEKFOdometry &odom=::odom, float heading_tolerance=40.0, float filter_range=3.5)
Construct a DistanceReset handler.
distancePose update(const std::vector< bool > &use_flags, bool setPose=false, bool filter=true)
Updates position using a specific set of sensors by flags.
distancePose update(bool setPose=false, bool filter=true)
Updates position using all configured sensors.
Configuration for a single distance sensor used in odometry reset.
double forward_offset
Offset of the sensor from the center of rotation (forward direction)
double mounting_angle
Mounting angle of the sensor in degrees relative to the robot heading.
double strafe_offset
Offset of the sensor from the center of rotation (strafe direction)
pros::Distance & device
Pointer to the PROS Distance sensor object.
The resultant position calculated by distance sensors.
bool using_odom_x
True if the X coordinate is from odometry (sensor couldn't read X)
bool using_odom_y
True if the Y coordinate is from odometry (sensor couldn't read Y)
double y
Y coordinate of the robot.
double x
X coordinate of the robot.