-
Notifications
You must be signed in to change notification settings - Fork 658
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(goal_planner): divide Planners to isolated threads #9514
feat(goal_planner): divide Planners to isolated threads #9514
Conversation
Thank you for contributing to the Autoware project! 🚧 If your pull request is in progress, switch it to draft mode. Please ensure:
|
6161574
to
919e4b9
Compare
e183b1e
to
b172a68
Compare
7410599
to
4ce8b96
Compare
Signed-off-by: Mamoru Sobue <[email protected]>
Signed-off-by: Mamoru Sobue <[email protected]>
Signed-off-by: Mamoru Sobue <[email protected]>
4ce8b96
to
4edb7a1
Compare
Signed-off-by: Mamoru Sobue <[email protected]>
auto lane_parking_planner = std::make_unique<LaneParkingPlanner>( | ||
node, lane_parking_mutex_, lane_parking_request_, lane_parking_response_, | ||
is_lane_parking_cb_running_, getLogger(), *parameters_); | ||
lane_parking_timer_ = rclcpp::create_timer( | ||
&node, clock_, lane_parking_period_ns, std::bind(&GoalPlannerModule::onTimer, this), | ||
&node, clock_, lane_parking_period_ns, | ||
[lane_parking_planner_bind = std::move(lane_parking_planner)]() { | ||
lane_parking_planner_bind->onTimer(); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to create lane_parking_planner
temporaly variable?
creating planner in lamda is ok?
const auto lane_parking_period_ns = rclcpp::Rate(1.0).period();
lane_parking_timer_cb_group_ =
node.create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
lane_parking_timer_ = rclcpp::create_timer(
&node, clock_, lane_parking_period_ns,
[lane_parkng_planner = std::make_unique<LaneParkingPlanner>(
node, lane_parking_mutex_, lane_parking_request_, lane_parking_response_,
is_lane_parking_cb_running_, getLogger(), *parameters_)]() {
lane_parkng_planner->onTimer();
},
lane_parking_timer_cb_group_);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to lane_parking_executor
in d42fc0d
auto freespace_planner = std::make_shared<FreespacePullOver>(node, *parameters, vehicle_info); | ||
const auto freespace_parking_period_ns = rclcpp::Rate(1.0).period(); | ||
freespace_parking_timer_cb_group_ = | ||
node.create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); | ||
auto freespace_parking_planner = std::make_unique<FreespaceParkingPlanner>( | ||
freespace_parking_mutex_, freespace_parking_request_, freespace_parking_response_, | ||
is_freespace_parking_cb_running_, getLogger(), clock_, freespace_planner); | ||
freespace_parking_timer_ = rclcpp::create_timer( | ||
&node, clock_, freespace_parking_period_ns, | ||
std::bind(&GoalPlannerModule::onFreespaceParkingTimer, this), | ||
[freespace_parking_planner_bind = std::move(freespace_parking_planner)]() { | ||
freespace_parking_planner_bind->onTimer(); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same to lane_parking
is it necessary to create lane_parking_planner temporaly variable?
creating planner in lamda is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to freespace_parking_executor
in d42fc0d
auto freespace_planner = std::make_shared<FreespacePullOver>(node, *parameters, vehicle_info); | ||
const auto freespace_parking_period_ns = rclcpp::Rate(1.0).period(); | ||
freespace_parking_timer_cb_group_ = | ||
node.create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive); | ||
auto freespace_parking_planner = std::make_unique<FreespaceParkingPlanner>( | ||
freespace_parking_mutex_, freespace_parking_request_, freespace_parking_response_, | ||
is_freespace_parking_cb_running_, getLogger(), clock_, freespace_planner); | ||
freespace_parking_timer_ = rclcpp::create_timer( | ||
&node, clock_, freespace_parking_period_ns, | ||
std::bind(&GoalPlannerModule::onFreespaceParkingTimer, this), | ||
[freespace_parking_planner_bind = std::move(freespace_parking_planner)]() { | ||
freespace_parking_planner_bind->onTimer(); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
freespace_planner
and freespace_parking_planner
are little confusing.
FreespaceParkingPlanner
is more like a thread or something.
std::optional<GoalPlannerData> gp_planner_data_{std::nullopt}; | ||
std::mutex gp_planner_data_mutex_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gp_planner_data
is deleted but still remain in comments. please modify or remove comments if they are not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete in d42fc0d
} | ||
auto & gp_planner_data = gp_planner_data_.value(); | ||
auto & lane_parking_request = lane_parking_request_.value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question:
why creating refrence?
we can not use update() of lane_parking_request_ directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in d42fc0d
// GoalPlannerModule::occupancy_grid_map_ and gp_planner_data.occupancy_grid_map share the | ||
// ownership, and gp_planner_data.occupancy_grid_map maybe also shared by the local | ||
// planner_data on onFreespaceParkingTimer thread local memory space. So following operation | ||
// is thread-safe because gp_planner_data.occupancy_grid_map is only re-pointed here and its | ||
// prior resource is still owned by the onFreespaceParkingTimer thread locally. | ||
occupancy_grid_map_ = gp_planner_data.occupancy_grid_map; | ||
occupancy_grid_map_ = freespace_parking_request.get_occupancy_grid_map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
occupancy_grid_map is not only for freepace_parking, it is also used for lane_parking.
for example,
checkOccupancyGridCollision(parking_path, occupancy_grid_map_)) {
is in selectPullOverPath
occupancy_grid_map is come from planner_data
occupancy_grid_map->setMap(*(planner_data.occupancy_grid));
not from freespace parking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove ogm-based-collision-detector from FreespaceExecutor in the future
std::atomic<bool> & is_lane_parking_cb_running_; | ||
rclcpp::Logger logger_; | ||
|
||
std::vector<std::shared_ptr<PullOverPlannerBase>> pull_over_planners_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
(I know this is just using previous code. but we can use unique_ptr or just vector. I want refactor in the future)
if (pull_over_planners_.empty()) { | ||
RCLCPP_ERROR(logger_, "Not found enabled planner"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pull_over_planners_.empty()) { | |
RCLCPP_ERROR(logger_, "Not found enabled planner"); | |
} | |
if (pull_over_planners_.empty()) { | |
RCLCPP_WARN( | |
getLogger(), | |
"No enabled planner found. The vehicle will stop in the road lane without pull over. Please " | |
"check the parameters if this is the intended behavior."); | |
} |
currently I changed some log messages in #9562
there may be similar parts, so please check
Signed-off-by: Mamoru Sobue <[email protected]>
auto path_and_goal_opt = | ||
const auto & pull_over_path_candidates = | ||
context_data.lane_parking_response.pull_over_path_candidates; | ||
auto lane_pull_over_path_opt = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto lane_pull_over_path_opt = | |
const auto lane_pull_over_path_opt = |
?
I can build with const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 181415e
...behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Mamoru Sobue <[email protected]>
Signed-off-by: Mamoru Sobue <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9514 +/- ##
==========================================
- Coverage 29.90% 29.85% -0.05%
==========================================
Files 1441 1446 +5
Lines 108349 108409 +60
Branches 42492 42496 +4
==========================================
- Hits 32403 32370 -33
- Misses 72763 72852 +89
- Partials 3183 3187 +4
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Mamoru Sobue <[email protected]>
58c879a
to
83e3f8f
Compare
Description
Currently
thread_safe_data_
member variable is accessed from many member functions. This structure is not healthy because there are other possible not thread-safe member variables, and numerous number of call to lock() is very insufficient.After this PR, there are 3 agents
goal_planner_module
Lock the
lane_parking_mutex_
, andLaneParkingRequest
memberLaneParkingResponse
to local scopeLock the
freespace_parking_mutex_
, andFreespaceParkingRequest
memberFreespaceParkingResponse
to local scopeLaneParkingThread
Lock the
lane_parking_mutex_
which is shared with goal_planner_module via reference, andLaneParkingResponse
to local scopeAfter computation,
Lock the
lane_parking_mutex_
, andLaneParkingResponse
This will be used by goal_planner_module
FreespaceParkingThread
Lock the
freespace_parking_mutex_
which is shared with goal_planner_module via reference, andFreespaceParkingResponse
to local scopeAfter computation,
Lock the
freespace_parking_mutex_
, andFreespaceParkingResponse
This will be used by goal_planner_module
Overall, thread safe data has been divided to above 4 classes, and the
response
value is copied to module sidePullOverContextData
member, so repetitive access to thread_safe_data withlock
have been purged.Related links
Parent Issue:
How was this PR tested?
Notes for reviewers
None.
Interface changes
None.
Effects on system behavior
None.