Skip to content

Commit 318b382

Browse files
committed
update planner, add map parameter
Signed-off-by: Barış Zeren <bzeren1819@gmail.com>
1 parent cf221be commit 318b382

File tree

11 files changed

+100
-45
lines changed

11 files changed

+100
-45
lines changed

launch/tier4_planning_launch/launch/planning.launch.xml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<arg name="planning_validator_param_path"/>
1010
<!-- Auto mode setting-->
1111
<arg name="enable_all_modules_auto_mode"/>
12+
<!-- Differential lanelet map loading setting -->
13+
<arg name="enable_differential_map_loading" default="true"/>
1214

1315
<group>
1416
<push-ros-namespace namespace="planning"/>
@@ -25,6 +27,7 @@
2527
<push-ros-namespace namespace="scenario_planning"/>
2628
<include file="$(find-pkg-share tier4_planning_launch)/launch/scenario_planning/scenario_planning.launch.xml">
2729
<arg name="enable_all_modules_auto_mode" value="$(var enable_all_modules_auto_mode)"/>
30+
<arg name="enable_differential_map_loading" value="$(var enable_differential_map_loading)"/>
2831
</include>
2932
</group>
3033

launch/tier4_planning_launch/launch/scenario_planning/lane_driving.launch.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<launch>
22
<arg name="enable_all_modules_auto_mode"/>
3+
<arg name="enable_differential_map_loading"/>
34

45
<!-- lane_driving scenario -->
56
<group>
@@ -11,6 +12,7 @@
1112
<include file="$(find-pkg-share tier4_planning_launch)/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.xml">
1213
<arg name="container_type" value="component_container_mt"/>
1314
<arg name="enable_all_modules_auto_mode" value="$(var enable_all_modules_auto_mode)"/>
15+
<arg name="enable_differential_map_loading" value="$(var enable_differential_map_loading)"/>
1416
<!-- This condition should be true if run_out module is enabled and its detection method is Points -->
1517
<arg name="launch_compare_map_pipeline" value="false"/>
1618
</include>

launch/tier4_planning_launch/launch/scenario_planning/lane_driving/behavior_planning/behavior_planning.launch.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<launch>
2+
<arg name="enable_all_modules_auto_mode"/>
3+
<arg name="enable_differential_map_loading"/>
4+
25
<arg name="input_route_topic_name" default="/planning/mission_planning/route"/>
36
<arg name="input_traffic_light_topic_name" default="/perception/traffic_light_recognition/traffic_signals"/>
47
<arg name="input_virtual_traffic_light_topic_name" default="/awapi/tmp/virtual_traffic_light_states"/>
5-
<arg name="input_vector_map_topic_name" default="/map/vector_map"/>
8+
<arg name="input_vector_map_topic_name" default="/map/vector_map" unless="$(var enable_differential_map_loading)"/>
9+
<arg name="input_vector_map_topic_name" default="/map/dynamic_vector_map" if="$(var enable_differential_map_loading)"/>
610
<arg name="input_pointcloud_map_topic_name" default="/map/pointcloud_map"/>
7-
<arg name="enable_all_modules_auto_mode"/>
811

912
<arg name="launch_avoidance_module" default="true"/>
1013
<arg name="launch_avoidance_by_lane_change_module" default="true"/>
@@ -203,6 +206,7 @@
203206
<param from="$(var nearest_search_param_path)"/>
204207
<param name="launch_modules" value="$(var behavior_path_planner_launch_modules)"/>
205208
<param name="enable_all_modules_auto_mode" value="$(var enable_all_modules_auto_mode)"/>
209+
<param name="enable_differential_map_loading" value="$(var enable_differential_map_loading)"/>
206210
<param from="$(var behavior_path_planner_side_shift_module_param_path)"/>
207211
<param from="$(var behavior_path_planner_avoidance_module_param_path)"/>
208212
<param from="$(var behavior_path_planner_avoidance_by_lc_module_param_path)"/>

launch/tier4_planning_launch/launch/scenario_planning/scenario_planning.launch.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<launch>
22
<arg name="enable_all_modules_auto_mode"/>
3+
<arg name="enable_differential_map_loading"/>
34
<!-- scenario selector -->
45
<group>
56
<include file="$(find-pkg-share scenario_selector)/launch/scenario_selector.launch.xml">
@@ -53,6 +54,7 @@
5354
<group>
5455
<include file="$(find-pkg-share tier4_planning_launch)/launch/scenario_planning/lane_driving.launch.xml">
5556
<arg name="enable_all_modules_auto_mode" value="$(var enable_all_modules_auto_mode)"/>
57+
<arg name="enable_differential_map_loading" value="$(var enable_differential_map_loading)"/>
5658
</include>
5759
</group>
5860
<!-- parking -->

planning/behavior_path_planner/src/behavior_path_planner_node.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ BehaviorPathPlannerParameters BehaviorPathPlannerNode::getCommonParam()
263263
p.ego_nearest_dist_threshold = declare_parameter<double>("ego_nearest_dist_threshold");
264264
p.ego_nearest_yaw_threshold = declare_parameter<double>("ego_nearest_yaw_threshold");
265265

266+
p.enable_differential_map_loading = declare_parameter<bool>("enable_differential_map_loading");
267+
266268
return p;
267269
}
268270

@@ -352,7 +354,8 @@ void BehaviorPathPlannerNode::run()
352354

353355
// update map
354356
if (map_ptr) {
355-
planner_data_->route_handler->setMap(*map_ptr);
357+
planner_data_->route_handler->setMap(
358+
*map_ptr, planner_data_->parameters.enable_differential_map_loading);
356359
planner_manager_->resetRootLanelet(planner_data_);
357360
}
358361

@@ -361,7 +364,8 @@ void BehaviorPathPlannerNode::run()
361364
// update route
362365
const bool is_first_time = !(planner_data_->route_handler->isHandlerReady());
363366
if (route_ptr) {
364-
planner_data_->route_handler->setRoute(*route_ptr);
367+
planner_data_->route_handler->setRoute(
368+
*route_ptr, planner_data_->parameters.enable_differential_map_loading);
365369
planner_manager_->resetRootLanelet(planner_data_);
366370

367371
// uuid is not changed when rerouting with modified goal,

planning/behavior_path_planner/src/planner_manager.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ BehaviorModuleOutput PlannerManager::run(const std::shared_ptr<PlannerData> & da
116116
is_any_approved_module_running || is_any_candidate_module_running_or_idle;
117117

118118
const bool is_out_of_route = utils::isEgoOutOfRoute(
119-
data->self_odometry->pose.pose, data->prev_modified_goal, data->route_handler);
119+
data->self_odometry->pose.pose, data->prev_modified_goal, data->route_handler,
120+
data->parameters);
120121

121122
if (!is_any_module_running && is_out_of_route) {
122123
BehaviorModuleOutput output = utils::createGoalAroundPath(data);

planning/behavior_path_planner_common/include/behavior_path_planner_common/parameters.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ struct BehaviorPathPlannerParameters
7676
double right_over_hang;
7777
double base_link2front;
7878
double base_link2rear;
79+
80+
// enable/disable differential map loading
81+
bool enable_differential_map_loading;
7982
};
8083

8184
#endif // BEHAVIOR_PATH_PLANNER_COMMON__PARAMETERS_HPP_

planning/behavior_path_planner_common/include/behavior_path_planner_common/utils/utils.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ bool isInLaneletWithYawThreshold(
232232

233233
bool isEgoOutOfRoute(
234234
const Pose & self_pose, const std::optional<PoseWithUuidStamped> & modified_goal,
235-
const std::shared_ptr<RouteHandler> & route_handler);
235+
const std::shared_ptr<RouteHandler> & route_handler,
236+
const BehaviorPathPlannerParameters & common_param);
236237

237238
bool isEgoWithinOriginalLane(
238239
const lanelet::ConstLanelets & current_lanes, const Pose & current_pose,

planning/behavior_path_planner_common/src/utils/utils.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ bool isInLaneletWithYawThreshold(
491491

492492
bool isEgoOutOfRoute(
493493
const Pose & self_pose, const std::optional<PoseWithUuidStamped> & modified_goal,
494-
const std::shared_ptr<RouteHandler> & route_handler)
494+
const std::shared_ptr<RouteHandler> & route_handler,
495+
const BehaviorPathPlannerParameters & common_param)
495496
{
496497
const Pose & goal_pose = (modified_goal && modified_goal->uuid == route_handler->getRouteUuid())
497498
? modified_goal->pose
@@ -503,17 +504,27 @@ bool isEgoOutOfRoute(
503504
if (utils::isInLanelets(goal_pose, shoulder_lanes)) {
504505
return !lanelet::utils::query::getClosestLanelet(shoulder_lanes, goal_pose, &goal_lane);
505506
}
506-
lanelet::LaneletMapPtr map = route_handler->getLaneletMapPtr();
507-
lanelet::ConstLanelets all_lanelets = lanelet::utils::query::laneletLayer(map);
508-
lanelet::ConstLanelets route_lanelets = route_handler->getRouteLanelets();
509-
for (auto it = route_lanelets.rbegin(); it != route_lanelets.rend(); ++it) {
510-
for (auto it2 = all_lanelets.rbegin(); it2 != all_lanelets.rend(); ++it2) {
511-
if ((*it).id() == (*it2).id()) {
512-
// std::cout << "Route lanelet id: " << (*it).id() << std::endl;
513-
// select the lanelet goal lanelet
514-
goal_lane = *it2;
515-
return false;
516-
}
507+
if (common_param.enable_differential_map_loading) {
508+
// If dynamic map is enabled, get the goal lanelet from the current lanelet map
509+
//
510+
// Check the route lanelets and last route element in the current lanelet map
511+
// will be the goal lanelet
512+
513+
lanelet::LaneletMapPtr map = route_handler->getLaneletMapPtr();
514+
lanelet::ConstLanelets all_lanelets = lanelet::utils::query::laneletLayer(map);
515+
lanelet::ConstLanelets route_lanelets = route_handler->getRouteLanelets();
516+
517+
auto goalLaneletIt =
518+
std::find_if(all_lanelets.rbegin(), all_lanelets.rend(), [&](const auto & currentLanelet) {
519+
return currentLanelet.id() == route_lanelets.back().id();
520+
});
521+
522+
if (goalLaneletIt != all_lanelets.rend()) {
523+
RCLCPP_DEBUG(
524+
rclcpp::get_logger("behavior_path_planner").get_child("util"),
525+
"Found goal lanelet in current lanelet map");
526+
goal_lane = *goalLaneletIt;
527+
return false;
517528
}
518529
}
519530
return !route_handler->getGoalLanelet(&goal_lane);

planning/route_handler/include/route_handler/route_handler.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class RouteHandler
5757
explicit RouteHandler(const HADMapBin & map_msg);
5858

5959
// non-const methods
60-
void setMap(const HADMapBin & map_msg);
61-
void setRoute(const LaneletRoute & route_msg);
60+
void setMap(const HADMapBin & map_msg, const bool & is_enable_differantial_lanelet = false);
61+
void setRoute(const LaneletRoute & route_msg, const bool & is_enable_differantial_lanelet = false);
6262
void setRouteLanelets(const lanelet::ConstLanelets & path_lanelets);
6363
void clearRoute();
6464

@@ -380,7 +380,7 @@ class RouteHandler
380380
Pose original_goal_pose_;
381381

382382
// non-const methods
383-
void setLaneletsFromRouteMsg();
383+
void setLaneletsFromRouteMsg(const bool & is_enable_differantial_lanelet = false);
384384

385385
// const methods
386386
// for routing

planning/route_handler/src/route_handler.cpp

+48-24
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ RouteHandler::RouteHandler(const HADMapBin & map_msg)
139139
route_ptr_ = nullptr;
140140
}
141141

142-
void RouteHandler::setMap(const HADMapBin & map_msg)
142+
void RouteHandler::setMap(const HADMapBin & map_msg, const bool & is_enable_differantial_lanelet)
143143
{
144144
lanelet_map_ptr_ = std::make_shared<lanelet::LaneletMap>();
145145
lanelet::utils::conversion::fromBinMsg(
@@ -163,7 +163,7 @@ void RouteHandler::setMap(const HADMapBin & map_msg)
163163
is_map_msg_ready_ = true;
164164
is_handler_ready_ = false;
165165

166-
setLaneletsFromRouteMsg();
166+
setLaneletsFromRouteMsg(is_enable_differantial_lanelet);
167167
}
168168

169169
bool RouteHandler::isRouteLooped(const RouteSections & route_sections)
@@ -180,7 +180,8 @@ bool RouteHandler::isRouteLooped(const RouteSections & route_sections)
180180
return false;
181181
}
182182

183-
void RouteHandler::setRoute(const LaneletRoute & route_msg)
183+
void RouteHandler::setRoute(
184+
const LaneletRoute & route_msg, const bool & is_enable_differantial_lanelet)
184185
{
185186
if (!isRouteLooped(route_msg.segments)) {
186187
// if get not modified route but new route, reset original start pose
@@ -190,7 +191,7 @@ void RouteHandler::setRoute(const LaneletRoute & route_msg)
190191
}
191192
route_ptr_ = std::make_shared<LaneletRoute>(route_msg);
192193
is_handler_ready_ = false;
193-
setLaneletsFromRouteMsg();
194+
setLaneletsFromRouteMsg(is_enable_differantial_lanelet);
194195
} else {
195196
RCLCPP_ERROR(
196197
logger_,
@@ -313,17 +314,19 @@ void RouteHandler::clearRoute()
313314
is_handler_ready_ = false;
314315
}
315316

316-
void RouteHandler::setLaneletsFromRouteMsg()
317+
void RouteHandler::setLaneletsFromRouteMsg(const bool & is_enable_differantial_lanelet)
317318
{
318319
if (!route_ptr_ || !is_map_msg_ready_) {
319320
return;
320321
}
321322
route_lanelets_.clear();
322323
preferred_lanelets_.clear();
323-
// const bool is_route_valid = lanelet::utils::route::isRouteValid(*route_ptr_,
324-
// lanelet_map_ptr_); if (!is_route_valid) {
325-
// return;
326-
// }
324+
if (!is_enable_differantial_lanelet) {
325+
const bool is_route_valid = lanelet::utils::route::isRouteValid(*route_ptr_, lanelet_map_ptr_);
326+
if (!is_route_valid) {
327+
return;
328+
}
329+
}
327330

328331
size_t primitive_size{0};
329332
for (const auto & route_section : route_ptr_->segments) {
@@ -341,11 +344,18 @@ void RouteHandler::setLaneletsFromRouteMsg()
341344
preferred_lanelets_.push_back(llt);
342345
}
343346
} catch (const std::exception & e) {
344-
std::cerr
345-
<< e.what()
346-
<< ". Maybe the loaded route was created on a different Map from the current one. "
347-
"Try to load the other Route again."
348-
<< std::endl;
347+
if (!is_enable_differantial_lanelet) {
348+
std::cerr
349+
<< e.what()
350+
<< ". Maybe the loaded route was created on a different Map from the current one. "
351+
"Try to load the other Route again."
352+
<< std::endl;
353+
return;
354+
} else {
355+
RCLCPP_DEBUG(
356+
logger_, "Failed to get lanelet differential map with id: %ld. %s", primitive.id,
357+
e.what());
358+
}
349359
}
350360
}
351361
}
@@ -359,11 +369,18 @@ void RouteHandler::setLaneletsFromRouteMsg()
359369
const auto & llt = lanelet_map_ptr_->laneletLayer.get(id);
360370
goal_lanelets_.push_back(llt);
361371
} catch (const std::exception & e) {
362-
std::cerr
363-
<< e.what()
364-
<< ". Maybe the loaded route was created on a different Map from the current one. "
365-
"Try to load the other Route again."
366-
<< std::endl;
372+
if (!is_enable_differantial_lanelet) {
373+
std::cerr
374+
<< e.what()
375+
<< ". Maybe the loaded route was created on a different Map from the current one. "
376+
"Try to load the other Route again."
377+
<< std::endl;
378+
return;
379+
} else {
380+
RCLCPP_DEBUG(
381+
logger_, "Failed to get lanelet differential map with id: %ld. %s", primitive.id,
382+
e.what());
383+
}
367384
}
368385
}
369386
start_lanelets_.reserve(route_ptr_->segments.front().primitives.size());
@@ -373,11 +390,18 @@ void RouteHandler::setLaneletsFromRouteMsg()
373390
const auto & llt = lanelet_map_ptr_->laneletLayer.get(id);
374391
start_lanelets_.push_back(llt);
375392
} catch (const std::exception & e) {
376-
std::cerr
377-
<< e.what()
378-
<< ". Maybe the loaded route was created on a different Map from the current one. "
379-
"Try to load the other Route again."
380-
<< std::endl;
393+
if (!is_enable_differantial_lanelet) {
394+
std::cerr
395+
<< e.what()
396+
<< ". Maybe the loaded route was created on a different Map from the current one. "
397+
"Try to load the other Route again."
398+
<< std::endl;
399+
return;
400+
} else {
401+
RCLCPP_DEBUG(
402+
logger_, "Failed to get lanelet differential map with id: %ld. %s", primitive.id,
403+
e.what());
404+
}
381405
}
382406
}
383407
}

0 commit comments

Comments
 (0)