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 66 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 76 of file tree_planner.hpp.

79 :
83 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::from_nanoseconds(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 auto& cur_plan = it->first;
46
47 if (cur_plan.maneuver_plan_id == "")
48 {
49 // Generate a new unique id for the maneuver plan
50 cur_plan.maneuver_plan_id =
51 boost::uuids::to_string(boost::uuids::random_generator()());
52 }
53
54 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"),
55 "Start printing newly requested maneuver plan for debugging:");
56
57 for (auto mvr : cur_plan.maneuvers)
58 {
59 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"),
60 "Maneuver: "<< maneuver_type_to_string(mvr.type));
61 }
62
63 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"),
64 "Ended printing newly requested maneuver plan for debugging");
65
66 auto plan_duration = rclcpp::Duration(0, 0); // zero duration
67
68 // If we're not at the root, plan_duration is nonzero (our plan should have maneuvers)
69 if (!cur_plan.maneuvers.empty())
70 {
71 // get plan duration
73 }
74
75 // save longest if none of the plans have enough target duration
76 if (plan_duration > longest_plan_duration)
77 {
78 longest_plan_duration = plan_duration;
79 longest_plan = cur_plan;
80 }
81
82 // Evaluate plan_duration is sufficient do not expand more
83 if (plan_duration >= target_plan_duration_)
84 {
85 final_open_list.push_back((*it));
86 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"), "Has enough duration, skipping that which has following mvrs..:");
87 for (auto mvr : it->first.maneuvers)
88 {
89 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("arbitrator"),
90 "Printing successful mvr: " << maneuver_type_to_string(mvr.type));
91 }
92 continue;
93 }
94
95 // Expand it, and reprioritize
96 std::vector<carma_planning_msgs::msg::ManeuverPlan> children = neighbor_generator_->generate_neighbors(cur_plan, start_state);
97 RCLCPP_DEBUG_STREAM(
98 rclcpp::get_logger("arbitrator"),
99 "Arbitrator received total of " << children.size()
100 << " response from strategic_plugins for plan_id: "
101 << std::string(cur_plan.maneuver_plan_id)
102 );
103 // Compute cost for each child and store in open list
104 for (auto child = children.begin(); child != children.end(); child++)
105 {
106 if (child->maneuvers.empty())
107 {
108 RCLCPP_DEBUG_STREAM(
109 rclcpp::get_logger("arbitrator"),
110 "Arbitrator didn't get successful maneuver plan for plan_id: "
111 << std::string(cur_plan.maneuver_plan_id)
112 <<", from one of the strategic plugin, which so far had maneuvers: "
113 );
114 for (auto mvr : cur_plan.maneuvers)
115 {
116 RCLCPP_DEBUG_STREAM(
117 rclcpp::get_logger("arbitrator"),
118 "Maneuver type: " << maneuver_type_to_string(mvr.type);
119 );
120 }
121 continue;
122 }
123
124 temp_open_list.push_back(std::make_pair(*child, cost_function_->compute_cost_per_unit_distance(*child)));
125 }
126 }
127
128 open_list_to_evaluate = temp_open_list;
129 }
130
131 if (final_open_list.empty())
132 {
133 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...");
134 throw std::runtime_error("None of the strategic plugins generated any valid plans! Please check if any is turned and returning valid maneuvers...");
135 }
136
137 final_open_list = search_strategy_->prioritize_plans(final_open_list);
138
139 // now every plan has enough duration if possible and prioritized
140 for (auto pair : final_open_list)
141 {
142 // Pop the first element off the open list
143 carma_planning_msgs::msg::ManeuverPlan cur_plan = pair.first;
144 rclcpp::Duration plan_duration(0,0); // zero duration
145
146 // get plan duration
148
149 // Evaluate plan_duration is sufficient do not expand more
150 if (plan_duration >= target_plan_duration_)
151 {
152 return cur_plan;
153 }
154 }
155
156 // If no perfect match is found, return the longest plan that fit the criteria
157 return longest_plan;
158 }
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.
std::string maneuver_type_to_string(uint8_t type)
Convert maneuver type enum to string representation.
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21

References cost_function_, arbitrator_utils::get_plan_end_time(), arbitrator_utils::get_plan_start_time(), arbitrator::maneuver_type_to_string(), neighbor_generator_, osm_transform::root, search_strategy_, target_plan_duration_, and carma_cooperative_perception::to_string().

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 93 of file tree_planner.hpp.

Referenced by generate_plan().

◆ neighbor_generator_

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

Definition at line 94 of file tree_planner.hpp.

Referenced by generate_plan().

◆ search_strategy_

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

Definition at line 95 of file tree_planner.hpp.

Referenced by generate_plan().

◆ target_plan_duration_

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

Definition at line 96 of file tree_planner.hpp.

Referenced by generate_plan().


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