HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
obstacle.h
Go to the documentation of this file.
1#pragma once
2
3#include "Eigen/Core"
4#include "Eigen/Dense"
5#include <cstddef>
6#include <vector>
7
8/**
9 * @brief Represents a physical obstacle on the field.
10 */
11struct Obstacle {
12 Eigen::Vector2f position; /**< 2D coordinate position of the obstacle */
13 float radius; /**< Radius of the obstacle used for avoidance */
14};
15
16/**
17 * @brief Manages a collection of obstacles and provides avoidance computations.
18 *
19 * Provides methods for checking path intersections and generating vectors to
20 * steer away from potential collisions.
21 */
23public:
24 /**
25 * @brief Default constructor for ObstacleManager.
26 */
27 ObstacleManager() = default;
28
29 /**
30 * @brief Set the dimensions of the robot to define its bounding box for
31 * collisions.
32 *
33 * @param width Width of the robot.
34 * @param length Length of the robot.
35 */
36 void setRobotDimensions(float width, float length);
37
38 /**
39 * @brief Add a circular obstacle to the field representation.
40 *
41 * @param x X coordinate of the obstacle.
42 * @param y Y coordinate of the obstacle.
43 * @param radius Radius of the obstacle.
44 */
45 void addObstacle(float x, float y, float radius);
46
47 /**
48 * @brief Remove an obstacle by its index.
49 *
50 * @param index The index of the obstacle in the internal vector.
51 */
52 void removeObstacle(size_t index);
53
54 /**
55 * @brief Clear all tracked obstacles.
56 */
58
59 /**
60 * @brief Get the list of currently tracked obstacles.
61 *
62 * @return const std::vector<Obstacle>& Reference to the obstacle vector.
63 */
64 const std::vector<Obstacle> &getObstacles() const;
65
66 /**
67 * @brief Check if a path segment intersects with any obstacle.
68 *
69 * @param start Start point of the segment.
70 * @param end End point of the segment.
71 * @param safety_margin Extra margin to add to the robot/obstacle bounds.
72 * @param out_obstacle Output parameter for the intersected obstacle.
73 * @param out_closest Output parameter for the closest point of intersection.
74 * @return true if an intersection occurs, false otherwise.
75 */
76 bool checkIntersection(const Eigen::Vector2f &start,
77 const Eigen::Vector2f &end, float safety_margin,
78 Obstacle &out_obstacle,
79 Eigen::Vector2f &out_closest) const;
80
81 /**
82 * @brief Calculate a target vector that avoids collisions while navigating
83 * towards a goal.
84 *
85 * @param robot_pos Current robot position.
86 * @param target_pos Desired goal position.
87 * @param safety_margin Extra margin around obstacles.
88 * @param clearance Desired clearance distance from obstacles.
89 * @param robot_heading_rad Current robot heading in radians.
90 * @param recursion_depth Internal use for recursive path-finding limitations.
91 * @return Eigen::Vector2f The corrected target point to aim for.
92 */
93 Eigen::Vector2f getAvoidanceTarget(const Eigen::Vector2f &robot_pos,
94 const Eigen::Vector2f &target_pos,
95 float safety_margin, float clearance,
96 float robot_heading_rad,
97 int recursion_depth = 0) const;
98
99 /**
100 * @brief Get an artificial potential field target vector.
101 *
102 * @param robot_pos Current robot position.
103 * @param target_pos Desired goal position.
104 * @param ka Attractive force constant.
105 * @param kr Repulsive force constant.
106 * @param influence_radius Distance at which obstacles begin exerting
107 * repulsive force.
108 * @param robot_heading_rad Current robot heading in radians.
109 * @return Eigen::Vector2f The resultant vector from potential fields.
110 */
111 Eigen::Vector2f getPotentialFieldTarget(const Eigen::Vector2f &robot_pos,
112 const Eigen::Vector2f &target_pos,
113 float ka, float kr,
114 float influence_radius,
115 float robot_heading_rad) const;
116
117private:
118 std::vector<Obstacle> obstacles;
119 float robot_width = 18.0f;
120 float robot_length = 18.0f;
121};
Manages a collection of obstacles and provides avoidance computations.
Definition obstacle.h:22
void clearObstacles()
Clear all tracked obstacles.
bool checkIntersection(const Eigen::Vector2f &start, const Eigen::Vector2f &end, float safety_margin, Obstacle &out_obstacle, Eigen::Vector2f &out_closest) const
Check if a path segment intersects with any obstacle.
const std::vector< Obstacle > & getObstacles() const
Get the list of currently tracked obstacles.
void addObstacle(float x, float y, float radius)
Add a circular obstacle to the field representation.
ObstacleManager()=default
Default constructor for ObstacleManager.
void removeObstacle(size_t index)
Remove an obstacle by its index.
void setRobotDimensions(float width, float length)
Set the dimensions of the robot to define its bounding box for collisions.
Eigen::Vector2f getAvoidanceTarget(const Eigen::Vector2f &robot_pos, const Eigen::Vector2f &target_pos, float safety_margin, float clearance, float robot_heading_rad, int recursion_depth=0) const
Calculate a target vector that avoids collisions while navigating towards a goal.
Eigen::Vector2f getPotentialFieldTarget(const Eigen::Vector2f &robot_pos, const Eigen::Vector2f &target_pos, float ka, float kr, float influence_radius, float robot_heading_rad) const
Get an artificial potential field target vector.
Represents a physical obstacle on the field.
Definition obstacle.h:11
Eigen::Vector2f position
2D coordinate position of the obstacle
Definition obstacle.h:12
float radius
Radius of the obstacle used for avoidance.
Definition obstacle.h:13