HoloLib
High-performance holonomic (X-Drive) control library for VEX V5
Loading...
Searching...
No Matches
ObstacleManager Class Reference

Manages a collection of obstacles and provides avoidance computations. More...

#include <obstacle.h>

Public Member Functions

 ObstacleManager ()=default
 Default constructor for ObstacleManager.
 
void setRobotDimensions (float width, float length)
 Set the dimensions of the robot to define its bounding box for collisions.
 
void addObstacle (float x, float y, float radius)
 Add a circular obstacle to the field representation.
 
void removeObstacle (size_t index)
 Remove an obstacle by its index.
 
void clearObstacles ()
 Clear all tracked obstacles.
 
const std::vector< Obstacle > & getObstacles () const
 Get the list of currently 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.
 
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.
 

Detailed Description

Manages a collection of obstacles and provides avoidance computations.

Provides methods for checking path intersections and generating vectors to steer away from potential collisions.

Definition at line 22 of file obstacle.h.

Constructor & Destructor Documentation

◆ ObstacleManager()

ObstacleManager::ObstacleManager ( )
default

Default constructor for ObstacleManager.

Member Function Documentation

◆ setRobotDimensions()

void ObstacleManager::setRobotDimensions ( float  width,
float  length 
)

Set the dimensions of the robot to define its bounding box for collisions.

Parameters
widthWidth of the robot.
lengthLength of the robot.

◆ addObstacle()

void ObstacleManager::addObstacle ( float  x,
float  y,
float  radius 
)

Add a circular obstacle to the field representation.

Parameters
xX coordinate of the obstacle.
yY coordinate of the obstacle.
radiusRadius of the obstacle.

◆ removeObstacle()

void ObstacleManager::removeObstacle ( size_t  index)

Remove an obstacle by its index.

Parameters
indexThe index of the obstacle in the internal vector.

◆ clearObstacles()

void ObstacleManager::clearObstacles ( )

Clear all tracked obstacles.

◆ getObstacles()

const std::vector< Obstacle > & ObstacleManager::getObstacles ( ) const

Get the list of currently tracked obstacles.

Returns
const std::vector<Obstacle>& Reference to the obstacle vector.

◆ checkIntersection()

bool ObstacleManager::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.

Parameters
startStart point of the segment.
endEnd point of the segment.
safety_marginExtra margin to add to the robot/obstacle bounds.
out_obstacleOutput parameter for the intersected obstacle.
out_closestOutput parameter for the closest point of intersection.
Returns
true if an intersection occurs, false otherwise.

◆ getAvoidanceTarget()

Eigen::Vector2f ObstacleManager::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.

Parameters
robot_posCurrent robot position.
target_posDesired goal position.
safety_marginExtra margin around obstacles.
clearanceDesired clearance distance from obstacles.
robot_heading_radCurrent robot heading in radians.
recursion_depthInternal use for recursive path-finding limitations.
Returns
Eigen::Vector2f The corrected target point to aim for.

◆ getPotentialFieldTarget()

Eigen::Vector2f ObstacleManager::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.

Parameters
robot_posCurrent robot position.
target_posDesired goal position.
kaAttractive force constant.
krRepulsive force constant.
influence_radiusDistance at which obstacles begin exerting repulsive force.
robot_heading_radCurrent robot heading in radians.
Returns
Eigen::Vector2f The resultant vector from potential fields.