Skip to content

Commit

Permalink
feat(planner_manager): limit iteration number by parameter (autowaref…
Browse files Browse the repository at this point in the history
…oundation#5352)

Signed-off-by: satoshi-ota <[email protected]>
  • Loading branch information
satoshi-ota committed Nov 22, 2023
1 parent dfe8ac3 commit e28e11b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**:
ros__parameters:
verbose: false
max_iteration_num: 100
planning_hz: 10.0
backward_path_length: 5.0
forward_path_length: 300.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct LateralAccelerationMap
struct BehaviorPathPlannerParameters
{
bool verbose;
size_t max_iteration_num{100};

ModuleConfigParameters config_avoidance;
ModuleConfigParameters config_avoidance_by_lc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct SceneModuleStatus
class PlannerManager
{
public:
PlannerManager(rclcpp::Node & node, const bool verbose);
PlannerManager(rclcpp::Node & node, const size_t max_iteration_num, const bool verbose);

/**
* @brief run all candidate and approved modules.
Expand Down Expand Up @@ -433,6 +433,8 @@ class PlannerManager

mutable std::shared_ptr<SceneModuleVisitor> debug_msg_ptr_;

size_t max_iteration_num_{100};

bool verbose_{false};
};
} // namespace behavior_path_planner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
const std::lock_guard<std::mutex> lock(mutex_manager_); // for planner_manager_

const auto & p = planner_data_->parameters;
planner_manager_ = std::make_shared<PlannerManager>(*this, p.verbose);
planner_manager_ = std::make_shared<PlannerManager>(*this, p.max_iteration_num, p.verbose);

const auto register_and_create_publisher = [&](const auto & manager) {
const auto & module_name = manager->name();
Expand Down Expand Up @@ -282,6 +282,7 @@ BehaviorPathPlannerParameters BehaviorPathPlannerNode::getCommonParam()
BehaviorPathPlannerParameters p{};

p.verbose = declare_parameter<bool>("verbose");
p.max_iteration_num = declare_parameter<int>("max_iteration_num");

const auto get_scene_module_manager_param = [&](std::string && ns) {
ModuleConfigParameters config;
Expand Down
17 changes: 14 additions & 3 deletions planning/behavior_path_planner/src/planner_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

namespace behavior_path_planner
{
PlannerManager::PlannerManager(rclcpp::Node & node, const bool verbose)
PlannerManager::PlannerManager(
rclcpp::Node & node, const size_t max_iteration_num, const bool verbose)
: logger_(node.get_logger().get_child("planner_manager")),
clock_(*node.get_clock()),
max_iteration_num_{max_iteration_num},
verbose_{verbose}
{
processing_time_.emplace("total_time", 0.0);
Expand Down Expand Up @@ -80,7 +82,7 @@ BehaviorModuleOutput PlannerManager::run(const std::shared_ptr<PlannerData> & da
return output;
}

while (rclcpp::ok()) {
for (size_t itr_num = 0;; ++itr_num) {
/**
* STEP1: get approved modules' output
*/
Expand Down Expand Up @@ -126,8 +128,17 @@ BehaviorModuleOutput PlannerManager::run(const std::shared_ptr<PlannerData> & da
addApprovedModule(highest_priority_module);
clearCandidateModules();
debug_info_.emplace_back(highest_priority_module, Action::ADD, "To Approval");

if (itr_num >= max_iteration_num_) {
RCLCPP_WARN_THROTTLE(
logger_, clock_, 1000, "Reach iteration limit (max: %ld). Output current result.",
max_iteration_num_);
processing_time_.at("total_time") = stop_watch_.toc("total_time", true);
return candidate_modules_output;
}
}
return BehaviorModuleOutput{};

return BehaviorModuleOutput{}; // something wrong.
}();

std::for_each(
Expand Down

0 comments on commit e28e11b

Please sign in to comment.