Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
arbitrator::TreePlanner Class Reference

Implementation of PlanningStrategy using a generic tree search algorithm. More...

#include <tree_planner.hpp>

Inheritance diagram for arbitrator::TreePlanner:
Inheritance graph
Collaboration diagram for arbitrator::TreePlanner:
Collaboration graph

Public Member Functions

 TreePlanner (std::shared_ptr< CostFunction > cf, std::shared_ptr< NeighborGenerator > ng, std::shared_ptr< SearchStrategy > ss, rclcpp::Duration target)
 Tree planner constructor. More...
 
carma_planning_msgs::msg::ManeuverPlan generate_plan (const VehicleState &start_state)
 Utilize the configured cost function, neighbor generator, and search strategy, to generate a plan by means of tree search. More...
 
- Public Member Functions inherited from arbitrator::PlanningStrategy
virtual carma_planning_msgs::msg::ManeuverPlan generate_plan (const VehicleState &start_state)=0
 Generate a plausible maneuver plan. More...
 
virtual ~PlanningStrategy ()
 Virtual destructor provided for memory safety. More...
 

Protected Attributes

std::shared_ptr< CostFunctioncost_function_
 
std::shared_ptr< NeighborGeneratorneighbor_generator_
 
std::shared_ptr< SearchStrategysearch_strategy_
 
rclcpp::Duration target_plan_duration_
 

Detailed Description

Implementation of PlanningStrategy using a generic tree search algorithm.

The fundamental components of this tree search are individually injected into this class at construction time to allow for fine-tuning of the algorithm and ensure better testability and separation of algorithmic concerns

Definition at line 40 of file tree_planner.hpp.

Constructor & Destructor Documentation

◆ TreePlanner()

arbitrator::TreePlanner::TreePlanner ( std::shared_ptr< CostFunction cf,
std::shared_ptr< NeighborGenerator ng,
std::shared_ptr< SearchStrategy ss,
rclcpp::Duration  target 
)
inline

Tree planner constructor.

Parameters
cfShared ptr to a CostFunction implementation
ngShared ptr to a NeighborGenerator implementation
ssShared ptr to a SearchStrategy implementation
targetThe desired duration of finished plans

Definition at line 50 of file tree_planner.hpp.

53 :
57 target_plan_duration_(target) {};
rclcpp::Duration target_plan_duration_
std::shared_ptr< SearchStrategy > search_strategy_
std::shared_ptr< NeighborGenerator > neighbor_generator_
std::shared_ptr< CostFunction > cost_function_

Member Function Documentation

◆ generate_plan()

carma_planning_msgs::msg::ManeuverPlan arbitrator::TreePlanner::generate_plan ( const VehicleState start_state)
virtual

Utilize the configured cost function, neighbor generator, and search strategy, to generate a plan by means of tree search.

Parameters
start_stateThe starting state of the vehicle to plan for

Implements arbitrator::PlanningStrategy.

Definition at line 25 of file tree_planner.cpp.

26 {
27 carma_planning_msgs::msg::ManeuverPlan root;
28 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> open_list_to_evaluate;
29 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> final_open_list;
30
31 const double INF = std::numeric_limits<double>::infinity();
32 open_list_to_evaluate.push_back(std::make_pair(root, INF));
33
34 carma_planning_msgs::msg::ManeuverPlan longest_plan = root; // Track longest plan in case target length is never reached
35 rclcpp::Duration longest_plan_duration = rclcpp::Duration(0);
36
37
38 while (!open_list_to_evaluate.empty())
39 {
40 std::vector<std::pair<carma_planning_msgs::msg::ManeuverPlan, double>> temp_open_list;
41
42 for (auto it = open_list_to_evaluate.begin(); it != open_list_to_evaluate.end(); it++)
43 {
44 // Pop the first element off the open list
45 carma_planning_msgs::msg::ManeuverPlan cur_plan = it->first;
46
47 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "START");
48
49 for (auto mvr : cur_plan.maneuvers)
50 {
51 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "Printing cur_plan: mvr: "<< (int)mvr.type);
52 }
53
54 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "PRINT END");
55
56 auto plan_duration = rclcpp::Duration(0, 0); // zero duration
57
58 // If we're not at the root, plan_duration is nonzero (our plan should have maneuvers)
59 if (!cur_plan.maneuvers.empty())
60 {
61 // get plan duration
63 }
64
65 // save longest if none of the plans have enough target duration
66 if (plan_duration > longest_plan_duration)
67 {
68 longest_plan_duration = plan_duration;
69 longest_plan = cur_plan;
70 }
71
72 // Evaluate plan_duration is sufficient do not expand more
73 if (plan_duration >= target_plan_duration_)
74 {
75 final_open_list.push_back((*it));
76 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "Has enough duration, skipping that which has following mvrs..:");
77 for (auto mvr : it->first.maneuvers)
78 {
79 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "Printing mvr: "<< (int)mvr.type);
80 }
81 continue;
82 }
83
84 // Expand it, and reprioritize
85 std::vector<carma_planning_msgs::msg::ManeuverPlan> children = neighbor_generator_->generate_neighbors(cur_plan, start_state);
86
87 // Compute cost for each child and store in open list
88 for (auto child = children.begin(); child != children.end(); child++)
89 {
90
91 if (child->maneuvers.empty())
92 {
93 RCLCPP_WARN_STREAM(rclcpp::get_logger("arbitrator"), "Child was empty for id: " << std::string(child->maneuver_plan_id));
94 continue;
95 }
96
97 temp_open_list.push_back(std::make_pair(*child, cost_function_->compute_cost_per_unit_distance(*child)));
98 }
99 }
100
101 open_list_to_evaluate = temp_open_list;
102 }
103
104 if (final_open_list.empty())
105 {
106 RCLCPP_ERROR_STREAM(rclcpp::get_logger("arbitrator"), "None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
107 throw std::runtime_error("None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
108 }
109
110 final_open_list = search_strategy_->prioritize_plans(final_open_list);
111
112 // now every plan has enough duration if possible and prioritized
113 for (auto pair : final_open_list)
114 {
115 // Pop the first element off the open list
116 carma_planning_msgs::msg::ManeuverPlan cur_plan = pair.first;
117 rclcpp::Duration plan_duration(0,0); // zero duration
118
119 // get plan duration
121
122 // Evaluate plan_duration is sufficient do not expand more
123 if (plan_duration >= target_plan_duration_)
124 {
125 return cur_plan;
126 }
127 }
128
129 // If no perfect match is found, return the longest plan that fit the criteria
130 return longest_plan;
131 }
rclcpp::Time get_plan_start_time(const carma_planning_msgs::msg::ManeuverPlan &)
Get the start time of the first maneuver in the plan.
rclcpp::Time get_plan_end_time(const carma_planning_msgs::msg::ManeuverPlan &)
Get the end time of the first maneuver in the plan.

References cost_function_, arbitrator_utils::get_plan_end_time(), arbitrator_utils::get_plan_start_time(), neighbor_generator_, search_strategy_, and target_plan_duration_.

Here is the call graph for this function:

Member Data Documentation

◆ cost_function_

std::shared_ptr<CostFunction> arbitrator::TreePlanner::cost_function_
protected

Definition at line 67 of file tree_planner.hpp.

Referenced by generate_plan().

◆ neighbor_generator_

std::shared_ptr<NeighborGenerator> arbitrator::TreePlanner::neighbor_generator_
protected

Definition at line 68 of file tree_planner.hpp.

Referenced by generate_plan().

◆ search_strategy_

std::shared_ptr<SearchStrategy> arbitrator::TreePlanner::search_strategy_
protected

Definition at line 69 of file tree_planner.hpp.

Referenced by generate_plan().

◆ target_plan_duration_

rclcpp::Duration arbitrator::TreePlanner::target_plan_duration_
protected

Definition at line 70 of file tree_planner.hpp.

Referenced by generate_plan().


The documentation for this class was generated from the following files: