Skip to content

Commit 0e0da7e

Browse files
committed
Benchmark CSV saving with evaluation py script #1
1 parent 505fdf9 commit 0e0da7e

15 files changed

+5525
-12
lines changed

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ find_package(tf2 REQUIRED)
1515
find_package(tf2_msgs REQUIRED)
1616
find_package(tf2_ros REQUIRED)
1717
find_package(tf2_geometry_msgs REQUIRED)
18+
find_package(wayp_plan_tools REQUIRED)
1819

1920
# uncomment the following section in order to fill in
2021
# further dependencies manually.
@@ -29,11 +30,17 @@ set(ament_dependencies
2930
tf2_msgs
3031
tf2_ros
3132
tf2_geometry_msgs
33+
wayp_plan_tools
3234
)
3335

3436
include_directories(
35-
include
37+
# include
38+
# share/${wayp_plan_tools}
39+
# ${wayp_plan_tools_INCLUDE_DIRS}
40+
../wayp_plan_tools/include # TODO: this solution only works for the current project structure
3641
)
42+
# ament_export_include_directories(include)
43+
# ament_export_dependencies(${ament_dependencies})
3744

3845
add_executable(pose_arr_to_tf src/pose_arr_to_tf.cpp)
3946
ament_target_dependencies(pose_arr_to_tf ${ament_dependencies} )
@@ -68,5 +75,6 @@ install(TARGETS
6875
pose_arr_to_tf
6976
visuals
7077
csv_saver
71-
DESTINATION lib/${PROJECT_NAME})
78+
DESTINATION lib/${PROJECT_NAME}
79+
)
7280
ament_package()

csv/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ A [Hungaroring](https://en.wikipedia.org/wiki/Hungaroring) inspired track.
1212
# `sim_waypoints3.csv`
1313

1414
![](../img/sim_waypoints3.svg)
15+
16+
17+
# Evaluation example
18+
19+
![](../img/csv_eval01.svg)

csv/csv_eval_measurement.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# load csv and plot it
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import matplotlib.gridspec as gridspec
5+
6+
# waypoint csv header: x,y,z,yaw,mps,change_flag
7+
W_X = 0
8+
W_Y = 1
9+
W_Z = 2
10+
W_YAW = 3
11+
W_MPS = 4
12+
# measure csv header: x,y,time,steering_angle,speed_mps,cur_lat_dist_abs,trg_way_lon_dist
13+
M_X = 0
14+
M_Y = 1
15+
M_TIME = 2
16+
M_STEER = 3
17+
M_SPEED = 4
18+
M_LAT_DIST = 5
19+
M_LON_DIST = 6
20+
21+
# create plot layout
22+
# f, (ax_xy, ax_st, ax_dist) = plt.subplots(nrows=3, ncols=1, sharex=False, gridspec_kw={"height_ratios": [3, 1, 1]})
23+
24+
f = plt.figure(constrained_layout=True)
25+
gs = f.add_gridspec(3, 3, width_ratios=[3, 1, 1], height_ratios=[3, 1, 1])
26+
ax_xy = f.add_subplot(gs[0, :])
27+
ax_st = f.add_subplot(gs[1, :-1])
28+
ax_txt = f.add_subplot(gs[1:, -1])
29+
ax_dist = f.add_subplot(gs[-1, :-1])
30+
31+
# ax_xy.set_xlabel("x") # , fontsize=6
32+
# ax_xy.set_ylabel("y")
33+
ax_st.set_xlabel("time")
34+
ax_st.set_ylabel("steer ang")
35+
ax_dist.set_xlabel("time")
36+
ax_dist.set_ylabel("lat dist")
37+
# ax_st.set_title("steering angle")
38+
# ax_dist.set_title("lat distance (abs)")
39+
ax_xy.axis("equal")
40+
ax_xy.grid()
41+
ax_st.grid()
42+
ax_dist.grid()
43+
ax_xy.legend(['first stock name', 'second stock name'])
44+
ax_txt.axis("off")
45+
46+
47+
48+
# read the data
49+
def read_data(filename):
50+
points = np.genfromtxt(filename, delimiter=",", skip_header=1)
51+
return points
52+
53+
def read_data_arr(filenames):
54+
points = []
55+
for filename in filenames:
56+
points.append(np.genfromtxt(filename + "_xypose.csv", delimiter=",", skip_header=1))
57+
return points
58+
59+
# plot x y data
60+
def plot_xy(points, fmt="", labl=""):
61+
ax_xy.plot(points[:, W_X], points[:, W_Y], fmt, label=labl, alpha=0.8)
62+
ax_xy.legend()
63+
64+
def plot_all(points, fmt="", labl=""):
65+
ax_xy.plot(points[:, W_X], points[:, W_Y], label=labl, alpha=0.8)
66+
ax_st.plot(points[:, M_TIME], points[:, M_STEER], fmt, label=labl, alpha=0.8)
67+
ax_dist.plot(points[:, M_TIME], points[:, M_LAT_DIST], fmt, label=labl, alpha=0.8)
68+
ax_xy.legend()
69+
70+
def read_text(filenames):
71+
text = ""
72+
for filename in filenames:
73+
text += "\n\n" + filename + "\n"
74+
with open(filename + "_metrics.csv", "r") as file:
75+
text += file.read()
76+
return text
77+
78+
79+
# main function
80+
if __name__ == "__main__":
81+
meas_arr = ["csv/tmp01", "csv/tmp02", "csv/tmp03"]
82+
wp_file = "csv/sim_waypoints3.csv"
83+
points_wp = read_data(wp_file)
84+
points_meas = read_data_arr(meas_arr)
85+
# ax_xy.plot(points_meas[0][:, M_X], points_meas[0][:, M_Y], "r.-", label="xy", alpha=0.1, linewidth=4.2)
86+
plot_xy(points_wp, fmt="k--", labl="waypoints")
87+
plot_all(points_meas[0], labl="p pursuit A")
88+
plot_all(points_meas[1], labl="p pursuit B")
89+
plot_all(points_meas[2], labl="p pursuit C")
90+
ax_txt.text(0.5, 0.5, read_text(meas_arr), ha="center", va="center", fontsize=8)
91+
# f.tight_layout()
92+
# f.savefig("img/csv_eval01.svg")
93+
plt.show()

csv/csv_vizu.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ def read_data(filename = 'csv/sim_waypoints1.csv'):
1717

1818
# main function
1919
if __name__ == '__main__':
20-
points = read_data('csv/sim_waypoints2.csv')
21-
plt.plot(points[:, 0], points[:, 1], 'r.-', label='xy', alpha=0.1, linewidth=4.2)
20+
my_file = 'csv/sim_waypoints2.csv'
21+
points = read_data(my_file)
22+
plt.plot(points[:, 0], points[:, 1], 'r.-', label=my_file, alpha=0.1, linewidth=4.2)
2223
# plt.quiver(points[:, 0], points[:, 1], np.cos(points[:, 3]), np.sin(points[:, 3]), angles='xy', scale_units='xy', scale=2.2, alpha=0.4)
2324
plt.xlabel('x', fontsize=6)
2425
plt.ylabel('y', fontsize=6)
25-
plt.title('sim_waypoints2', fontsize=6)
26+
plt.title(my_file, fontsize=6)
2627
plt.axis('equal')
2728
plt.grid()
29+
plt.legend()
2830
plt.show()

csv/tmp01_metrics.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MAX_LAT_DISTANCE,9.8051
2+
AVG_LAT_DISTANCE,0.7500
3+
lookahead_min,2.5
4+
lookahead_max,6.5

0 commit comments

Comments
 (0)