Skip to content

Commit 020ec25

Browse files
Add general turnSignal method to start planner
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 6ee9627 commit 020ec25

File tree

2 files changed

+56
-87
lines changed

2 files changed

+56
-87
lines changed

planning/behavior_path_start_planner_module/include/behavior_path_start_planner_module/start_planner_module.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
3535

36+
#include <lanelet2_core/Forward.h>
3637
#include <tf2/utils.h>
3738

3839
#include <atomic>
@@ -239,6 +240,7 @@ class StartPlannerModule : public SceneModuleInterface
239240
std::vector<std::shared_ptr<PullOutPlannerBase>> start_planners_;
240241
PullOutStatus status_;
241242
mutable StartPlannerDebugData debug_data_;
243+
std::optional<lanelet::Id> ignore_signal_{std::nullopt};
242244

243245
std::deque<nav_msgs::msg::Odometry::ConstSharedPtr> odometry_buffer_;
244246

@@ -264,7 +266,7 @@ class StartPlannerModule : public SceneModuleInterface
264266
std::shared_ptr<LaneDepartureChecker> lane_departure_checker_;
265267

266268
// turn signal
267-
TurnSignalInfo calcTurnSignalInfo() const;
269+
TurnSignalInfo calcTurnSignalInfo();
268270

269271
void incrementPathIndex();
270272
PathWithLaneId getCurrentPath() const;

planning/behavior_path_start_planner_module/src/start_planner_module.cpp

+53-86
Original file line numberDiff line numberDiff line change
@@ -1215,103 +1215,70 @@ bool StartPlannerModule::hasFinishedCurrentPath()
12151215
return is_near_target && isStopped();
12161216
}
12171217

1218-
TurnSignalInfo StartPlannerModule::calcTurnSignalInfo() const
1218+
TurnSignalInfo StartPlannerModule::calcTurnSignalInfo()
12191219
{
1220-
TurnSignalInfo turn_signal{}; // output
1220+
const auto path = getFullPath();
1221+
if (path.points.empty()) return getPreviousModuleOutput().turn_signal_info;
12211222

12221223
const Pose & current_pose = planner_data_->self_odometry->pose.pose;
1223-
const Pose & start_pose = status_.pull_out_path.start_pose;
1224-
const Pose & end_pose = status_.pull_out_path.end_pose;
1225-
1226-
// turn on hazard light when backward driving
1227-
if (!status_.driving_forward) {
1228-
turn_signal.hazard_signal.command = HazardLightsCommand::ENABLE;
1229-
const auto back_start_pose = planner_data_->route_handler->getOriginalStartPose();
1230-
turn_signal.desired_start_point = back_start_pose;
1231-
turn_signal.required_start_point = back_start_pose;
1232-
// pull_out start_pose is same to backward driving end_pose
1233-
turn_signal.required_end_point = start_pose;
1234-
turn_signal.desired_end_point = start_pose;
1235-
return turn_signal;
1236-
}
1237-
1238-
// turn on right signal until passing pull_out end point
1239-
const auto path = getFullPath();
1240-
// pull out path does not overlap
1241-
const double distance_from_end =
1242-
motion_utils::calcSignedArcLength(path.points, end_pose.position, current_pose.position);
1224+
const auto shift_start_idx =
1225+
motion_utils::findNearestIndex(path.points, status_.pull_out_path.start_pose.position);
1226+
const auto shift_end_idx =
1227+
motion_utils::findNearestIndex(path.points, status_.pull_out_path.end_pose.position);
1228+
const lanelet::ConstLanelets current_lanes = utils::getCurrentLanes(planner_data_);
1229+
1230+
const auto is_ignore_signal = [this](const lanelet::Id & id) {
1231+
if (!ignore_signal_.has_value()) {
1232+
return false;
1233+
}
1234+
return ignore_signal_.value() == id;
1235+
};
12431236

1244-
if (path.points.empty()) {
1245-
return {};
1237+
const auto update_ignore_signal = [this](const lanelet::Id & id, const bool is_ignore) {
1238+
return is_ignore ? std::make_optional(id) : std::nullopt;
1239+
};
1240+
1241+
lanelet::Lanelet closest_lanelet;
1242+
lanelet::utils::query::getClosestLanelet(current_lanes, current_pose, &closest_lanelet);
1243+
1244+
if (is_ignore_signal(closest_lanelet.id())) {
1245+
return getPreviousModuleOutput().turn_signal_info;
12461246
}
12471247

1248-
// calculate lateral offset from pull out target lane center line
1249-
lanelet::ConstLanelet closest_road_lane;
1250-
const double backward_path_length =
1251-
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
1252-
const auto road_lanes = utils::getExtendedCurrentLanes(
1253-
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
1254-
/*forward_only_in_route*/ true);
1255-
lanelet::utils::query::getClosestLanelet(road_lanes, start_pose, &closest_road_lane);
1256-
const double lateral_offset =
1257-
lanelet::utils::getLateralDistanceToCenterline(closest_road_lane, start_pose);
1258-
1259-
turn_signal.turn_signal.command = std::invoke([&]() {
1260-
if (distance_from_end >= 0.0) return TurnIndicatorsCommand::DISABLE;
1261-
if (lateral_offset > parameters_->th_turn_signal_on_lateral_offset)
1262-
return TurnIndicatorsCommand::ENABLE_RIGHT;
1263-
if (lateral_offset < -parameters_->th_turn_signal_on_lateral_offset)
1264-
return TurnIndicatorsCommand::ENABLE_LEFT;
1265-
return TurnIndicatorsCommand::DISABLE;
1266-
});
1248+
const double current_shift_length =
1249+
lanelet::utils::getArcCoordinates(current_lanes, current_pose).distance;
12671250

1268-
turn_signal.desired_start_point = start_pose;
1269-
turn_signal.required_start_point = start_pose;
1270-
turn_signal.desired_end_point = end_pose;
1271-
1272-
// check if intersection exists within search length
1273-
const bool is_near_intersection = std::invoke([&]() {
1274-
const double check_length = parameters_->intersection_search_length;
1275-
double accumulated_length = 0.0;
1276-
const size_t current_idx = motion_utils::findNearestIndex(path.points, current_pose.position);
1277-
for (size_t i = current_idx; i < path.points.size() - 1; ++i) {
1278-
const auto & p = path.points.at(i);
1279-
for (const auto & lane : planner_data_->route_handler->getLaneletsFromIds(p.lane_ids)) {
1280-
const std::string turn_direction = lane.attributeOr("turn_direction", "else");
1281-
if (turn_direction == "right" || turn_direction == "left" || turn_direction == "straight") {
1282-
return true;
1283-
}
1284-
}
1285-
accumulated_length += tier4_autoware_utils::calcDistance2d(p, path.points.at(i + 1));
1286-
if (accumulated_length > check_length) {
1287-
return false;
1288-
}
1289-
}
1290-
return false;
1291-
});
1251+
constexpr bool egos_lane_is_shifted = true;
1252+
constexpr bool is_pull_out = true;
12921253

1293-
turn_signal.required_end_point = std::invoke([&]() {
1294-
if (is_near_intersection) return end_pose;
1295-
const double length_start_to_end =
1296-
motion_utils::calcSignedArcLength(path.points, start_pose.position, end_pose.position);
1297-
const auto ratio = std::clamp(
1298-
parameters_->length_ratio_for_turn_signal_deactivation_near_intersection, 0.0, 1.0);
1299-
1300-
const double required_end_length = length_start_to_end * ratio;
1301-
double accumulated_length = 0.0;
1302-
const size_t start_idx = motion_utils::findNearestIndex(path.points, start_pose.position);
1303-
for (size_t i = start_idx; i < path.points.size() - 1; ++i) {
1304-
accumulated_length +=
1305-
tier4_autoware_utils::calcDistance2d(path.points.at(i), path.points.at(i + 1));
1306-
if (accumulated_length > required_end_length) {
1307-
return path.points.at(i).point.pose;
1308-
}
1254+
// In Geometric pull out, the ego stops once and then steers the wheels to the opposite direction.
1255+
// This sometimes causes the getBehaviorTurnSignalInfo method to detect the ego as stopped and
1256+
// close to complete its shift, so it wrongly turns off the blinkers, this override helps avoid
1257+
// this issue.
1258+
const bool override_ego_stopped_check = std::invoke([&]() {
1259+
if (status_.planner_type != PlannerType::GEOMETRIC) {
1260+
return false;
13091261
}
1310-
// not found required end point
1311-
return end_pose;
1262+
constexpr double distance_threshold = 1.0;
1263+
const auto stop_point = status_.pull_out_path.partial_paths.front().points.back();
1264+
const double distance_from_ego_to_stop_point = std::abs(motion_utils::calcSignedArcLength(
1265+
path.points, stop_point.point.pose.position, current_pose.position));
1266+
return distance_from_ego_to_stop_point < distance_threshold;
13121267
});
13131268

1314-
return turn_signal;
1269+
const auto [new_signal, is_ignore] = planner_data_->getBehaviorTurnSignalInfo(
1270+
path, shift_start_idx, shift_end_idx, current_lanes, current_shift_length,
1271+
status_.driving_forward, egos_lane_is_shifted, override_ego_stopped_check, is_pull_out);
1272+
ignore_signal_ = update_ignore_signal(closest_lanelet.id(), is_ignore);
1273+
1274+
const auto original_signal = getPreviousModuleOutput().turn_signal_info;
1275+
const auto current_seg_idx = planner_data_->findEgoSegmentIndex(path.points);
1276+
const auto output_turn_signal_info = planner_data_->turn_signal_decider.use_prior_turn_signal(
1277+
path, current_pose, current_seg_idx, original_signal, new_signal,
1278+
planner_data_->parameters.ego_nearest_dist_threshold,
1279+
planner_data_->parameters.ego_nearest_yaw_threshold);
1280+
1281+
return output_turn_signal_info;
13151282
}
13161283

13171284
bool StartPlannerModule::isSafePath() const

0 commit comments

Comments
 (0)