Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(planner_manager): limit iteration number by parameter (#5352) #967

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -91,7 +91,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 @@ -462,6 +462,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 @@ -130,7 +130,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 @@ -277,6 +277,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 @@ -27,9 +27,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 @@ -79,7 +81,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 @@ -125,8 +127,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
Loading