Skip to content

Commit 2c45de7

Browse files
further refactoring
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent ebef825 commit 2c45de7

File tree

2 files changed

+85
-81
lines changed

2 files changed

+85
-81
lines changed

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/start_planner_module.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ class StartPlannerModule : public SceneModuleInterface
178178

179179
bool requiresDynamicObjectsCollisionDetection() const;
180180

181+
uint16_t getSteeringFactorDirection(
182+
const behavior_path_planner::BehaviorModuleOutput & output) const
183+
{
184+
switch (output.turn_signal_info.turn_signal.command) {
185+
case TurnIndicatorsCommand::ENABLE_LEFT:
186+
return SteeringFactor::LEFT;
187+
188+
case TurnIndicatorsCommand::ENABLE_RIGHT:
189+
return SteeringFactor::RIGHT;
190+
191+
default:
192+
return SteeringFactor::STRAIGHT;
193+
}
194+
};
195+
181196
/**
182197
* @brief Check if there are no moving objects around within a certain radius.
183198
*

planning/behavior_path_start_planner_module/src/start_planner_module.cpp

+70-81
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,7 @@ BehaviorModuleOutput StartPlannerModule::plan()
452452

453453
setDrivableAreaInfo(output);
454454

455-
const uint16_t steering_factor_direction = std::invoke([&output]() {
456-
if (output.turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_LEFT) {
457-
return SteeringFactor::LEFT;
458-
} else if (output.turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_RIGHT) {
459-
return SteeringFactor::RIGHT;
460-
}
461-
return SteeringFactor::STRAIGHT;
462-
});
455+
const auto steering_factor_direction = getSteeringFactorDirection(output);
463456

464457
if (status_.driving_forward) {
465458
const double start_distance = motion_utils::calcSignedArcLength(
@@ -473,15 +466,16 @@ BehaviorModuleOutput StartPlannerModule::plan()
473466
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose},
474467
{start_distance, finish_distance}, PlanningBehavior::START_PLANNER, steering_factor_direction,
475468
SteeringFactor::TURNING, "");
476-
} else {
477-
const double distance = motion_utils::calcSignedArcLength(
478-
path.points, planner_data_->self_odometry->pose.pose.position,
479-
status_.pull_out_path.start_pose.position);
480-
updateRTCStatus(0.0, distance);
481-
steering_factor_interface_ptr_->updateSteeringFactor(
482-
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose}, {0.0, distance},
483-
PlanningBehavior::START_PLANNER, steering_factor_direction, SteeringFactor::TURNING, "");
469+
setDebugData();
470+
return output;
484471
}
472+
const double distance = motion_utils::calcSignedArcLength(
473+
path.points, planner_data_->self_odometry->pose.pose.position,
474+
status_.pull_out_path.start_pose.position);
475+
updateRTCStatus(0.0, distance);
476+
steering_factor_interface_ptr_->updateSteeringFactor(
477+
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose}, {0.0, distance},
478+
PlanningBehavior::START_PLANNER, steering_factor_direction, SteeringFactor::TURNING, "");
485479

486480
setDebugData();
487481

@@ -562,14 +556,7 @@ BehaviorModuleOutput StartPlannerModule::planWaitingApproval()
562556

563557
setDrivableAreaInfo(output);
564558

565-
const uint16_t steering_factor_direction = std::invoke([&output]() {
566-
if (output.turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_LEFT) {
567-
return SteeringFactor::LEFT;
568-
} else if (output.turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_RIGHT) {
569-
return SteeringFactor::RIGHT;
570-
}
571-
return SteeringFactor::STRAIGHT;
572-
});
559+
const auto steering_factor_direction = getSteeringFactorDirection(output);
573560

574561
if (status_.driving_forward) {
575562
const double start_distance = motion_utils::calcSignedArcLength(
@@ -583,15 +570,17 @@ BehaviorModuleOutput StartPlannerModule::planWaitingApproval()
583570
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose},
584571
{start_distance, finish_distance}, PlanningBehavior::START_PLANNER, steering_factor_direction,
585572
SteeringFactor::APPROACHING, "");
586-
} else {
587-
const double distance = motion_utils::calcSignedArcLength(
588-
stop_path.points, planner_data_->self_odometry->pose.pose.position,
589-
status_.pull_out_path.start_pose.position);
590-
updateRTCStatus(0.0, distance);
591-
steering_factor_interface_ptr_->updateSteeringFactor(
592-
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose}, {0.0, distance},
593-
PlanningBehavior::START_PLANNER, steering_factor_direction, SteeringFactor::APPROACHING, "");
573+
setDebugData();
574+
575+
return output;
594576
}
577+
const double distance = motion_utils::calcSignedArcLength(
578+
stop_path.points, planner_data_->self_odometry->pose.pose.position,
579+
status_.pull_out_path.start_pose.position);
580+
updateRTCStatus(0.0, distance);
581+
steering_factor_interface_ptr_->updateSteeringFactor(
582+
{status_.pull_out_path.start_pose, status_.pull_out_path.end_pose}, {0.0, distance},
583+
PlanningBehavior::START_PLANNER, steering_factor_direction, SteeringFactor::APPROACHING, "");
595584

596585
setDebugData();
597586

@@ -651,16 +640,20 @@ PriorityOrder StartPlannerModule::determinePriorityOrder(
651640
order_priority.emplace_back(i, planner);
652641
}
653642
}
654-
} else if (search_priority == "short_back_distance") {
643+
return order_priority;
644+
}
645+
646+
if (search_priority == "short_back_distance") {
655647
for (size_t i = 0; i < start_pose_candidates_num; i++) {
656648
for (const auto & planner : start_planners_) {
657649
order_priority.emplace_back(i, planner);
658650
}
659651
}
660-
} else {
661-
RCLCPP_ERROR(getLogger(), "Invalid search_priority: %s", search_priority.c_str());
662-
throw std::domain_error("[start_planner] invalid search_priority");
652+
return order_priority;
663653
}
654+
655+
RCLCPP_ERROR(getLogger(), "Invalid search_priority: %s", search_priority.c_str());
656+
throw std::domain_error("[start_planner] invalid search_priority");
664657
return order_priority;
665658
}
666659

@@ -1092,12 +1085,7 @@ bool StartPlannerModule::isStuck()
10921085
return false;
10931086
}
10941087

1095-
if (status_.planner_type == PlannerType::STOP) {
1096-
return true;
1097-
}
1098-
1099-
// not found safe path
1100-
if (!status_.found_pull_out_path) {
1088+
if (status_.planner_type == PlannerType::STOP || !status_.found_pull_out_path) {
11011089
return true;
11021090
}
11031091

@@ -1190,30 +1178,26 @@ TurnSignalInfo StartPlannerModule::calcTurnSignalInfo() const
11901178
return false;
11911179
});
11921180

1193-
if (is_near_intersection) {
1194-
// offset required end pose with ration to activate turn signal for intersection
1195-
turn_signal.required_end_point = std::invoke([&]() {
1196-
const double length_start_to_end =
1197-
motion_utils::calcSignedArcLength(path.points, start_pose.position, end_pose.position);
1198-
const auto ratio = std::clamp(
1199-
parameters_->length_ratio_for_turn_signal_deactivation_near_intersection, 0.0, 1.0);
1200-
1201-
const double required_end_length = length_start_to_end * ratio;
1202-
double accumulated_length = 0.0;
1203-
const size_t start_idx = motion_utils::findNearestIndex(path.points, start_pose.position);
1204-
for (size_t i = start_idx; i < path.points.size() - 1; ++i) {
1205-
accumulated_length +=
1206-
tier4_autoware_utils::calcDistance2d(path.points.at(i), path.points.at(i + 1));
1207-
if (accumulated_length > required_end_length) {
1208-
return path.points.at(i).point.pose;
1209-
}
1181+
turn_signal.required_end_point = std::invoke([&]() {
1182+
if (is_near_intersection) return end_pose;
1183+
const double length_start_to_end =
1184+
motion_utils::calcSignedArcLength(path.points, start_pose.position, end_pose.position);
1185+
const auto ratio = std::clamp(
1186+
parameters_->length_ratio_for_turn_signal_deactivation_near_intersection, 0.0, 1.0);
1187+
1188+
const double required_end_length = length_start_to_end * ratio;
1189+
double accumulated_length = 0.0;
1190+
const size_t start_idx = motion_utils::findNearestIndex(path.points, start_pose.position);
1191+
for (size_t i = start_idx; i < path.points.size() - 1; ++i) {
1192+
accumulated_length +=
1193+
tier4_autoware_utils::calcDistance2d(path.points.at(i), path.points.at(i + 1));
1194+
if (accumulated_length > required_end_length) {
1195+
return path.points.at(i).point.pose;
12101196
}
1211-
// not found required end point
1212-
return end_pose;
1213-
});
1214-
} else {
1215-
turn_signal.required_end_point = end_pose;
1216-
}
1197+
}
1198+
// not found required end point
1199+
return end_pose;
1200+
});
12171201

12181202
return turn_signal;
12191203
}
@@ -1382,22 +1366,27 @@ bool StartPlannerModule::planFreespacePath()
13821366

13831367
void StartPlannerModule::setDrivableAreaInfo(BehaviorModuleOutput & output) const
13841368
{
1385-
if (status_.planner_type == PlannerType::FREESPACE) {
1386-
const double drivable_area_margin = planner_data_->parameters.vehicle_width;
1387-
output.drivable_area_info.drivable_margin =
1388-
planner_data_->parameters.vehicle_width / 2.0 + drivable_area_margin;
1389-
} else {
1390-
const auto target_drivable_lanes = utils::getNonOverlappingExpandedLanes(
1391-
output.path, generateDrivableLanes(output.path),
1392-
planner_data_->drivable_area_expansion_parameters);
1393-
1394-
DrivableAreaInfo current_drivable_area_info;
1395-
current_drivable_area_info.drivable_lanes = target_drivable_lanes;
1396-
output.drivable_area_info =
1397-
status_.driving_forward
1398-
? utils::combineDrivableAreaInfo(
1399-
current_drivable_area_info, getPreviousModuleOutput().drivable_area_info)
1400-
: current_drivable_area_info;
1369+
switch (status_.planner_type) {
1370+
case PlannerType::FREESPACE: {
1371+
const double drivable_area_margin = planner_data_->parameters.vehicle_width;
1372+
output.drivable_area_info.drivable_margin =
1373+
planner_data_->parameters.vehicle_width / 2.0 + drivable_area_margin;
1374+
break;
1375+
}
1376+
default: {
1377+
const auto target_drivable_lanes = utils::getNonOverlappingExpandedLanes(
1378+
output.path, generateDrivableLanes(output.path),
1379+
planner_data_->drivable_area_expansion_parameters);
1380+
1381+
DrivableAreaInfo current_drivable_area_info;
1382+
current_drivable_area_info.drivable_lanes = target_drivable_lanes;
1383+
output.drivable_area_info =
1384+
status_.driving_forward
1385+
? utils::combineDrivableAreaInfo(
1386+
current_drivable_area_info, getPreviousModuleOutput().drivable_area_info)
1387+
: current_drivable_area_info;
1388+
break;
1389+
}
14011390
}
14021391
}
14031392

0 commit comments

Comments
 (0)