forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathscene_intersection.cpp
3441 lines (3219 loc) · 152 KB
/
scene_intersection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2020 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "scene_intersection.hpp"
#include "util.hpp"
#include <behavior_velocity_planner_common/utilization/boost_geometry_helper.hpp>
#include <behavior_velocity_planner_common/utilization/trajectory_utils.hpp>
#include <behavior_velocity_planner_common/utilization/util.hpp>
#include <interpolation/spline_interpolation_points_2d.hpp>
#include <lanelet2_extension/regulatory_elements/road_marking.hpp>
#include <lanelet2_extension/utility/query.hpp>
#include <lanelet2_extension/utility/utilities.hpp>
#include <motion_utils/trajectory/trajectory.hpp>
#include <opencv2/imgproc.hpp>
#include <tier4_autoware_utils/geometry/boost_polygon_utils.hpp>
#include <tier4_autoware_utils/geometry/geometry.hpp>
#include <tier4_autoware_utils/ros/uuid_helper.hpp>
#include <boost/geometry/algorithms/convex_hull.hpp>
#include <boost/geometry/algorithms/correct.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <lanelet2_core/geometry/LineString.h>
#include <lanelet2_core/geometry/Point.h>
#include <lanelet2_core/geometry/Polygon.h>
#include <lanelet2_core/primitives/BasicRegulatoryElements.h>
#include <lanelet2_core/primitives/LineString.h>
#include <algorithm>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <tuple>
#include <vector>
namespace tier4_autoware_utils
{
template <>
inline geometry_msgs::msg::Point getPoint(const lanelet::ConstPoint3d & p)
{
geometry_msgs::msg::Point point;
point.x = p.x();
point.y = p.y();
point.z = p.z();
return point;
}
} // namespace tier4_autoware_utils
namespace behavior_velocity_planner
{
namespace bg = boost::geometry;
namespace
{
Polygon2d createOneStepPolygon(
const geometry_msgs::msg::Pose & prev_pose, const geometry_msgs::msg::Pose & next_pose,
const autoware_auto_perception_msgs::msg::Shape & shape)
{
const auto prev_poly = tier4_autoware_utils::toPolygon2d(prev_pose, shape);
const auto next_poly = tier4_autoware_utils::toPolygon2d(next_pose, shape);
Polygon2d one_step_poly;
for (const auto & point : prev_poly.outer()) {
one_step_poly.outer().push_back(point);
}
for (const auto & point : next_poly.outer()) {
one_step_poly.outer().push_back(point);
}
bg::correct(one_step_poly);
Polygon2d convex_one_step_poly;
bg::convex_hull(one_step_poly, convex_one_step_poly);
return convex_one_step_poly;
}
} // namespace
static bool isTargetStuckVehicleType(
const autoware_auto_perception_msgs::msg::PredictedObject & object)
{
if (
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::CAR ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::BUS ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::TRUCK ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::TRAILER ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::MOTORCYCLE) {
return true;
}
return false;
}
static bool isTargetCollisionVehicleType(
const autoware_auto_perception_msgs::msg::PredictedObject & object)
{
if (
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::CAR ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::BUS ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::TRUCK ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::TRAILER ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::MOTORCYCLE ||
object.classification.at(0).label ==
autoware_auto_perception_msgs::msg::ObjectClassification::BICYCLE) {
return true;
}
return false;
}
IntersectionModule::IntersectionModule(
const int64_t module_id, const int64_t lane_id,
[[maybe_unused]] std::shared_ptr<const PlannerData> planner_data,
const PlannerParam & planner_param, const std::set<lanelet::Id> & associative_ids,
const std::string & turn_direction, const bool has_traffic_light,
const bool enable_occlusion_detection, rclcpp::Node & node, const rclcpp::Logger logger,
const rclcpp::Clock::SharedPtr clock)
: SceneModuleInterface(module_id, logger, clock),
node_(node),
lane_id_(lane_id),
associative_ids_(associative_ids),
turn_direction_(turn_direction),
has_traffic_light_(has_traffic_light),
enable_occlusion_detection_(enable_occlusion_detection),
occlusion_attention_divisions_(std::nullopt),
occlusion_uuid_(tier4_autoware_utils::generateUUID())
{
velocity_factor_.init(PlanningBehavior::INTERSECTION);
planner_param_ = planner_param;
{
collision_state_machine_.setMarginTime(
planner_param_.collision_detection.collision_detection_hold_time);
}
{
before_creep_state_machine_.setMarginTime(
planner_param_.occlusion.temporal_stop_time_before_peeking);
before_creep_state_machine_.setState(StateMachine::State::STOP);
}
{
occlusion_stop_state_machine_.setMarginTime(
planner_param_.occlusion.occlusion_detection_hold_time);
occlusion_stop_state_machine_.setState(StateMachine::State::GO);
}
{
temporal_stop_before_attention_state_machine_.setMarginTime(
planner_param_.occlusion.occlusion_detection_hold_time);
temporal_stop_before_attention_state_machine_.setState(StateMachine::State::STOP);
}
{
static_occlusion_timeout_state_machine_.setMarginTime(
planner_param_.occlusion.static_occlusion_with_traffic_light_timeout);
static_occlusion_timeout_state_machine_.setState(StateMachine::State::STOP);
}
decision_state_pub_ =
node_.create_publisher<std_msgs::msg::String>("~/debug/intersection/decision_state", 1);
ego_ttc_pub_ = node_.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
"~/debug/intersection/ego_ttc", 1);
object_ttc_pub_ = node_.create_publisher<tier4_debug_msgs::msg::Float64MultiArrayStamped>(
"~/debug/intersection/object_ttc", 1);
}
void IntersectionModule::initializeRTCStatus()
{
setSafe(true);
setDistance(std::numeric_limits<double>::lowest());
// occlusion
occlusion_safety_ = true;
occlusion_stop_distance_ = std::numeric_limits<double>::lowest();
occlusion_first_stop_required_ = false;
// activated_ and occlusion_activated_ must be set from manager's RTC callback
}
// template-specification based visitor pattern
// https://en.cppreference.com/w/cpp/utility/variant/visit
template <class... Ts>
struct VisitorSwitch : Ts...
{
using Ts::operator()...;
};
template <class... Ts>
VisitorSwitch(Ts...) -> VisitorSwitch<Ts...>;
template <typename T>
void prepareRTCByDecisionResult(
const T & result, const autoware_auto_planning_msgs::msg::PathWithLaneId & path,
bool * default_safety, double * default_distance, bool * occlusion_safety,
double * occlusion_distance)
{
static_assert("Unsupported type passed to prepareRTCByDecisionResult");
return;
}
template <>
void prepareRTCByDecisionResult(
[[maybe_unused]] const IntersectionModule::Indecisive & result,
[[maybe_unused]] const autoware_auto_planning_msgs::msg::PathWithLaneId & path,
[[maybe_unused]] bool * default_safety, [[maybe_unused]] double * default_distance,
[[maybe_unused]] bool * occlusion_safety, [[maybe_unused]] double * occlusion_distance)
{
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::StuckStop & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "StuckStop");
const auto closest_idx = result.closest_idx;
const auto stopline_idx = result.stuck_stopline_idx;
*default_safety = false;
*default_distance = motion_utils::calcSignedArcLength(path.points, closest_idx, stopline_idx);
*occlusion_safety = true;
if (result.occlusion_stopline_idx) {
const auto occlusion_stopline_idx = result.occlusion_stopline_idx.value();
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
}
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::YieldStuckStop & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, [[maybe_unused]] double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "YieldStuckStop");
const auto closest_idx = result.closest_idx;
const auto stopline_idx = result.stuck_stopline_idx;
*default_safety = false;
*default_distance = motion_utils::calcSignedArcLength(path.points, closest_idx, stopline_idx);
*occlusion_safety = true;
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::NonOccludedCollisionStop & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "NonOccludedCollisionStop");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.collision_stopline_idx;
*default_safety = false;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
const auto occlusion_stopline = result.occlusion_stopline_idx;
*occlusion_safety = true;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline);
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::FirstWaitBeforeOcclusion & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "FirstWaitBeforeOcclusion");
const auto closest_idx = result.closest_idx;
const auto first_stopline_idx = result.first_stopline_idx;
const auto occlusion_stopline_idx = result.occlusion_stopline_idx;
*default_safety = false;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, first_stopline_idx);
*occlusion_safety = result.is_actually_occlusion_cleared;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::PeekingTowardOcclusion & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "PeekingTowardOcclusion");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.collision_stopline_idx;
const auto occlusion_stopline_idx = result.occlusion_stopline_idx;
*default_safety = true;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
*occlusion_safety = result.is_actually_occlusion_cleared;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::OccludedAbsenceTrafficLight & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "OccludedAbsenceTrafficLight");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.closest_idx;
*default_safety = !result.collision_detected;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
*occlusion_safety = result.is_actually_occlusion_cleared;
*occlusion_distance = 0;
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::OccludedCollisionStop & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "OccludedCollisionStop");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.collision_stopline_idx;
const auto occlusion_stopline_idx = result.occlusion_stopline_idx;
*default_safety = false;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
*occlusion_safety = result.is_actually_occlusion_cleared;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::Safe & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "Safe");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.collision_stopline_idx;
const auto occlusion_stopline_idx = result.occlusion_stopline_idx;
*default_safety = true;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
*occlusion_safety = true;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
return;
}
template <>
void prepareRTCByDecisionResult(
const IntersectionModule::FullyPrioritized & result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, bool * default_safety,
double * default_distance, bool * occlusion_safety, double * occlusion_distance)
{
RCLCPP_DEBUG(rclcpp::get_logger("prepareRTCByDecisionResult"), "FullyPrioritized");
const auto closest_idx = result.closest_idx;
const auto collision_stopline_idx = result.collision_stopline_idx;
const auto occlusion_stopline_idx = result.occlusion_stopline_idx;
*default_safety = !result.collision_detected;
*default_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, collision_stopline_idx);
*occlusion_safety = true;
*occlusion_distance =
motion_utils::calcSignedArcLength(path.points, closest_idx, occlusion_stopline_idx);
return;
}
void IntersectionModule::prepareRTCStatus(
const DecisionResult & decision_result,
const autoware_auto_planning_msgs::msg::PathWithLaneId & path)
{
bool default_safety = true;
double default_distance = std::numeric_limits<double>::lowest();
std::visit(
VisitorSwitch{[&](const auto & decision) {
prepareRTCByDecisionResult(
decision, path, &default_safety, &default_distance, &occlusion_safety_,
&occlusion_stop_distance_);
}},
decision_result);
setSafe(default_safety);
setDistance(default_distance);
occlusion_first_stop_required_ =
std::holds_alternative<IntersectionModule::FirstWaitBeforeOcclusion>(decision_result);
}
template <typename T>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved, const T & decision_result,
const IntersectionModule::PlannerParam & planner_param, const double baselink2front,
autoware_auto_planning_msgs::msg::PathWithLaneId * path, StopReason * stop_reason,
VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
static_assert("Unsupported type passed to reactRTCByDecisionResult");
return;
}
template <>
void reactRTCApprovalByDecisionResult(
[[maybe_unused]] const bool rtc_default_approved,
[[maybe_unused]] const bool rtc_occlusion_approved,
[[maybe_unused]] const IntersectionModule::Indecisive & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
[[maybe_unused]] const double baselink2front,
[[maybe_unused]] autoware_auto_planning_msgs::msg::PathWithLaneId * path,
[[maybe_unused]] StopReason * stop_reason,
[[maybe_unused]] VelocityFactorInterface * velocity_factor,
[[maybe_unused]] DebugData * debug_data)
{
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::StuckStop & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"StuckStop, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
const auto closest_idx = decision_result.closest_idx;
if (!rtc_default_approved) {
// use default_rtc uuid for stuck vehicle detection
const auto stopline_idx = decision_result.stuck_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
stop_factor.stop_factor_points = planning_utils::toRosPoints(debug_data->conflicting_targets);
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (
!rtc_occlusion_approved && decision_result.occlusion_stopline_idx &&
planner_param.occlusion.enable) {
const auto occlusion_stopline_idx = decision_result.occlusion_stopline_idx.value();
planning_utils::setVelocityFromIndex(occlusion_stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(occlusion_stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(occlusion_stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(closest_idx).point.pose,
path->points.at(occlusion_stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::YieldStuckStop & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"YieldStuckStop, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
const auto closest_idx = decision_result.closest_idx;
if (!rtc_default_approved) {
// use default_rtc uuid for stuck vehicle detection
const auto stopline_idx = decision_result.stuck_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
stop_factor.stop_factor_points = planning_utils::toRosPoints(debug_data->conflicting_targets);
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::NonOccludedCollisionStop & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"NonOccludedCollisionStop, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.collision_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
const auto stopline_idx = decision_result.occlusion_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::FirstWaitBeforeOcclusion & decision_result,
const IntersectionModule::PlannerParam & planner_param, const double baselink2front,
autoware_auto_planning_msgs::msg::PathWithLaneId * path, StopReason * stop_reason,
VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"FirstWaitBeforeOcclusion, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.first_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_first_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
if (planner_param.occlusion.creep_during_peeking.enable) {
const size_t occlusion_peeking_stopline = decision_result.occlusion_stopline_idx;
const size_t closest_idx = decision_result.closest_idx;
for (size_t i = closest_idx; i < occlusion_peeking_stopline; i++) {
planning_utils::setVelocityFromIndex(
i, planner_param.occlusion.creep_during_peeking.creep_velocity, path);
}
}
const auto stopline_idx = decision_result.occlusion_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::PeekingTowardOcclusion & decision_result,
const IntersectionModule::PlannerParam & planner_param, const double baselink2front,
autoware_auto_planning_msgs::msg::PathWithLaneId * path, StopReason * stop_reason,
VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"PeekingTowardOcclusion, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
// NOTE: creep_velocity should be inserted first at closest_idx if !rtc_default_approved
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
const size_t occlusion_peeking_stopline =
decision_result.temporal_stop_before_attention_required
? decision_result.first_attention_stopline_idx
: decision_result.occlusion_stopline_idx;
if (planner_param.occlusion.creep_during_peeking.enable) {
const size_t closest_idx = decision_result.closest_idx;
for (size_t i = closest_idx; i < occlusion_peeking_stopline; i++) {
planning_utils::setVelocityFromIndex(
i, planner_param.occlusion.creep_during_peeking.creep_velocity, path);
}
}
planning_utils::setVelocityFromIndex(occlusion_peeking_stopline, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(occlusion_peeking_stopline, baselink2front, *path);
debug_data->static_occlusion_with_traffic_light_timeout =
decision_result.static_occlusion_timeout;
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(occlusion_peeking_stopline).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(occlusion_peeking_stopline).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.collision_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::OccludedCollisionStop & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"OccludedCollisionStop, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.collision_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
const auto stopline_idx = decision_result.temporal_stop_before_attention_required
? decision_result.first_attention_stopline_idx
: decision_result.occlusion_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
debug_data->static_occlusion_with_traffic_light_timeout =
decision_result.static_occlusion_timeout;
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::OccludedAbsenceTrafficLight & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"OccludedAbsenceTrafficLight, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.closest_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && decision_result.temporal_stop_before_attention_required) {
const auto stopline_idx = decision_result.first_attention_area_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && !decision_result.temporal_stop_before_attention_required) {
const auto closest_idx = decision_result.closest_idx;
const auto peeking_limit_line = decision_result.peeking_limit_line_idx;
for (auto i = closest_idx; i <= peeking_limit_line; ++i) {
planning_utils::setVelocityFromIndex(
i, planner_param.occlusion.creep_velocity_without_traffic_light, path);
}
debug_data->absence_traffic_light_creep_wall =
planning_utils::getAheadPose(closest_idx, baselink2front, *path);
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::Safe & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"Safe, approval = (default: %d, occlusion: %d)", rtc_default_approved, rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.collision_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
const auto stopline_idx = decision_result.occlusion_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
template <>
void reactRTCApprovalByDecisionResult(
const bool rtc_default_approved, const bool rtc_occlusion_approved,
const IntersectionModule::FullyPrioritized & decision_result,
[[maybe_unused]] const IntersectionModule::PlannerParam & planner_param,
const double baselink2front, autoware_auto_planning_msgs::msg::PathWithLaneId * path,
StopReason * stop_reason, VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
RCLCPP_DEBUG(
rclcpp::get_logger("reactRTCApprovalByDecisionResult"),
"FullyPrioritized, approval = (default: %d, occlusion: %d)", rtc_default_approved,
rtc_occlusion_approved);
if (!rtc_default_approved) {
const auto stopline_idx = decision_result.collision_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->collision_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
if (!rtc_occlusion_approved && planner_param.occlusion.enable) {
const auto stopline_idx = decision_result.occlusion_stopline_idx;
planning_utils::setVelocityFromIndex(stopline_idx, 0.0, path);
debug_data->occlusion_stop_wall_pose =
planning_utils::getAheadPose(stopline_idx, baselink2front, *path);
{
tier4_planning_msgs::msg::StopFactor stop_factor;
stop_factor.stop_pose = path->points.at(stopline_idx).point.pose;
planning_utils::appendStopReason(stop_factor, stop_reason);
velocity_factor->set(
path->points, path->points.at(decision_result.closest_idx).point.pose,
path->points.at(stopline_idx).point.pose, VelocityFactor::UNKNOWN);
}
}
return;
}
void reactRTCApproval(
const bool rtc_default_approval, const bool rtc_occlusion_approval,
const IntersectionModule::DecisionResult & decision_result,
const IntersectionModule::PlannerParam & planner_param, const double baselink2front,
autoware_auto_planning_msgs::msg::PathWithLaneId * path, StopReason * stop_reason,
VelocityFactorInterface * velocity_factor, DebugData * debug_data)
{
std::visit(
VisitorSwitch{[&](const auto & decision) {
reactRTCApprovalByDecisionResult(
rtc_default_approval, rtc_occlusion_approval, decision, planner_param, baselink2front, path,
stop_reason, velocity_factor, debug_data);
}},
decision_result);
return;
}
static std::string formatDecisionResult(const IntersectionModule::DecisionResult & decision_result)
{
if (std::holds_alternative<IntersectionModule::Indecisive>(decision_result)) {
const auto indecisive = std::get<IntersectionModule::Indecisive>(decision_result);
return "Indecisive because " + indecisive.error;
}
if (std::holds_alternative<IntersectionModule::Safe>(decision_result)) {
return "Safe";
}
if (std::holds_alternative<IntersectionModule::StuckStop>(decision_result)) {
return "StuckStop";
}
if (std::holds_alternative<IntersectionModule::YieldStuckStop>(decision_result)) {
return "YieldStuckStop";
}
if (std::holds_alternative<IntersectionModule::NonOccludedCollisionStop>(decision_result)) {
return "NonOccludedCollisionStop";
}
if (std::holds_alternative<IntersectionModule::FirstWaitBeforeOcclusion>(decision_result)) {
return "FirstWaitBeforeOcclusion";
}
if (std::holds_alternative<IntersectionModule::PeekingTowardOcclusion>(decision_result)) {
return "PeekingTowardOcclusion";
}
if (std::holds_alternative<IntersectionModule::OccludedCollisionStop>(decision_result)) {
return "OccludedCollisionStop";
}
if (std::holds_alternative<IntersectionModule::OccludedAbsenceTrafficLight>(decision_result)) {
return "OccludedAbsenceTrafficLight";
}
if (std::holds_alternative<IntersectionModule::FullyPrioritized>(decision_result)) {
return "FullyPrioritized";
}
return "";
}
bool IntersectionModule::modifyPathVelocity(PathWithLaneId * path, StopReason * stop_reason)
{
debug_data_ = DebugData();
*stop_reason = planning_utils::initializeStopReason(StopReason::INTERSECTION);
// set default RTC
initializeRTCStatus();
// calculate the
const auto decision_result = modifyPathVelocityDetail(path, stop_reason);
prev_decision_result_ = decision_result;
const std::string decision_type =
"intersection" + std::to_string(module_id_) + " : " + formatDecisionResult(decision_result);
std_msgs::msg::String decision_result_msg;
decision_result_msg.data = decision_type;
decision_state_pub_->publish(decision_result_msg);
prepareRTCStatus(decision_result, *path);
const double baselink2front = planner_data_->vehicle_info_.max_longitudinal_offset_m;
reactRTCApproval(
activated_, occlusion_activated_, decision_result, planner_param_, baselink2front, path,
stop_reason, &velocity_factor_, &debug_data_);
if (!activated_ || !occlusion_activated_) {
is_go_out_ = false;
} else {
is_go_out_ = true;
}
RCLCPP_DEBUG(logger_, "===== plan end =====");
return true;
}
bool IntersectionModule::isGreenSolidOn(lanelet::ConstLanelet lane)
{
using TrafficSignalElement = autoware_perception_msgs::msg::TrafficSignalElement;
std::optional<lanelet::Id> tl_id = std::nullopt;
for (auto && tl_reg_elem : lane.regulatoryElementsAs<lanelet::TrafficLight>()) {
tl_id = tl_reg_elem->id();
break;
}
if (!tl_id) {
// this lane has no traffic light
return false;
}
const auto tl_info_opt = planner_data_->getTrafficSignal(
tl_id.value(), true /* traffic light module keeps last observation*/);
if (!tl_info_opt) {
// the info of this traffic light is not available
return false;
}
const auto & tl_info = tl_info_opt.value();
for (auto && tl_light : tl_info.signal.elements) {
if (
tl_light.color == TrafficSignalElement::GREEN &&
tl_light.shape == TrafficSignalElement::CIRCLE) {
return true;
}
}
return false;
}
IntersectionModule::DecisionResult IntersectionModule::modifyPathVelocityDetail(
PathWithLaneId * path, [[maybe_unused]] StopReason * stop_reason)
{
const auto lanelet_map_ptr = planner_data_->route_handler_->getLaneletMapPtr();
const auto routing_graph_ptr = planner_data_->route_handler_->getRoutingGraphPtr();
const auto & assigned_lanelet = lanelet_map_ptr->laneletLayer.get(lane_id_);
const std::string turn_direction = assigned_lanelet.attributeOr("turn_direction", "else");
const double baselink2front = planner_data_->vehicle_info_.max_longitudinal_offset_m;
const auto footprint = planner_data_->vehicle_info_.createFootprint(0.0, 0.0);
const auto & current_pose = planner_data_->current_odometry->pose;
// spline interpolation
const auto interpolated_path_info_opt = util::generateInterpolatedPath(
lane_id_, associative_ids_, *path, planner_param_.common.path_interpolation_ds, logger_);
if (!interpolated_path_info_opt) {
return IntersectionModule::Indecisive{"splineInterpolate failed"};
}
const auto & interpolated_path_info = interpolated_path_info_opt.value();
if (!interpolated_path_info.lane_id_interval) {
return IntersectionModule::Indecisive{
"Path has no interval on intersection lane " + std::to_string(lane_id_)};
}
// cache intersection lane information because it is invariant
const auto lanelets_on_path =
planning_utils::getLaneletsOnPath(*path, lanelet_map_ptr, current_pose);
if (!intersection_lanelets_) {
intersection_lanelets_ =