11def plot_data(filename, min_x=(-10, 10), min_y=(-10, 10)):
12 path_x, path_y = [], []
13 cone_x, cone_y, cone_colors = [], [], []
14 car_x, car_y =
None,
None
16 with open(filename,
'r')
as f:
18 data = line.strip().split()
22 path_x.append(float(data[1]))
23 path_y.append(float(data[2]))
25 cone_x.append(float(data[1]))
26 cone_y.append(float(data[2]))
27 cone_colors.append(
'yellow' if data[3] ==
'yellow_cone' else 'blue')
29 car_x = float(data[1])
30 car_y = float(data[2])
32 fig, ax = plt.subplots(figsize=(11, 10))
34 ax.scatter(cone_x, cone_y, c=cone_colors, edgecolors=
'black', s=100)
36 ax.plot(path_x[0:], path_y[0:],
'r-', linewidth=1, zorder=1)
37 ax.scatter(path_x[1:], path_y[1:], c=
'red', s=50, label=
'Path', zorder=2)
38 ax.scatter(path_x[0], path_y[0], c=
'orange', s=50, label=
'Start', zorder=3)
40 if car_x
is not None and car_y
is not None:
41 ax.scatter(car_x, car_y, c=
'green', s=150, label=
'Car Position', zorder=4)
43 all_x = path_x + cone_x
44 all_y = path_y + cone_y
46 x_min = min(min_x[0], min(all_x))
if all_x
else min_x[0]
47 x_max = max(min_x[1], max(all_x))
if all_x
else min_x[1]
48 y_min = min(min_y[0], min(all_y))
if all_y
else min_y[0]
49 y_max = max(min_y[1], max(all_y))
if all_y
else min_y[1]
51 ax.set_xlim(x_min - 5, x_max + 5)
52 ax.set_ylim(y_min - 5, y_max + 5)
57 ax.set_title(
'Track Visualization')
61 folder_path =
"/home/ws/src/planning/test/integration_tests/results/"
65 for i
in range(1, len(txt_files)+1):
66 selected_file = os.path.join(folder_path, txt_files[i-1])
67 plot_data(selected_file, min_x=(-2, 20), min_y=(-2, 20))
71 choice = int(input(
"\nEnter the number of the file to plot (0 to exit): "))
74 if 1 <= choice <= len(txt_files):
75 selected_file = os.path.join(folder_path, txt_files[choice-1])
76 plot_data(selected_file, min_x=(-5, 20), min_y=(-5, 30))
78 print(
"Invalid selection. Please try again.")
80 print(
"Please enter a valid number.")