|
Formula Student Autonomous Systems
The code for the main driverless system
|
Generates optimal local paths. More...
#include <path_calculation.hpp>

Public Member Functions | |
| PathCalculation ()=default | |
| Construct a new default PathCalculation object. | |
| PathCalculation (const PathCalculationConfig &config) | |
| Construct a new PathCalculation object with configuration. | |
| std::vector< PathPoint > | calculate_path (const std::vector< Cone > &cone_array) |
| Generate a path from an array of cones. | |
| std::vector< PathPoint > | calculate_trackdrive (const std::vector< Cone > &cone_array) |
| Generate a closed loop path for trackdrive competition. | |
| void | set_vehicle_pose (const common_lib::structures::Pose &vehicle_pose) |
| Set the current vehicle position and orientation. | |
| bool | is_map_closed (std::vector< PathPoint > &path) const |
| Checks if the path forms a closed loop and closes it if the transition cost is below config_.close_cost_. | |
| std::vector< PathPoint > | get_path_to_car () const |
| Get the path from the start to a lookback distance behind the car’s current position. | |
| const std::vector< std::pair< Point, Point > > & | get_triangulations () const |
| Get the triangulation segments used in path generation. | |
| const std::vector< PathPoint > & | get_yellow_cones () const |
| Gets the list of yellow cones detected or used in the path calculation. | |
| const std::vector< PathPoint > & | get_blue_cones () const |
| Gets the list of blue cones detected or used in the path calculation. | |
Private Member Functions | |
| void | initialize_path_from_initial_pose () |
| Initialize the path from the vehicle's initial pose. | |
| void | update_path_from_past_path () |
| Initialize the path from the previous path. | |
| void | extend_path (int max_points) |
| Extend the path by adding midpoints. | |
| void | clear_path_state () |
| Reset path construction state. | |
| int | reset_path (bool should_reset) |
| Handle path reset when completing a lap. | |
| std::pair< std::shared_ptr< Midpoint >, std::shared_ptr< Midpoint > > | select_starting_midpoints () |
| Select the first two midpoints to start the path. | |
| std::vector< std::shared_ptr< Midpoint > > | select_candidate_midpoints (const Midpoint &anchor_pose, int num_candidates) const |
| Select candidate midpoints in front of the vehicle. | |
| std::pair< double, std::shared_ptr< Midpoint > > | find_best_next_midpoint (int depth, const std::shared_ptr< Midpoint > &previous, const std::shared_ptr< Midpoint > ¤t, double max_cost) const |
| Recursively find the best next midpoint using depth-first search. | |
| double | calculate_cost (double previous_x, double previous_y, double current_x, double current_y, double next_x, double next_y) const |
| Calculate the cost of transitioning through three consecutive points. | |
| void | discard_cones_along_path () |
| Invalidate cones and midpoints along the last path segment. | |
| void | discard_cone (const std::shared_ptr< Midpoint > &last_mp, const std::shared_ptr< Midpoint > ¤t_mp) |
| Determine which cone to discard between two consecutive midpoints. | |
| void | invalidate_midpoints_with_discarded_cones () |
| Mark midpoints as invalid if they use discarded cones. | |
| void | remove_invalid_neighbors () |
| Remove invalid neighbors from all midpoint connection lists. | |
| std::shared_ptr< Midpoint > | find_nearest_midpoint (const Point &target) const |
| Find the nearest valid midpoint to a target position. | |
| std::pair< int, double > | find_best_loop_closure (const std::vector< PathPoint > &path) const |
| Finds the best loop closure point in a path. | |
| std::vector< PathPoint > | get_path_points_from_colorpoints (const std::vector< Colorpoint > &colorpoints) const |
| Converts a vector of Colorpoint objects into a vector of PathPoint objects. | |
Private Attributes | |
| PathCalculationConfig | config_ |
| MidpointGenerator | midpoint_generator_ |
| common_lib::structures::Pose | initial_pose_ |
| common_lib::structures::Pose | vehicle_pose_ |
| bool | initial_pose_set_ = false |
| std::vector< Colorpoint > | path_to_car_ |
| std::vector< Colorpoint > | past_path_ |
| int | reset_path_counter_ = 0 |
| std::vector< std::shared_ptr< Midpoint > > | midpoints_ |
| std::vector< Colorpoint > | current_path_ |
| std::vector< PathPoint > | yellow_cones_ |
| std::vector< PathPoint > | blue_cones_ |
| std::unordered_map< Point, std::shared_ptr< Midpoint > > | point_to_midpoint_ |
| std::unordered_set< std::shared_ptr< Midpoint > > | visited_midpoints_ |
| std::unordered_set< std::shared_ptr< Cone > > | discarded_cones_ |
Generates optimal local paths.
PathCalculation computes navigation paths by creating midpoints between track cones and searching for optimal sequences using depth-first search with cost-based evaluation. It maintains continuity with previous paths and discards cones as they are passed.
Definition at line 33 of file path_calculation.hpp.
|
default |
Construct a new default PathCalculation object.
|
inlineexplicit |
Construct a new PathCalculation object with configuration.
| config | Configuration parameters for path calculation behavior. |
Definition at line 44 of file path_calculation.hpp.
|
private |
Calculate the cost of transitioning through three consecutive points.
Computes a weighted cost based on the distance (current→next) and the angle change (previous→current→next). Lower costs indicate smoother, more efficient paths.
| previous_x,previous_y | Coordinates of the previous point |
| current_x,current_y | Coordinates of the current point |
| next_x,next_y | Coordinates of the next point |
Definition at line 427 of file path_calculation.cpp.

Generate a path from an array of cones.
Processes cone positions to create an optimal navigation path. Updates the internal state to maintain path continuity between invocations.
| cone_array | Array of cones representing the track. |
Definition at line 13 of file path_calculation.cpp.


| std::vector< PathPoint > PathCalculation::calculate_trackdrive | ( | const std::vector< Cone > & | cone_array | ) |
Generate a closed loop path for trackdrive competition.
Creates a path that forms a complete loop around the track, with interpolated connections and overlap points for continuous traversal.
| cone_array | Array of cones representing the track. |
Definition at line 101 of file path_calculation.cpp.


|
private |
Reset path construction state.
Clears all internal tracking structures (current path, visited midpoints, discarded cones) to prepare for a fresh path calculation.
Definition at line 135 of file path_calculation.cpp.

|
private |
Determine which cone to discard between two consecutive midpoints.
Identifies the cone from the previous midpoint that is not used by the current midpoint, indicating it has been passed.
| last_mp | The previous midpoint in the path. |
| current_mp | The current midpoint in the path. |
Definition at line 476 of file path_calculation.cpp.

|
private |
Invalidate cones and midpoints along the last path segment.
Marks cones as discarded if they were on the side of the path that has been passed. Invalidates any midpoints that depend on discarded cones and removes invalid neighbors from connectivity lists.
Definition at line 450 of file path_calculation.cpp.


|
private |
Extend the path by adding midpoints.
Iteratively searches for optimal next midpoints using depth-first search until reaching the maximum point limit or exhausting valid options.
| max_points | Maximum number of new points to add. |
Definition at line 243 of file path_calculation.cpp.


|
private |
Finds the best loop closure point in a path.
| path | A vector of PathPoint objects representing the path to analyze. Each PathPoint must have a valid position with x and y coordinates. |
Definition at line 534 of file path_calculation.cpp.


|
private |
Recursively find the best next midpoint using depth-first search.
Performs a bounded DFS to evaluate continuation paths from the current midpoint, balancing between direction consistency and distance.
| depth | Current search depth (decrements toward base case). |
| previous | Previous midpoint in the path. |
| current | Current midpoint being evaluated. |
| max_cost | Cost threshold for pruning branches. |
Definition at line 388 of file path_calculation.cpp.


|
private |
Find the nearest valid midpoint to a target position.
Performs a linear search through all midpoints to locate the closest one within the tolerance distance.
| target | The target point to search around. |
Definition at line 516 of file path_calculation.cpp.

| const std::vector< PathPoint > & PathCalculation::get_blue_cones | ( | ) | const |
Gets the list of blue cones detected or used in the path calculation.
Definition at line 590 of file path_calculation.cpp.

|
private |
Converts a vector of Colorpoint objects into a vector of PathPoint objects.
| points | A vector containing the input Colorpoint objects. |
Definition at line 567 of file path_calculation.cpp.

| std::vector< PathPoint > PathCalculation::get_path_to_car | ( | ) | const |
Get the path from the start to a lookback distance behind the car’s current position.
Definition at line 580 of file path_calculation.cpp.


Get the triangulation segments used in path generation.
Definition at line 584 of file path_calculation.cpp.


| const std::vector< PathPoint > & PathCalculation::get_yellow_cones | ( | ) | const |
Gets the list of yellow cones detected or used in the path calculation.
Definition at line 588 of file path_calculation.cpp.

|
private |
Initialize the path from the vehicle's initial pose.
Selects the first two midpoints ahead of the vehicle to start the path when no previous path exists.
Definition at line 167 of file path_calculation.cpp.


|
private |
Mark midpoints as invalid if they use discarded cones.
Iterates through all midpoints and invalidates those whose defining cones have been marked as discarded.
Definition at line 491 of file path_calculation.cpp.

| bool PathCalculation::is_map_closed | ( | std::vector< PathPoint > & | path | ) | const |
Checks if the path forms a closed loop and closes it if the transition cost is below config_.close_cost_.
| path | The path to evaluate, modified in place if loop closure is found |
Definition at line 80 of file path_calculation.cpp.


|
private |
Remove invalid neighbors from all midpoint connection lists.
Filters out neighbors that have been invalidated from each midpoint's close_points list to maintain consistency.
Definition at line 502 of file path_calculation.cpp.

|
private |
Handle path reset when completing a lap.
Adjusts the maximum points allowed and clears historical path data when completing a circuit.
| should_reset | Whether to trigger a full path reset. |
Definition at line 145 of file path_calculation.cpp.

|
private |
Select candidate midpoints in front of the vehicle.
Uses a priority queue to identify the most promising midpoints ahead of the vehicle based on combined distance and angle cost.
| anchor_pose | Reference pose to evaluate candidates from. |
| num_candidates | Number of candidates to return. |
Definition at line 338 of file path_calculation.cpp.

|
private |
Select the first two midpoints to start the path.
Identifies candidate midpoints ahead of the vehicle and performs a cost-based search to select the best starting pair.
Definition at line 295 of file path_calculation.cpp.


| void PathCalculation::set_vehicle_pose | ( | const common_lib::structures::Pose & | vehicle_pose | ) |
Set the current vehicle position and orientation.
Propagates the vehicle pose to the midpoint generator and maintains the current pose for path calculations.
| vehicle_pose | The current vehicle position and orientation. |
Definition at line 160 of file path_calculation.cpp.


|
private |
Initialize the path from the previous path.
Snaps past path points to valid midpoints and carries forward as much of the previous path as possible, respecting distance constraints.
Definition at line 189 of file path_calculation.cpp.


|
private |
Definition at line 139 of file path_calculation.hpp.
|
private |
Definition at line 120 of file path_calculation.hpp.
|
private |
Definition at line 137 of file path_calculation.hpp.
|
private |
Definition at line 142 of file path_calculation.hpp.
|
private |
Definition at line 124 of file path_calculation.hpp.
|
private |
Definition at line 126 of file path_calculation.hpp.
|
private |
Definition at line 121 of file path_calculation.hpp.
|
private |
Definition at line 134 of file path_calculation.hpp.
|
private |
Definition at line 130 of file path_calculation.hpp.
|
private |
Definition at line 129 of file path_calculation.hpp.
Definition at line 140 of file path_calculation.hpp.
|
private |
Definition at line 131 of file path_calculation.hpp.
|
private |
Definition at line 125 of file path_calculation.hpp.
|
private |
Definition at line 141 of file path_calculation.hpp.
|
private |
Definition at line 138 of file path_calculation.hpp.