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