Skip to content

Commit

Permalink
feat(planner_manager): limit iteration number by parameter
Browse files Browse the repository at this point in the history
Signed-off-by: satoshi-ota <[email protected]>
  • Loading branch information
satoshi-ota committed Oct 19, 2023
1 parent b019643 commit 1c843ac
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 @@ -97,7 +97,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 @@ -446,6 +446,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 @@ -132,7 +132,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 bool create_publishers) {
Expand Down Expand Up @@ -272,6 +272,7 @@ BehaviorPathPlannerParameters BehaviorPathPlannerNode::getCommonParam()
BehaviorPathPlannerParameters p{};

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

Check warning on line 275 in planning/behavior_path_planner/src/behavior_path_planner_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

BehaviorPathPlannerNode::getCommonParam increases from 103 to 104 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.

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 @@ -29,9 +29,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 @@ -82,7 +84,7 @@ BehaviorModuleOutput PlannerManager::run(const std::shared_ptr<PlannerData> & da
return output;
}

while (rclcpp::ok()) {
for (size_t itr_num = 0;; ++itr_num) {

Check warning on line 87 in planning/behavior_path_planner/src/planner_manager.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/planner_manager.cpp#L87

Added line #L87 was not covered by tests
/**
* STEP1: get approved modules' output
*/
Expand Down Expand Up @@ -128,8 +130,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(

Check warning on line 135 in planning/behavior_path_planner/src/planner_manager.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/src/planner_manager.cpp#L135

Added line #L135 was not covered by tests
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.

Check warning on line 143 in planning/behavior_path_planner/src/planner_manager.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

PlannerManager::run increases in cyclomatic complexity from 12 to 13, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
}();

std::for_each(
Expand Down

0 comments on commit 1c843ac

Please sign in to comment.