Skip to content

Commit 859776d

Browse files
authored
feat(intersection): resurrect debug ego-object ttc visualizer (autowarefoundation#6829)
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 51efa6d commit 859776d

File tree

5 files changed

+112
-280
lines changed

5 files changed

+112
-280
lines changed

.cspell.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2-
"ignorePaths": ["perception/bytetrack/lib/**"],
2+
"ignorePaths": [
3+
"perception/bytetrack/lib/**",
4+
"planning/behavior_velocity_intersection_module/scripts/**"
5+
],
36
"ignoreRegExpList": [],
4-
"words": ["dltype", "tvmgen"]
7+
"words": ["dltype", "tvmgen", "fromarray"]
58
}

planning/behavior_velocity_intersection_module/scripts/ttc.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from threading import Lock
2222
import time
2323

24+
from PIL import Image
2425
import imageio
2526
import matplotlib
2627
import matplotlib.pyplot as plt
@@ -218,7 +219,19 @@ def plot_world(self):
218219
def cleanup(self):
219220
if self.args.save:
220221
kwargs_write = {"fps": self.args.fps, "quantizer": "nq"}
221-
imageio.mimsave("./" + self.args.gif + ".gif", self.images, **kwargs_write)
222+
max_size_total = 0
223+
max_size = None
224+
for image in self.images:
225+
(w, h) = image.size
226+
if w * h > max_size_total:
227+
max_size = image.size
228+
max_size_total = w * h
229+
reshaped = []
230+
for image in self.images:
231+
reshaped.append(image.resize(max_size))
232+
233+
imageio.mimsave("./" + self.args.gif + ".gif", reshaped, **kwargs_write)
234+
print("saved fig")
222235
rclpy.shutdown()
223236

224237
def on_plot_timer(self):
@@ -241,6 +254,7 @@ def on_plot_timer(self):
241254
if self.args.save:
242255
image = np.frombuffer(self.fig.canvas.tostring_rgb(), dtype="uint8")
243256
image = image.reshape(self.fig.canvas.get_width_height()[::-1] + (3,))
257+
image = Image.fromarray(image.astype(np.uint8))
244258
self.images.append(image)
245259

246260
def on_ego_ttc(self, msg):

planning/behavior_velocity_intersection_module/src/scene_intersection.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,20 @@ intersection::DecisionResult IntersectionModule::modifyPathVelocityDetail(
239239
// passed each pass judge line for the first time, save current collision status for late
240240
// diagnosis
241241
// ==========================================================================================
242+
tier4_debug_msgs::msg::Float64MultiArrayStamped object_ttc_time_array;
242243
updateObjectInfoManagerCollision(
243244
path_lanelets, time_distance_array, traffic_prioritized_level, safely_passed_1st_judge_line,
244-
safely_passed_2nd_judge_line);
245+
safely_passed_2nd_judge_line, &object_ttc_time_array);
246+
{
247+
const auto & debug = planner_param_.debug.ttc;
248+
if (
249+
std::find(debug.begin(), debug.end(), lane_id_) != debug.end() ||
250+
std::find(debug.begin(), debug.end(), -1) != debug.end()) {
251+
ego_ttc_pub_->publish(ego_ttc_time_array);
252+
object_ttc_pub_->publish(object_ttc_time_array);
253+
}
254+
}
255+
245256
for (const auto & object_info : object_info_manager_.attentionObjects()) {
246257
if (!object_info->unsafe_info()) {
247258
continue;

planning/behavior_velocity_intersection_module/src/scene_intersection.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ class IntersectionModule : public SceneModuleInterface
754754
void updateObjectInfoManagerCollision(
755755
const intersection::PathLanelets & path_lanelets, const TimeDistanceArray & time_distance_array,
756756
const TrafficPrioritizedLevel & traffic_prioritized_level,
757-
const bool passed_1st_judge_line_first_time, const bool passed_2nd_judge_line_first_time);
757+
const bool passed_1st_judge_line_first_time, const bool passed_2nd_judge_line_first_time,
758+
tier4_debug_msgs::msg::Float64MultiArrayStamped * object_ttc_time_array);
758759

759760
void cutPredictPathWithinDuration(
760761
const builtin_interfaces::msg::Time & object_stamp, const double time_thr,

0 commit comments

Comments
 (0)