Skip to content

Commit f514bca

Browse files
authored
feat(intersection): publish and visualize the reason for dangerous situation to blame past detection fault retrospectively (#6143)
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 5b91874 commit f514bca

20 files changed

+1928
-688
lines changed

planning/behavior_velocity_intersection_module/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
1212
src/util.cpp
1313
src/scene_intersection.cpp
1414
src/intersection_lanelets.cpp
15+
src/object_manager.cpp
16+
src/decision_result.cpp
1517
src/scene_intersection_prepare_data.cpp
1618
src/scene_intersection_stuck.cpp
1719
src/scene_intersection_occlusion.cpp

planning/behavior_velocity_intersection_module/config/intersection.param.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
object_expected_deceleration: 2.0
6060
ignore_on_red_traffic_light:
6161
object_margin_to_path: 2.0
62+
avoid_collision_by_acceleration:
63+
object_time_margin_to_collision_point: 4.0
6264

6365
occlusion:
6466
enable: false

planning/behavior_velocity_intersection_module/package.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@
2222
<depend>autoware_auto_planning_msgs</depend>
2323
<depend>autoware_perception_msgs</depend>
2424
<depend>behavior_velocity_planner_common</depend>
25+
<depend>fmt</depend>
2526
<depend>geometry_msgs</depend>
2627
<depend>interpolation</depend>
2728
<depend>lanelet2_extension</depend>
2829
<depend>libopencv-dev</depend>
30+
<depend>magic_enum</depend>
2931
<depend>motion_utils</depend>
3032
<depend>nav_msgs</depend>
3133
<depend>pluginlib</depend>
3234
<depend>rclcpp</depend>
3335
<depend>route_handler</depend>
3436
<depend>rtc_interface</depend>
3537
<depend>tf2_geometry_msgs</depend>
36-
<depend>tier4_api_msgs</depend>
3738
<depend>tier4_autoware_utils</depend>
3839
<depend>tier4_planning_msgs</depend>
3940
<depend>vehicle_info_util</depend>

planning/behavior_velocity_intersection_module/src/debug.cpp

+85-37
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,21 @@
3131
#include <string>
3232
#include <vector>
3333

34-
namespace behavior_velocity_planner
35-
{
3634
namespace
3735
{
3836
using tier4_autoware_utils::appendMarkerArray;
3937
using tier4_autoware_utils::createMarkerColor;
4038
using tier4_autoware_utils::createMarkerOrientation;
4139
using tier4_autoware_utils::createMarkerScale;
4240

43-
static visualization_msgs::msg::MarkerArray createLaneletPolygonsMarkerArray(
41+
visualization_msgs::msg::MarkerArray createLaneletPolygonsMarkerArray(
4442
const std::vector<lanelet::CompoundPolygon3d> & polygons, const std::string & ns,
4543
const int64_t lane_id, const double r, const double g, const double b)
4644
{
4745
visualization_msgs::msg::MarkerArray msg;
4846

4947
int32_t i = 0;
50-
int32_t uid = planning_utils::bitShift(lane_id);
48+
int32_t uid = behavior_velocity_planner::planning_utils::bitShift(lane_id);
5149
for (const auto & polygon : polygons) {
5250
visualization_msgs::msg::Marker marker{};
5351
marker.header.frame_id = "map";
@@ -158,8 +156,59 @@ visualization_msgs::msg::MarkerArray createLineMarkerArray(
158156
return marker_point;
159157
}
160158

159+
constexpr std::tuple<float, float, float> white()
160+
{
161+
constexpr uint64_t code = 0xfdfdfd;
162+
constexpr float r = static_cast<int>(code >> 16) / 255.0;
163+
constexpr float g = static_cast<int>((code << 48) >> 56) / 255.0;
164+
constexpr float b = static_cast<int>((code << 56) >> 56) / 255.0;
165+
return {r, g, b};
166+
}
167+
168+
constexpr std::tuple<float, float, float> green()
169+
{
170+
constexpr uint64_t code = 0x5fa641;
171+
constexpr float r = static_cast<int>(code >> 16) / 255.0;
172+
constexpr float g = static_cast<int>((code << 48) >> 56) / 255.0;
173+
constexpr float b = static_cast<int>((code << 56) >> 56) / 255.0;
174+
return {r, g, b};
175+
}
176+
177+
constexpr std::tuple<float, float, float> yellow()
178+
{
179+
constexpr uint64_t code = 0xebce2b;
180+
constexpr float r = static_cast<int>(code >> 16) / 255.0;
181+
constexpr float g = static_cast<int>((code << 48) >> 56) / 255.0;
182+
constexpr float b = static_cast<int>((code << 56) >> 56) / 255.0;
183+
return {r, g, b};
184+
}
185+
186+
constexpr std::tuple<float, float, float> red()
187+
{
188+
constexpr uint64_t code = 0xba1c30;
189+
constexpr float r = static_cast<int>(code >> 16) / 255.0;
190+
constexpr float g = static_cast<int>((code << 48) >> 56) / 255.0;
191+
constexpr float b = static_cast<int>((code << 56) >> 56) / 255.0;
192+
return {r, g, b};
193+
}
194+
195+
constexpr std::tuple<float, float, float> light_blue()
196+
{
197+
constexpr uint64_t code = 0x96cde6;
198+
constexpr float r = static_cast<int>(code >> 16) / 255.0;
199+
constexpr float g = static_cast<int>((code << 48) >> 56) / 255.0;
200+
constexpr float b = static_cast<int>((code << 56) >> 56) / 255.0;
201+
return {r, g, b};
202+
}
161203
} // namespace
162204

205+
namespace behavior_velocity_planner
206+
{
207+
using tier4_autoware_utils::appendMarkerArray;
208+
using tier4_autoware_utils::createMarkerColor;
209+
using tier4_autoware_utils::createMarkerOrientation;
210+
using tier4_autoware_utils::createMarkerScale;
211+
163212
visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray()
164213
{
165214
visualization_msgs::msg::MarkerArray debug_marker_array;
@@ -168,37 +217,37 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
168217

169218
if (debug_data_.attention_area) {
170219
appendMarkerArray(
171-
createLaneletPolygonsMarkerArray(
220+
::createLaneletPolygonsMarkerArray(
172221
debug_data_.attention_area.value(), "attention_area", lane_id_, 0.0, 1.0, 0.0),
173222
&debug_marker_array);
174223
}
175224

176225
if (debug_data_.occlusion_attention_area) {
177226
appendMarkerArray(
178-
createLaneletPolygonsMarkerArray(
227+
::createLaneletPolygonsMarkerArray(
179228
debug_data_.occlusion_attention_area.value(), "occlusion_attention_area", lane_id_, 0.917,
180229
0.568, 0.596),
181230
&debug_marker_array);
182231
}
183232

184233
if (debug_data_.adjacent_area) {
185234
appendMarkerArray(
186-
createLaneletPolygonsMarkerArray(
235+
::createLaneletPolygonsMarkerArray(
187236
debug_data_.adjacent_area.value(), "adjacent_area", lane_id_, 0.913, 0.639, 0.149),
188237
&debug_marker_array);
189238
}
190239

191240
if (debug_data_.first_attention_area) {
192241
appendMarkerArray(
193-
createLaneletPolygonsMarkerArray(
242+
::createLaneletPolygonsMarkerArray(
194243
{debug_data_.first_attention_area.value()}, "first_attention_area", lane_id_, 1, 0.647,
195244
0.0),
196245
&debug_marker_array, now);
197246
}
198247

199248
if (debug_data_.second_attention_area) {
200249
appendMarkerArray(
201-
createLaneletPolygonsMarkerArray(
250+
::createLaneletPolygonsMarkerArray(
202251
{debug_data_.second_attention_area.value()}, "second_attention_area", lane_id_, 1, 0.647,
203252
0.0),
204253
&debug_marker_array, now);
@@ -214,15 +263,15 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
214263

215264
if (debug_data_.yield_stuck_detect_area) {
216265
appendMarkerArray(
217-
createLaneletPolygonsMarkerArray(
266+
::createLaneletPolygonsMarkerArray(
218267
debug_data_.yield_stuck_detect_area.value(), "yield_stuck_detect_area", lane_id_, 0.6588235,
219268
0.34509, 0.6588235),
220269
&debug_marker_array);
221270
}
222271

223272
if (debug_data_.ego_lane) {
224273
appendMarkerArray(
225-
createLaneletPolygonsMarkerArray(
274+
::createLaneletPolygonsMarkerArray(
226275
{debug_data_.ego_lane.value()}, "ego_lane", lane_id_, 1, 0.647, 0.0),
227276
&debug_marker_array, now);
228277
}
@@ -235,59 +284,58 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
235284
&debug_marker_array, now);
236285
}
237286

238-
size_t i{0};
239-
for (const auto & p : debug_data_.candidate_collision_object_polygons) {
240-
appendMarkerArray(
241-
debug::createPolygonMarkerArray(
242-
p, "candidate_collision_object_polygons", lane_id_ + i++, now, 0.3, 0.0, 0.0, 0.0, 0.5,
243-
0.5),
244-
&debug_marker_array, now);
245-
}
246-
287+
static constexpr auto white = ::white();
288+
static constexpr auto green = ::green();
289+
static constexpr auto yellow = ::yellow();
290+
static constexpr auto red = ::red();
291+
static constexpr auto light_blue = ::light_blue();
247292
appendMarkerArray(
248293
debug::createObjectsMarkerArray(
249-
debug_data_.conflicting_targets, "conflicting_targets", module_id_, now, 0.99, 0.4, 0.0),
294+
debug_data_.safe_under_traffic_control_targets, "safe_under_traffic_control_targets",
295+
module_id_, now, std::get<0>(light_blue), std::get<1>(light_blue), std::get<2>(light_blue)),
250296
&debug_marker_array, now);
251297

252298
appendMarkerArray(
253299
debug::createObjectsMarkerArray(
254-
debug_data_.amber_ignore_targets, "amber_ignore_targets", module_id_, now, 0.0, 1.0, 0.0),
300+
debug_data_.unsafe_targets, "unsafe_targets", module_id_, now, std::get<0>(green),
301+
std::get<1>(green), std::get<2>(green)),
255302
&debug_marker_array, now);
256303

257304
appendMarkerArray(
258305
debug::createObjectsMarkerArray(
259-
debug_data_.red_overshoot_ignore_targets, "red_overshoot_ignore_targets", module_id_, now,
260-
0.0, 1.0, 0.0),
306+
debug_data_.misjudge_targets, "misjudge_targets", module_id_, now, std::get<0>(yellow),
307+
std::get<1>(yellow), std::get<2>(yellow)),
261308
&debug_marker_array, now);
262309

263310
appendMarkerArray(
264311
debug::createObjectsMarkerArray(
265-
debug_data_.stuck_targets, "stuck_targets", module_id_, now, 0.99, 0.99, 0.2),
312+
debug_data_.too_late_detect_targets, "too_late_detect_targets", module_id_, now,
313+
std::get<0>(red), std::get<1>(red), std::get<2>(red)),
266314
&debug_marker_array, now);
267315

268316
appendMarkerArray(
269317
debug::createObjectsMarkerArray(
270-
debug_data_.yield_stuck_targets, "stuck_targets", module_id_, now, 0.4, 0.99, 0.2),
318+
debug_data_.parked_targets, "parked_targets", module_id_, now, std::get<0>(white),
319+
std::get<1>(white), std::get<2>(white)),
271320
&debug_marker_array, now);
272321

273322
appendMarkerArray(
274323
debug::createObjectsMarkerArray(
275-
debug_data_.blocking_attention_objects, "blocking_attention_objects", module_id_, now, 0.99,
276-
0.99, 0.6),
324+
debug_data_.stuck_targets, "stuck_targets", module_id_, now, std::get<0>(white),
325+
std::get<1>(white), std::get<2>(white)),
277326
&debug_marker_array, now);
278327

279-
/*
280328
appendMarkerArray(
281-
createPoseMarkerArray(
282-
debug_data_.predicted_obj_pose, "predicted_obj_pose", module_id_, 0.7, 0.85, 0.9),
329+
debug::createObjectsMarkerArray(
330+
debug_data_.yield_stuck_targets, "yield_stuck_targets", module_id_, now, std::get<0>(white),
331+
std::get<1>(white), std::get<2>(white)),
283332
&debug_marker_array, now);
284-
*/
285333

286334
if (debug_data_.first_pass_judge_wall_pose) {
287335
const double r = debug_data_.passed_first_pass_judge ? 1.0 : 0.0;
288336
const double g = debug_data_.passed_first_pass_judge ? 0.0 : 1.0;
289337
appendMarkerArray(
290-
createPoseMarkerArray(
338+
::createPoseMarkerArray(
291339
debug_data_.first_pass_judge_wall_pose.value(), "first_pass_judge_wall_pose", module_id_, r,
292340
g, 0.0),
293341
&debug_marker_array, now);
@@ -297,7 +345,7 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
297345
const double r = debug_data_.passed_second_pass_judge ? 1.0 : 0.0;
298346
const double g = debug_data_.passed_second_pass_judge ? 0.0 : 1.0;
299347
appendMarkerArray(
300-
createPoseMarkerArray(
348+
::createPoseMarkerArray(
301349
debug_data_.second_pass_judge_wall_pose.value(), "second_pass_judge_wall_pose", module_id_,
302350
r, g, 0.0),
303351
&debug_marker_array, now);
@@ -314,7 +362,7 @@ visualization_msgs::msg::MarkerArray IntersectionModule::createDebugMarkerArray(
314362
if (debug_data_.nearest_occlusion_projection) {
315363
const auto [point_start, point_end] = debug_data_.nearest_occlusion_projection.value();
316364
appendMarkerArray(
317-
createLineMarkerArray(
365+
::createLineMarkerArray(
318366
point_start, point_end, "nearest_occlusion_projection", lane_id_, 0.5, 0.5, 0.0),
319367
&debug_marker_array, now);
320368
}
@@ -369,11 +417,11 @@ visualization_msgs::msg::MarkerArray MergeFromPrivateRoadModule::createDebugMark
369417

370418
const auto state = state_machine_.getState();
371419

372-
int32_t uid = planning_utils::bitShift(module_id_);
420+
int32_t uid = behavior_velocity_planner::planning_utils::bitShift(module_id_);
373421
const auto now = this->clock_->now();
374422
if (state == StateMachine::State::STOP) {
375423
appendMarkerArray(
376-
createPoseMarkerArray(debug_data_.stop_point_pose, "stop_point_pose", uid, 1.0, 0.0, 0.0),
424+
::createPoseMarkerArray(debug_data_.stop_point_pose, "stop_point_pose", uid, 1.0, 0.0, 0.0),
377425
&debug_marker_array, now);
378426
}
379427

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 Tier IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "decision_result.hpp"
16+
17+
namespace behavior_velocity_planner::intersection
18+
{
19+
std::string formatDecisionResult(const DecisionResult & decision_result)
20+
{
21+
if (std::holds_alternative<InternalError>(decision_result)) {
22+
const auto state = std::get<InternalError>(decision_result);
23+
return "InternalError because " + state.error;
24+
}
25+
if (std::holds_alternative<OverPassJudge>(decision_result)) {
26+
const auto state = std::get<OverPassJudge>(decision_result);
27+
return "OverPassJudge:\nsafety_report:" + state.safety_report + "\nevasive_report:\n" +
28+
state.evasive_report;
29+
}
30+
if (std::holds_alternative<StuckStop>(decision_result)) {
31+
return "StuckStop";
32+
}
33+
if (std::holds_alternative<YieldStuckStop>(decision_result)) {
34+
const auto state = std::get<YieldStuckStop>(decision_result);
35+
return "YieldStuckStop:\nsafety_report:" + state.safety_report;
36+
}
37+
if (std::holds_alternative<NonOccludedCollisionStop>(decision_result)) {
38+
const auto state = std::get<NonOccludedCollisionStop>(decision_result);
39+
return "NonOccludedCollisionStop\nsafety_report:" + state.safety_report;
40+
}
41+
if (std::holds_alternative<FirstWaitBeforeOcclusion>(decision_result)) {
42+
return "FirstWaitBeforeOcclusion";
43+
}
44+
if (std::holds_alternative<PeekingTowardOcclusion>(decision_result)) {
45+
return "PeekingTowardOcclusion";
46+
}
47+
if (std::holds_alternative<OccludedCollisionStop>(decision_result)) {
48+
const auto state = std::get<OccludedCollisionStop>(decision_result);
49+
return "OccludedCollisionStop\nsafety_report:" + state.safety_report;
50+
}
51+
if (std::holds_alternative<OccludedAbsenceTrafficLight>(decision_result)) {
52+
const auto state = std::get<OccludedAbsenceTrafficLight>(decision_result);
53+
return "OccludedAbsenceTrafficLight\nsafety_report:" + state.safety_report;
54+
}
55+
if (std::holds_alternative<Safe>(decision_result)) {
56+
return "Safe";
57+
}
58+
if (std::holds_alternative<FullyPrioritized>(decision_result)) {
59+
const auto state = std::get<FullyPrioritized>(decision_result);
60+
return "FullyPrioritized\nsafety_report:" + state.safety_report;
61+
}
62+
return "";
63+
}
64+
65+
} // namespace behavior_velocity_planner::intersection

0 commit comments

Comments
 (0)