1#ifndef SRC_PLANNING_INCLUDE_PLANNING_PATH_CALCULATION_HPP_
2#define SRC_PLANNING_INCLUDE_PLANNING_PATH_CALCULATION_HPP_
18#include "rclcpp/rclcpp.hpp"
58 std::vector<PathPoint>
calculate_path(
const std::vector<Cone>& cone_array);
214 int num_candidates)
const;
229 int depth,
const std::shared_ptr<Midpoint>& previous,
230 const std::shared_ptr<Midpoint>& current,
double max_cost)
const;
243 double calculate_cost(
double previous_x,
double previous_y,
double current_x,
double current_y,
244 double next_x,
double next_y)
const;
266 void discard_cone(
const std::shared_ptr<Midpoint>& last_mp,
267 const std::shared_ptr<Midpoint>& current_mp);
320 const std::vector<Colorpoint>& colorpoints)
const;
Generates midpoints between cones using Delaunay triangulation.
Generates optimal local paths.
PathCalculation(const PathCalculationConfig &config)
Construct a new PathCalculation object with configuration.
std::pair< std::shared_ptr< Midpoint >, std::shared_ptr< Midpoint > > select_starting_midpoints()
Select the first two midpoints to start the path.
std::vector< Colorpoint > past_path_
int reset_path(bool should_reset)
Handle path reset when completing a lap.
const std::vector< PathPoint > & get_yellow_cones() const
Gets the list of yellow cones detected or used in the path calculation.
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::unordered_set< std::shared_ptr< Midpoint > > visited_midpoints_
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.
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.
std::vector< PathPoint > get_path_to_car() const
Get the path from the start to a lookback distance behind the car’s current position.
common_lib::structures::Pose vehicle_pose_
std::vector< PathPoint > calculate_path(const std::vector< Cone > &cone_array)
Generate a path from an array of cones.
void initialize_path_from_initial_pose()
Initialize the path from the vehicle's initial pose.
void remove_invalid_neighbors()
Remove invalid neighbors from all midpoint connection lists.
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_....
std::unordered_set< std::shared_ptr< Cone > > discarded_cones_
std::vector< PathPoint > yellow_cones_
PathCalculation()=default
Construct a new default PathCalculation object.
std::shared_ptr< Midpoint > find_nearest_midpoint(const Point &target) const
Find the nearest valid midpoint to a target position.
void extend_path(int max_points)
Extend the path by adding midpoints.
void clear_path_state()
Reset path construction state.
MidpointGenerator midpoint_generator_
void update_path_from_past_path()
Initialize the path from the previous path.
void invalidate_midpoints_with_discarded_cones()
Mark midpoints as invalid if they use discarded cones.
const std::vector< PathPoint > & get_blue_cones() const
Gets the list of blue cones detected or used in the path calculation.
std::vector< PathPoint > blue_cones_
const std::vector< std::pair< Point, Point > > & get_triangulations() const
Get the triangulation segments used in path generation.
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.
std::vector< PathPoint > calculate_trackdrive(const std::vector< Cone > &cone_array)
Generate a closed loop path for trackdrive competition.
common_lib::structures::Pose initial_pose_
std::vector< std::shared_ptr< Midpoint > > midpoints_
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< Colorpoint > current_path_
std::unordered_map< Point, std::shared_ptr< Midpoint > > point_to_midpoint_
void discard_cones_along_path()
Invalidate cones and midpoints along the last path segment.
void set_vehicle_pose(const common_lib::structures::Pose &vehicle_pose)
Set the current vehicle position and orientation.
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.
std::vector< Colorpoint > path_to_car_
PathCalculationConfig config_
MidPoint struct represents a potential path point with connections.
Struct for pose representation.