Skip to content

Commit 2c765a9

Browse files
danielsanchezaransaka1-s
authored andcommitted
feat(goal_planner): add general turnsignalinfo method for goal planner (autowarefoundation#6629)
add general turnsignalinfo method for goal planner Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 5bcd590 commit 2c765a9

File tree

2 files changed

+91
-33
lines changed

2 files changed

+91
-33
lines changed

planning/behavior_path_goal_planner_module/include/behavior_path_goal_planner_module/goal_planner_module.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
3838
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_command.hpp>
3939

40+
#include <lanelet2_core/Forward.h>
41+
42+
#include <atomic>
4043
#include <deque>
4144
#include <limits>
4245
#include <memory>
@@ -452,9 +455,8 @@ class GoalPlannerModule : public SceneModuleInterface
452455
void setDrivableAreaInfo(BehaviorModuleOutput & output) const;
453456

454457
// output setter
455-
void setOutput(BehaviorModuleOutput & output) const;
456-
void setStopPath(BehaviorModuleOutput & output) const;
457-
void updatePreviousData(const BehaviorModuleOutput & output);
458+
void setOutput(BehaviorModuleOutput & output);
459+
void updatePreviousData();
458460

459461
/**
460462
* @brief Sets a stop path in the current path based on safety conditions and previous paths.
@@ -467,10 +469,11 @@ class GoalPlannerModule : public SceneModuleInterface
467469
*/
468470
void setStopPathFromCurrentPath(BehaviorModuleOutput & output) const;
469471
void setModifiedGoal(BehaviorModuleOutput & output) const;
470-
void setTurnSignalInfo(BehaviorModuleOutput & output) const;
472+
void setTurnSignalInfo(BehaviorModuleOutput & output);
471473

472474
// new turn signal
473-
TurnSignalInfo calcTurnSignalInfo() const;
475+
TurnSignalInfo calcTurnSignalInfo();
476+
std::optional<lanelet::Id> ignore_signal_{std::nullopt};
474477

475478
std::optional<BehaviorModuleOutput> last_previous_module_output_{};
476479
bool hasPreviousModulePathShapeChanged() const;

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

+83-28
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ std::vector<DrivableLanes> GoalPlannerModule::generateDrivableLanes() const
796796
return utils::generateDrivableLanesWithShoulderLanes(current_lanes, pull_over_lanes);
797797
}
798798

799-
void GoalPlannerModule::setOutput(BehaviorModuleOutput & output) const
799+
void GoalPlannerModule::setOutput(BehaviorModuleOutput & output)
800800
{
801801
output.reference_path = getPreviousModuleOutput().reference_path;
802802

@@ -907,7 +907,7 @@ void GoalPlannerModule::setModifiedGoal(BehaviorModuleOutput & output) const
907907
}
908908
}
909909

910-
void GoalPlannerModule::setTurnSignalInfo(BehaviorModuleOutput & output) const
910+
void GoalPlannerModule::setTurnSignalInfo(BehaviorModuleOutput & output)
911911
{
912912
const auto original_signal = getPreviousModuleOutput().turn_signal_info;
913913
const auto new_signal = calcTurnSignalInfo();
@@ -1433,43 +1433,98 @@ bool GoalPlannerModule::isOnModifiedGoal() const
14331433
parameters_->th_arrived_distance;
14341434
}
14351435

1436-
TurnSignalInfo GoalPlannerModule::calcTurnSignalInfo() const
1436+
TurnSignalInfo GoalPlannerModule::calcTurnSignalInfo()
14371437
{
1438-
TurnSignalInfo turn_signal{}; // output
1438+
const auto path = thread_safe_data_.get_pull_over_path()->getFullPath();
1439+
if (path.points.empty()) return getPreviousModuleOutput().turn_signal_info;
14391440

14401441
const auto & current_pose = planner_data_->self_odometry->pose.pose;
14411442
const auto & start_pose = thread_safe_data_.get_pull_over_path()->start_pose;
14421443
const auto & end_pose = thread_safe_data_.get_pull_over_path()->end_pose;
1443-
const auto full_path = thread_safe_data_.get_pull_over_path()->getFullPath();
14441444

1445-
// calc TurnIndicatorsCommand
1446-
{
1447-
const double distance_to_end =
1448-
calcSignedArcLength(full_path.points, current_pose.position, end_pose.position);
1449-
const bool is_before_end_pose = distance_to_end >= 0.0;
1450-
if (is_before_end_pose) {
1451-
if (left_side_parking_) {
1452-
turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
1453-
} else {
1454-
turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
1455-
}
1456-
} else {
1457-
turn_signal.turn_signal.command = TurnIndicatorsCommand::NO_COMMAND;
1445+
const auto shift_start_idx = motion_utils::findNearestIndex(path.points, start_pose.position);
1446+
const auto shift_end_idx = motion_utils::findNearestIndex(path.points, end_pose.position);
1447+
1448+
const auto is_ignore_signal = [this](const lanelet::Id & id) {
1449+
if (!ignore_signal_.has_value()) {
1450+
return false;
14581451
}
1452+
return ignore_signal_.value() == id;
1453+
};
1454+
1455+
const auto update_ignore_signal = [this](const lanelet::Id & id, const bool is_ignore) {
1456+
return is_ignore ? std::make_optional(id) : std::nullopt;
1457+
};
1458+
1459+
const lanelet::ConstLanelets current_lanes = utils::getExtendedCurrentLanes(
1460+
planner_data_, parameters_->backward_goal_search_length,
1461+
parameters_->forward_goal_search_length,
1462+
/*forward_only_in_route*/ false);
1463+
1464+
if (current_lanes.empty()) {
1465+
return {};
14591466
}
14601467

1461-
// calc desired/required start/end point
1462-
{
1463-
// ego decelerates so that current pose is the point `turn_light_on_threshold_time` seconds
1464-
// before starting pull_over
1465-
turn_signal.desired_start_point =
1466-
last_approval_data_ && hasDecidedPath() ? last_approval_data_->pose : current_pose;
1467-
turn_signal.desired_end_point = end_pose;
1468-
turn_signal.required_start_point = start_pose;
1469-
turn_signal.required_end_point = end_pose;
1468+
lanelet::Lanelet closest_lanelet;
1469+
lanelet::utils::query::getClosestLanelet(current_lanes, current_pose, &closest_lanelet);
1470+
1471+
if (is_ignore_signal(closest_lanelet.id())) {
1472+
return getPreviousModuleOutput().turn_signal_info;
14701473
}
14711474

1472-
return turn_signal;
1475+
const double current_shift_length =
1476+
lanelet::utils::getArcCoordinates(current_lanes, current_pose).distance;
1477+
1478+
constexpr bool egos_lane_is_shifted = true;
1479+
constexpr bool is_driving_forward = true;
1480+
1481+
constexpr bool is_pull_out = false;
1482+
const bool override_ego_stopped_check = std::invoke([&]() {
1483+
if (thread_safe_data_.getPullOverPlannerType() == PullOverPlannerType::SHIFT) {
1484+
return false;
1485+
}
1486+
constexpr double distance_threshold = 1.0;
1487+
const auto stop_point =
1488+
thread_safe_data_.get_pull_over_path()->partial_paths.front().points.back();
1489+
const double distance_from_ego_to_stop_point = std::abs(motion_utils::calcSignedArcLength(
1490+
path.points, stop_point.point.pose.position, current_pose.position));
1491+
return distance_from_ego_to_stop_point < distance_threshold;
1492+
});
1493+
1494+
const auto [new_signal, is_ignore] = planner_data_->getBehaviorTurnSignalInfo(
1495+
path, shift_start_idx, shift_end_idx, current_lanes, current_shift_length, is_driving_forward,
1496+
egos_lane_is_shifted, override_ego_stopped_check, is_pull_out);
1497+
ignore_signal_ = update_ignore_signal(closest_lanelet.id(), is_ignore);
1498+
1499+
return new_signal;
1500+
// // calc TurnIndicatorsCommand
1501+
// {
1502+
// const double distance_to_end =
1503+
// calcSignedArcLength(full_path.points, current_pose.position, end_pose.position);
1504+
// const bool is_before_end_pose = distance_to_end >= 0.0;
1505+
// if (is_before_end_pose) {
1506+
// if (left_side_parking_) {
1507+
// turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_LEFT;
1508+
// } else {
1509+
// turn_signal.turn_signal.command = TurnIndicatorsCommand::ENABLE_RIGHT;
1510+
// }
1511+
// } else {
1512+
// turn_signal.turn_signal.command = TurnIndicatorsCommand::NO_COMMAND;
1513+
// }
1514+
// }
1515+
1516+
// // calc desired/required start/end point
1517+
// {
1518+
// // ego decelerates so that current pose is the point `turn_light_on_threshold_time` seconds
1519+
// // before starting pull_over
1520+
// turn_signal.desired_start_point =
1521+
// last_approval_data_ && hasDecidedPath() ? last_approval_data_->pose : current_pose;
1522+
// turn_signal.desired_end_point = end_pose;
1523+
// turn_signal.required_start_point = start_pose;
1524+
// turn_signal.required_end_point = end_pose;
1525+
// }
1526+
1527+
// return turn_signal;
14731528
}
14741529

14751530
bool GoalPlannerModule::checkOccupancyGridCollision(const PathWithLaneId & path) const

0 commit comments

Comments
 (0)