Skip to content

Commit

Permalink
fix(planner_manager): use LIFO policy in approved modules unregisteri…
Browse files Browse the repository at this point in the history
…ng (#3434)

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
  • Loading branch information
satoshi-ota authored Apr 19, 2023
1 parent 8c79dbd commit dfd4bcb
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions planning/behavior_path_planner/src/planner_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ BehaviorModuleOutput PlannerManager::runApprovedModules(const std::shared_ptr<Pl
candidate_module_ptrs_.push_back(*itr);
}

approved_module_ptrs_.erase(
std::remove_if(
approved_module_ptrs_.begin(), approved_module_ptrs_.end(), waiting_approval_modules),
approved_module_ptrs_.end());
approved_module_ptrs_.erase(itr, approved_module_ptrs_.end());
}

/**
Expand Down Expand Up @@ -424,24 +421,55 @@ BehaviorModuleOutput PlannerManager::runApprovedModules(const std::shared_ptr<Pl
return results.at(output_module_name);
}();

const auto not_success_itr = std::find_if(
approved_module_ptrs_.rbegin(), approved_module_ptrs_.rend(),
[](const auto & m) { return m->getCurrentStatus() != ModuleStatus::SUCCESS; });

// convert reverse iterator -> iterator
const auto success_itr = std::prev(not_success_itr).base() - 1;

/**
* 1.remove success modules. these modules' outputs are used as valid plan.
* 2.update root lanelet if lane change module succeeded path planning, and finished correctly.
* there is no succeeded module. return.
*/
{
const auto itr = std::find_if(
approved_module_ptrs_.begin(), approved_module_ptrs_.end(),
[](const auto & m) { return m->getCurrentStatus() == ModuleStatus::SUCCESS; });
if (success_itr == approved_module_ptrs_.end()) {
return approved_modules_output;
}

if (itr == approved_module_ptrs_.begin()) {
if ((*itr)->name().find("lane_change") != std::string::npos) {
root_lanelet_ = updateRootLanelet(data);
}
const auto lane_change_itr = std::find_if(
success_itr, approved_module_ptrs_.end(),
[](const auto & m) { return m->name().find("lane_change") != std::string::npos; });

clearCandidateModules();
deleteExpiredModules(*itr);
approved_module_ptrs_.erase(itr);
}
/**
* remove success modules according to Last In First Out(LIFO) policy. when the next module is in
* ModuleStatus::RUNNING, the previous module keeps running even if it is in
* ModuleStatus::SUCCESS.
*/
if (lane_change_itr == approved_module_ptrs_.end()) {
std::for_each(
success_itr, approved_module_ptrs_.end(), [this](auto & m) { deleteExpiredModules(m); });

approved_module_ptrs_.erase(success_itr, approved_module_ptrs_.end());
clearCandidateModules();

return approved_modules_output;
}

/**
* as an exception, when there is lane change module is in succeeded modules, it doesn't remove
* any modules if module whose status is NOT ModuleStatus::SUCCESS exists. this is because the
* root lanelet is updated at the moment of lane change module's unregistering, and that causes
* change First In module's input.
*/
if (not_success_itr == approved_module_ptrs_.rend()) {
std::for_each(
success_itr, approved_module_ptrs_.end(), [this](auto & m) { deleteExpiredModules(m); });

approved_module_ptrs_.erase(success_itr, approved_module_ptrs_.end());
clearCandidateModules();

root_lanelet_ = updateRootLanelet(data);

return approved_modules_output;
}

return approved_modules_output;
Expand Down

0 comments on commit dfd4bcb

Please sign in to comment.