Skip to content

Commit d44ce07

Browse files
committed
feat(intersection): consider abnormal violating vehicles
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent e6de0f6 commit d44ce07

File tree

4 files changed

+92
-39
lines changed

4 files changed

+92
-39
lines changed

planning/behavior_velocity_intersection_module/src/debug.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
291291
&debug_marker_array);
292292
}
293293

294+
if (debug_data_.yield_area) {
295+
appendMarkerArray(
296+
::createLaneletPolygonsMarkerArray(
297+
debug_data_.yield_area.value(), "yield_area", lane_id_, 0.6588235, 0.34509, 0.6588235),
298+
&debug_marker_array);
299+
}
300+
294301
if (debug_data_.ego_lane) {
295302
appendMarkerArray(
296303
::createLaneletPolygonsMarkerArray(

planning/behavior_velocity_intersection_module/src/intersection_lanelets.hpp

+32-19
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,29 @@ struct IntersectionLanelets
5252
{
5353
return is_prioritized_ ? attention_non_preceding_stoplines_ : attention_stoplines_;
5454
}
55+
const lanelet::ConstLanelets & attention_non_preceding() const
56+
{
57+
return attention_non_preceding_;
58+
}
5559
const lanelet::ConstLanelets & conflicting() const { return conflicting_; }
5660
const lanelet::ConstLanelets & adjacent() const { return adjacent_; }
5761
const lanelet::ConstLanelets & occlusion_attention() const
5862
{
5963
return is_prioritized_ ? attention_non_preceding_ : occlusion_attention_;
6064
}
61-
const lanelet::ConstLanelets & attention_non_preceding() const
65+
const lanelet::ConstLanelets & yield() const { return yield_; }
66+
const std::vector<std::optional<lanelet::ConstLineString3d>> & yield_stoplines() const
6267
{
63-
return attention_non_preceding_;
68+
return yield_stoplines_;
6469
}
6570
const std::vector<lanelet::CompoundPolygon3d> & attention_area() const
6671
{
6772
return is_prioritized_ ? attention_non_preceding_area_ : attention_area_;
6873
}
74+
const std::optional<lanelet::CompoundPolygon3d> & first_attention_area() const
75+
{
76+
return first_attention_area_;
77+
}
6978
const std::vector<lanelet::CompoundPolygon3d> & conflicting_area() const
7079
{
7180
return conflicting_area_;
@@ -75,6 +84,7 @@ struct IntersectionLanelets
7584
{
7685
return occlusion_attention_area_;
7786
}
87+
const std::vector<lanelet::CompoundPolygon3d> & yield_area() const { return yield_area_; }
7888
const std::optional<lanelet::ConstLanelet> & first_conflicting_lane() const
7989
{
8090
return first_conflicting_lane_;
@@ -87,10 +97,6 @@ struct IntersectionLanelets
8797
{
8898
return first_attention_lane_;
8999
}
90-
const std::optional<lanelet::CompoundPolygon3d> & first_attention_area() const
91-
{
92-
return first_attention_area_;
93-
}
94100
const std::optional<lanelet::ConstLanelet> & second_attention_lane() const
95101
{
96102
return second_attention_lane_;
@@ -103,48 +109,55 @@ struct IntersectionLanelets
103109
/**
104110
* the set of attention lanelets which is topologically merged
105111
*/
106-
lanelet::ConstLanelets attention_;
107-
std::vector<lanelet::CompoundPolygon3d> attention_area_;
112+
lanelet::ConstLanelets attention_{};
113+
std::vector<lanelet::CompoundPolygon3d> attention_area_{};
108114

109115
/**
110116
* the stop lines for each attention_lanelets associated with traffic lights. At intersection
111117
* without traffic lights, each value is null
112118
*/
113-
std::vector<std::optional<lanelet::ConstLineString3d>> attention_stoplines_;
119+
std::vector<std::optional<lanelet::ConstLineString3d>> attention_stoplines_{};
114120

115121
/**
116122
* the conflicting part of attention lanelets
117123
*/
118-
lanelet::ConstLanelets attention_non_preceding_;
119-
std::vector<lanelet::CompoundPolygon3d> attention_non_preceding_area_;
124+
lanelet::ConstLanelets attention_non_preceding_{};
125+
std::vector<lanelet::CompoundPolygon3d> attention_non_preceding_area_{};
120126

121127
/**
122128
* the stop lines for each attention_non_preceding_
123129
*/
124-
std::vector<std::optional<lanelet::ConstLineString3d>> attention_non_preceding_stoplines_;
130+
std::vector<std::optional<lanelet::ConstLineString3d>> attention_non_preceding_stoplines_{};
125131

126132
/**
127133
* the conflicting lanelets of the objective intersection lanelet
128134
*/
129-
lanelet::ConstLanelets conflicting_;
130-
std::vector<lanelet::CompoundPolygon3d> conflicting_area_;
135+
lanelet::ConstLanelets conflicting_{};
136+
std::vector<lanelet::CompoundPolygon3d> conflicting_area_{};
131137

132138
/**
133139
*
134140
*/
135-
lanelet::ConstLanelets adjacent_;
136-
std::vector<lanelet::CompoundPolygon3d> adjacent_area_;
141+
lanelet::ConstLanelets adjacent_{};
142+
std::vector<lanelet::CompoundPolygon3d> adjacent_area_{};
137143

138144
/**
139145
* the set of attention lanelets for occlusion detection which is topologically merged
140146
*/
141-
lanelet::ConstLanelets occlusion_attention_;
142-
std::vector<lanelet::CompoundPolygon3d> occlusion_attention_area_;
147+
lanelet::ConstLanelets occlusion_attention_{};
148+
std::vector<lanelet::CompoundPolygon3d> occlusion_attention_area_{};
149+
150+
/**
151+
* the set of lanelets that the objective intersection lanelet has RightOfWay over
152+
*/
153+
lanelet::ConstLanelets yield_{};
154+
std::vector<std::optional<lanelet::ConstLineString3d>> yield_stoplines_{};
155+
std::vector<lanelet::CompoundPolygon3d> yield_area_{};
143156

144157
/**
145158
* the vector of sum of each occlusion_attention lanelet
146159
*/
147-
std::vector<double> occlusion_attention_size_;
160+
std::vector<double> occlusion_attention_size_{};
148161

149162
/**
150163
* the first conflicting lanelet which ego path points intersect for the first time

planning/behavior_velocity_intersection_module/src/scene_intersection.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class IntersectionModule : public SceneModuleInterface
224224
std::optional<lanelet::CompoundPolygon3d> ego_lane{std::nullopt};
225225
std::optional<geometry_msgs::msg::Polygon> stuck_vehicle_detect_area{std::nullopt};
226226
std::optional<std::vector<lanelet::CompoundPolygon3d>> yield_stuck_detect_area{std::nullopt};
227+
std::optional<std::vector<lanelet::CompoundPolygon3d>> yield_area{std::nullopt};
227228

228229
std::optional<geometry_msgs::msg::Polygon> candidate_collision_ego_lane_polygon{std::nullopt};
229230
autoware_auto_perception_msgs::msg::PredictedObjects safe_under_traffic_control_targets;
@@ -558,10 +559,7 @@ class IntersectionModule : public SceneModuleInterface
558559
/**
559560
* @brief generate IntersectionLanelets
560561
*/
561-
intersection::IntersectionLanelets generateObjectiveLanelets(
562-
lanelet::LaneletMapConstPtr lanelet_map_ptr,
563-
lanelet::routing::RoutingGraphPtr routing_graph_ptr,
564-
const lanelet::ConstLanelet assigned_lanelet) const;
562+
intersection::IntersectionLanelets generateObjectiveLanelets() const;
565563

566564
/**
567565
* @brief generate PathLanelets

planning/behavior_velocity_intersection_module/src/scene_intersection_prepare_data.cpp

+51-16
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,15 @@ IntersectionModule::prepareIntersectionData(const bool is_prioritized, PathWithL
190190
}
191191

192192
if (!intersection_lanelets_) {
193-
intersection_lanelets_ =
194-
generateObjectiveLanelets(lanelet_map_ptr, routing_graph_ptr, assigned_lanelet);
193+
intersection_lanelets_ = generateObjectiveLanelets();
195194
}
196195
auto & intersection_lanelets = intersection_lanelets_.value();
197196
debug_data_.attention_area = intersection_lanelets.attention_area();
198197
debug_data_.first_attention_area = intersection_lanelets.first_attention_area();
199198
debug_data_.second_attention_area = intersection_lanelets.second_attention_area();
200199
debug_data_.occlusion_attention_area = intersection_lanelets.occlusion_attention_area();
201200
debug_data_.adjacent_area = intersection_lanelets.adjacent_area();
201+
debug_data_.yield_area = intersection_lanelets.yield_area();
202202

203203
// ==========================================================================================
204204
// at the very first time of registration of this module, the path may not be conflicting with
@@ -573,25 +573,18 @@ IntersectionModule::generateIntersectionStopLines(
573573
return intersection_stoplines;
574574
}
575575

576-
intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets(
577-
lanelet::LaneletMapConstPtr lanelet_map_ptr, lanelet::routing::RoutingGraphPtr routing_graph_ptr,
578-
const lanelet::ConstLanelet assigned_lanelet) const
576+
intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets() const
579577
{
578+
const auto lanelet_map_ptr = planner_data_->route_handler_->getLaneletMapPtr();
579+
const auto routing_graph_ptr = planner_data_->route_handler_->getRoutingGraphPtr();
580+
const auto & assigned_lanelet = lanelet_map_ptr->laneletLayer.get(lane_id_);
581+
580582
const double detection_area_length = planner_param_.common.attention_area_length;
581583
const double occlusion_detection_area_length =
582584
planner_param_.occlusion.occlusion_attention_area_length;
583585
const bool consider_wrong_direction_vehicle =
584586
planner_param_.collision_detection.consider_wrong_direction_vehicle;
585587

586-
// retrieve a stopline associated with a traffic light
587-
bool has_traffic_light = false;
588-
if (const auto tl_reg_elems = assigned_lanelet.regulatoryElementsAs<lanelet::TrafficLight>();
589-
tl_reg_elems.size() != 0) {
590-
const auto tl_reg_elem = tl_reg_elems.front();
591-
const auto stopline_opt = tl_reg_elem->stopLine();
592-
if (!!stopline_opt) has_traffic_light = true;
593-
}
594-
595588
// for low priority lane
596589
// if ego_lane has right of way (i.e. is high priority),
597590
// ignore yieldLanelets (i.e. low priority lanes)
@@ -644,7 +637,7 @@ intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets
644637
}
645638

646639
// exclude yield lanelets and ego lanelets from detection_lanelets
647-
if (turn_direction_ == std::string("straight") && has_traffic_light) {
640+
if (turn_direction_ == std::string("straight") && has_traffic_light_) {
648641
// if assigned lanelet is "straight" with traffic light, detection area is not necessary
649642
} else {
650643
if (consider_wrong_direction_vehicle) {
@@ -724,6 +717,15 @@ intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets
724717
auto [attention_lanelets, original_attention_lanelet_sequences] =
725718
util::mergeLaneletsByTopologicalSort(detection_and_preceding_lanelets, routing_graph_ptr);
726719

720+
const auto adjacents = planning_utils::getConstLaneletsFromIds(lanelet_map_ptr, associative_ids_);
721+
// yield
722+
lanelet::ConstLanelets yield{};
723+
for (const auto & conflicting : conflicting_ex_ego_lanelets) {
724+
if (!lanelet::utils::contains(adjacents, conflicting)) {
725+
yield.push_back(conflicting);
726+
}
727+
}
728+
727729
intersection::IntersectionLanelets result;
728730
result.attention_ = std::move(attention_lanelets);
729731
for (const auto & original_attention_lanelet_seq : original_attention_lanelet_sequences) {
@@ -743,6 +745,7 @@ intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets
743745
}
744746
result.attention_stoplines_.push_back(stopline);
745747
}
748+
746749
result.attention_non_preceding_ = std::move(detection_lanelets);
747750
for (unsigned i = 0; i < result.attention_non_preceding_.size(); ++i) {
748751
std::optional<lanelet::ConstLineString3d> stopline = std::nullopt;
@@ -752,11 +755,42 @@ intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets
752755
const auto stopline_opt = traffic_light->stopLine();
753756
if (!stopline_opt) continue;
754757
stopline = stopline_opt.get();
758+
break;
755759
}
756760
result.attention_non_preceding_stoplines_.push_back(stopline);
757761
}
762+
763+
result.yield_ = std::move(yield);
764+
for (unsigned i = 0; i < result.yield_.size(); ++i) {
765+
std::optional<lanelet::ConstLineString3d> stopline = std::nullopt;
766+
const auto & ll = result.yield_.at(i);
767+
// ==========================================================================================
768+
// NOTE: for yield_lanes we should prioritize road_marking stopline over traffic light stopline
769+
// ==========================================================================================
770+
const auto traffic_lights = ll.regulatoryElementsAs<lanelet::TrafficLight>();
771+
for (const auto & traffic_light : traffic_lights) {
772+
const auto stopline_opt = traffic_light->stopLine();
773+
if (!stopline_opt) continue;
774+
stopline = stopline_opt.get();
775+
break;
776+
}
777+
const auto road_markings = ll.regulatoryElementsAs<lanelet::autoware::RoadMarking>();
778+
for (const auto & road_marking : road_markings) {
779+
const std::string type =
780+
road_marking->roadMarking().attributeOr(lanelet::AttributeName::Type, "none");
781+
if (type == lanelet::AttributeValueString::StopLine) {
782+
stopline = road_marking->roadMarking();
783+
break;
784+
}
785+
}
786+
if (stopline)
787+
RCLCPP_INFO(
788+
logger_, "for yield lane %ld, stopline id is %ld", ll.id(), stopline.value().id());
789+
result.yield_stoplines_.push_back(stopline);
790+
}
791+
758792
result.conflicting_ = std::move(conflicting_ex_ego_lanelets);
759-
result.adjacent_ = planning_utils::getConstLaneletsFromIds(lanelet_map_ptr, associative_ids_);
793+
result.adjacent_ = adjacents;
760794
// NOTE: occlusion_attention is not inverted here
761795
// TODO(Mamoru Sobue): apply mergeLaneletsByTopologicalSort for occlusion lanelets as well and
762796
// then trim part of them based on curvature threshold
@@ -771,6 +805,7 @@ intersection::IntersectionLanelets IntersectionModule::generateObjectiveLanelets
771805
result.conflicting_area_ = util::getPolygon3dFromLanelets(result.conflicting_);
772806
result.adjacent_area_ = util::getPolygon3dFromLanelets(result.adjacent_);
773807
result.occlusion_attention_area_ = util::getPolygon3dFromLanelets(result.occlusion_attention_);
808+
result.yield_area_ = util::getPolygon3dFromLanelets(result.yield_);
774809
return result;
775810
}
776811

0 commit comments

Comments
 (0)