14 std::string global_config_path =
16 RCLCPP_DEBUG(rclcpp::get_logger(
"planning"),
"Loading global config from: %s",
17 global_config_path.c_str());
19 YAML::Node global_config = YAML::LoadFile(global_config_path);
20 adapter = global_config[
"global"][
"adapter"].as<std::string>();
24 std::string planning_config_path =
26 RCLCPP_DEBUG(rclcpp::get_logger(
"planning"),
"Loading planning config from: %s",
27 planning_config_path.c_str());
29 YAML::Node planning = YAML::LoadFile(planning_config_path);
30 YAML::Node planning_config = planning[
"planning"];
39 params.
pc_angle_gain_ = planning_config[
"pc_angle_gain"].as<
double>();
43 params.
pc_max_cost_ = planning_config[
"pc_max_cost"].as<
double>();
46 params.
pc_max_points_ = planning_config[
"pc_max_points"].as<
int>();
50 params.
pc_close_cost_ = planning_config[
"pc_close_cost"].as<
double>();
60 planning_config[
"smoothing_spline_coeffs_ratio"].as<
float>();
62 planning_config[
"smoothing_min_path_point_distance"].as<
float>();
78 planning_config[
"vp_longitudinal_acceleration"].as<
double>();
84 planning_config[
"planning_publishing_visualization_msgs"].as<
bool>();
87 planning_config[
"planning_braking_distance_acceleration"].as<
double>();
89 planning_config[
"planning_braking_distance_autocross"].as<
double>();
91 if (adapter ==
"eufs") {
104 planning_config_(params),
105 map_frame_id_(params.map_frame_id_),
106 desired_velocity_(params.vp_desired_velocity_) {
113 create_client<rcl_interfaces::srv::GetParameters>(
"/pacsim/pacsim_node/get_parameters");
118 path_pub_ = create_publisher<custom_interfaces::msg::PathPointArray>(
"/path_planning/path", 10);
121 create_publisher<std_msgs::msg::Float64>(
"/path_planning/execution_time", 10);
125 create_publisher<visualization_msgs::msg::MarkerArray>(
"/path_planning/yellow_cones", 10);
127 create_publisher<visualization_msgs::msg::MarkerArray>(
"/path_planning/blue_cones", 10);
129 create_publisher<visualization_msgs::msg::Marker>(
"/path_planning/triangulations", 10);
131 create_publisher<visualization_msgs::msg::MarkerArray>(
"/path_planning/path_to_car", 10);
133 create_publisher<visualization_msgs::msg::MarkerArray>(
"/path_planning/full_path", 10);
135 create_publisher<visualization_msgs::msg::Marker>(
"/path_planning/smoothed_path_", 10);
137 create_publisher<visualization_msgs::msg::MarkerArray>(
"/path_planning/velocity_hover", 10);
142 "/state_estimation/vehicle_pose", 10,
145 track_map_sub_ = create_subscription<custom_interfaces::msg::ConeArray>(
146 "/state_estimation/map", 10,
150 "/state_estimation/lap_counter", 10, [
this](
const std_msgs::msg::Float64::SharedPtr msg) {
155 RCLCPP_INFO(rclcpp::get_logger(
"planning"),
"Using simulated state estimation: %d",
162 Mission mission_result = Mission::NONE;
164 if (!
param_client_->wait_for_service(std::chrono::milliseconds(100))) {
165 RCLCPP_ERROR(get_logger(),
"Service /pacsim/pacsim_node/get_parameters not available.");
167 auto request = std::make_shared<rcl_interfaces::srv::GetParameters::Request>();
168 request->names.push_back(
"discipline");
171 request, [
this](rclcpp::Client<rcl_interfaces::srv::GetParameters>::SharedFuture future) {
172 auto response = future.get();
173 Mission mission_result = Mission::AUTOCROSS;
175 if (!response->values.empty() && response->values[0].type == 4) {
176 std::string
discipline = response->values[0].string_value;
177 RCLCPP_INFO(get_logger(),
"Discipline received: %s",
discipline.c_str());
180 mission_result = Mission::SKIDPAD;
182 mission_result = Mission::ACCELERATION;
184 mission_result = Mission::TRACKDRIVE;
186 mission_result = Mission::AUTOCROSS;
189 RCLCPP_ERROR(get_logger(),
"Failed to retrieve discipline parameter.");
204 RCLCPP_DEBUG(get_logger(),
"Received Pose: %lf - %lf - %lf", message.x, message.y, message.theta);
206 pose_ =
Pose(message.x, message.y, message.theta);
221 int number_of_cones_received =
static_cast<int>(message.cone_array.size());
222 RCLCPP_DEBUG(get_logger(),
"Planning received %i cones", number_of_cones_received);
234 int n =
static_cast<int>(path.size());
241 double dx = path[1].position.x - path[0].position.x;
242 double dy = path[1].position.y - path[0].position.y;
243 path[0].orientation = std::atan2(dy, dx);
247 for (
int i = 1; i < n - 1; i++) {
248 dx = path[i + 1].position.x - path[i - 1].position.x;
249 dy = path[i + 1].position.y - path[i - 1].position.y;
250 path[i].orientation = std::atan2(dy, dx);
254 dx = path[n - 1].position.x - path[n - 2].position.x;
255 dy = path[n - 1].position.y - path[n - 2].position.y;
256 path[n - 1].orientation = std::atan2(dy, dx);
259 for (
int i = 0; i < n; i++) {
260 int prev = (i - 1 + n) % n;
261 int next = (i + 1) % n;
263 double dx = path[next].position.x - path[prev].position.x;
264 double dy = path[next].position.y - path[prev].position.y;
266 path[i].orientation = std::atan2(dy, dx);
283 double total_length = 0.0;
284 double lap_time = 0.0;
286 double sum_vel = 0.0;
295 double dx = p2.position.x - p1.position.x;
296 double dy = p2.position.y - p1.position.y;
297 double ds = std::sqrt(dx * dx + dy * dy);
302 double v_avg = (p1.ideal_velocity + p2.ideal_velocity) / 2.0;
305 v_avg = std::max(v_avg, 0.1);
307 lap_time += ds / v_avg;
310 sum_vel += p1.ideal_velocity;
311 max_vel = std::max(max_vel, p1.ideal_velocity);
312 min_vel = std::min(min_vel, p1.ideal_velocity);
317 RCLCPP_DEBUG(get_logger(),
"Trackdrive path calculated with %d points",
320 RCLCPP_DEBUG(get_logger(),
321 "Lap Time: %.2f s | Length: %.1f m | Avg: %.2f m/s | Min: %.2f m/s "
323 lap_time, total_length, avg_vel, min_vel, max_vel);
391 RCLCPP_DEBUG(rclcpp::get_logger(
"planning"),
"Running Planning Algorithms");
398 rclcpp::Time start_time = now();
402 RCLCPP_ERROR(get_logger(),
"Mission is NONE, cannot run planning algorithms.");
405 case Mission::SKIDPAD:
409 case Mission::ACCELERATION:
410 case Mission::EBS_TEST:
414 case Mission::AUTOCROSS:
418 case Mission::TRACKDRIVE:
430 RCLCPP_INFO(rclcpp::get_logger(
"planning"),
"Final path size: %d",
441 RCLCPP_DEBUG(get_logger(),
"Planning will publish %i path points\n",
452 custom_interfaces::msg::PathPointArray message =
459 rclcpp::Time end_time = now();
460 std_msgs::msg::Float64 planning_execution_time;
461 planning_execution_time.data = (end_time - start_time).seconds() * 1000;
468 visualization_msgs::msg::Marker::MODIFY));
484 visualization_msgs::msg::Marker::MODIFY));
Generates optimal local paths.
const std::vector< PathPoint > & get_yellow_cones() const
Gets the list of yellow cones detected or used in the path calculation.
std::vector< PathPoint > get_path_to_car() const
Get the path from the start to a lookback distance behind the car’s current position.
std::vector< PathPoint > calculate_path(const std::vector< Cone > &cone_array)
Generate a path from an array of cones.
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_....
const std::vector< PathPoint > & get_blue_cones() const
Gets the list of blue cones detected or used in the path calculation.
const std::vector< std::pair< Point, Point > > & get_triangulations() const
Get the triangulation segments used in path generation.
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.
class that defines the path smoothing algorithm
std::vector< PathPoint > smooth_path(const std::vector< PathPoint > &path, bool is_path_closed) const
Smooths a path by fitting a B-spline through the input points.
std::vector< PathPoint > optimize_path(const std::vector< PathPoint > &path, const std::vector< PathPoint > &yellow_cones, const std::vector< PathPoint > &blue_cones) const
Optimizes a racing line path by fitting splines through track boundaries and applying quadratic progr...
rclcpp::Publisher< visualization_msgs::msg::Marker >::SharedPtr smoothed_path_pub_
Publisher for velocity hover markers.
PathSmoothing path_smoothing_
void track_map_callback(const custom_interfaces::msg::ConeArray &message)
Callback for track map updates.
Planning(const PlanningParameters ¶ms)
Constructs a Planning node with the specified configuration parameters.
void fetch_discipline()
Fetches the current mission/discipline from the pacsim simulation service.
void run_full_map()
Generates and optimizes a closed-loop global track path.
void vehicle_localization_callback(const custom_interfaces::msg::Pose &message)
Callback for vehicle localization pose updates.
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr velocity_hover_pub_
std::vector< Cone > cone_array_
std::string map_frame_id_
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr path_to_car_pub_
Publisher for the entire planned path (from start to finish)
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr yellow_cones_pub_
< Publisher for the yellow cones
void run_acceleration()
Executes planning for the acceleration mission.
PathCalculation path_calculation_
void set_mission(Mission mission)
Sets the mission type for planning execution.
static PlanningParameters load_config(std::string &adapter)
Loads planning configuration from YAML files.
rclcpp::Subscription< custom_interfaces::msg::Pose >::SharedPtr vehicle_localization_sub_
void run_autocross()
Executes planning for the autocross mission.
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr full_path_pub_
Publisher for the smoothed path.
std::vector< PathPoint > smoothed_path_
double initial_car_orientation_
rclcpp::Publisher< visualization_msgs::msg::Marker >::SharedPtr triangulations_pub_
Publisher for the past portion of the path (from the start to a lookback distance behind the car’s cu...
void compute_path_orientation(std::vector< PathPoint > &path)
Computes and assigns the orientation for each point in the path.
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr blue_cones_pub_
Publisher for Delaunay triangulations.
rclcpp::Subscription< custom_interfaces::msg::ConeArray >::SharedPtr track_map_sub_
void run_trackdrive()
Executes planning for the trackdrive mission.
std::vector< PathPoint > full_path_
rclcpp::Publisher< std_msgs::msg::Float64 >::SharedPtr planning_execution_time_pub_
PlanningConfig planning_config_
rclcpp::Client< rcl_interfaces::srv::GetParameters >::SharedPtr param_client_
rclcpp::Subscription< std_msgs::msg::Float64 >::SharedPtr lap_counter_sub_
void publish_path_points() const
Publishes the final planned path to the control module.
void publish_execution_time(rclcpp::Time start_time)
Publishes the planning algorithm execution time.
rclcpp::Publisher< custom_interfaces::msg::PathPointArray >::SharedPtr path_pub_
< Publisher of the smoothed path to control
void publish_visualization_msgs() const
Publishes all visualization markers.
void run_planning_algorithms()
Runs the appropriate planning algorithm based on current mission.
VelocityPlanning velocity_planning_
class that defines the skidpad path algorithm
std::vector< PathPoint > skidpad_path(const std::vector< Cone > &cone_array, common_lib::structures::Pose pose)
Generate a path for skidpad course.
Computes velocity profiles for a planned path based on curvature and dynamics constraints.
void stop(std::vector< PathPoint > &final_path, double braking_distance)
Applies a braking velocity profile starting after a given braking distance.
void set_velocity(std::vector< PathPoint > &final_path)
Assigns an velocity to each point of the path.
void trackdrive_velocity(std::vector< PathPoint > &final_path)
Computes velocity for trackdrive scenarios.
custom_interfaces::msg::ConeArray custom_interfaces_array_from_vector(const std::vector< common_lib::structures::Cone > &input_cones)
std::vector< common_lib::structures::Cone > cone_vector_from_custom_interfaces(const custom_interfaces::msg::ConeArray &msg)
visualization_msgs::msg::Marker line_marker_from_structure_array(const std::vector< T > &structure_array, const std::string &name_space, const std::string &frame_id, const int id, const std::string &color="red", const std::string &shape="line", float scale=0.1f, int action=visualization_msgs::msg::Marker::MODIFY)
Converts a vector of cones to a marker array.
visualization_msgs::msg::MarkerArray marker_array_from_structure_array(const std::vector< T > &structure_array, const std::string &name_space, const std::string &frame_id, const std::string &color="red", const std::string &shape="cylinder", float scale=0.5, int action=visualization_msgs::msg::Marker::MODIFY)
Converts a vector of cones to a marker array.
visualization_msgs::msg::MarkerArray velocity_hover_markers(const std::vector< common_lib::structures::PathPoint > &path_array, const std::string &name_space, const std::string &frame_id, float scale=0.2f, int every_nth=1)
Creates sphere markers at each path point with velocity in the marker namespace When you hover over t...
visualization_msgs::msg::Marker lines_marker_from_triangulations(const std::vector< std::pair< Point, Point > > &triangulations, const std::string &name_space, const std::string &frame_id, int id, const std::string &color, float scale, int action)
Converts a vector of triangulation edges to a marker.
std::string get_config_yaml_path(const std::string &package_name, const std::string &dir, const std::string &filename)
common_lib::competition_logic::Mission Mission
common_lib::structures::Pose Pose
bool use_path_smoothing_
Flag to enable/disable spline-based path smoothing.
int spline_precision_
Number of interpolated points between each pair of input points.
bool publishing_visualization_msgs_
double braking_distance_acceleration_
PathCalculationConfig path_calculation_
PathSmoothingConfig smoothing_
VelocityPlanningConfig velocity_planning_
double braking_distance_autocross_
double smoothing_safety_margin_
bool vp_use_velocity_planning_
int smoothing_max_iterations_
double vp_braking_acceleration_
double planning_braking_distance_acceleration_
Distance to start braking during acceleration mode.
double pc_distance_exponent_
bool smoothing_use_path_smoothing_
int skidpad_minimum_cones_
double vp_minimum_velocity_
double planning_braking_distance_autocross_
Distance to start braking during autocross/trackdrive mode.
double vp_lateral_acceleration_
double vp_desired_velocity_
double pc_minimum_point_distance_
double smoothing_tolerance_
float smoothing_spline_coeffs_ratio_
bool planning_using_full_map_
Flag to enable/disable using planning with the full map.
std::string planning_adapter_
The adapter planning is currently using like Pacsim, Vehicle...
double skidpad_tolerance_
double mg_maximum_cone_distance_
double vp_longitudinal_acceleration_
double mg_sliding_window_radius_
int smoothing_spline_order_
std::string map_frame_id_
bool planning_using_simulated_se_
Flag to enable/disable the use of simulated State Estimation.
bool planning_publishing_visualization_msgs_
Flag to enable/disable publishing of visualization messages.
int smoothing_spline_precision_
double smoothing_car_width_
double mg_minimum_cone_distance_
bool pc_use_sliding_window_
float smoothing_min_path_point_distance_
bool smoothing_use_optimization_
double smoothing_safety_weight_
double pc_angle_exponent_
double smoothing_curvature_weight_