@@ -48,20 +48,20 @@ def parse_behavior_log(filename):
4848def parse_tracker_csv (filename ):
4949 """
5050 Parses the pure pursuit tracker log file and extracts the following data:
51- - vehicle time (from column index 18)
52- - Crosstrack error (from column index 20)
51+ - vehicle time (from column index 19)
5352 - X position actual (from column index 2)
5453 - Y position actual (from column index 5)
5554 - X position desired (from column index 11)
5655 - Y position desired (from column index 14)
5756 """
5857
5958 data = np .genfromtxt (filename , delimiter = ',' , skip_header = 1 )
60- vehicle_time = data [:, 18 ]
59+ vehicle_time = data [:, 19 ]
6160 cte = data [:, 20 ]
6261 x_actual , y_actual = data [:, 2 ], data [:, 5 ]
6362 x_desired , y_desired = data [:, 11 ], data [:, 14 ]
64- return vehicle_time , cte , x_actual , y_actual , x_desired , y_desired
63+ speed_actual = data [:, - 1 ]
64+ return vehicle_time , cte , x_actual , y_actual , x_desired , y_desired , speed_actual
6565
6666def compute_derivative (times , values ):
6767 """
@@ -74,16 +74,17 @@ def compute_derivative(times, values):
7474 return times [1 :], derivative
7575
7676def compute_gs (times , xs , ys ):
77- print (times )
78- print (xs )
7977 xtimes , vxs = compute_derivative (times , xs )
8078 ytimes , vys = compute_derivative (times , ys )
81- axtimes , axs = compute_derivative (times [1 :], vxs )
82- aytimes , ays = compute_derivative (times [1 :], vys )
79+ vs = np .sqrt (vxs ** 2 + vys ** 2 )
80+ long_times , long_accels = compute_derivative (times [1 :], vs )
81+ psis = np .arctan2 (vys , vxs )
82+ yaw_rate_times , yaw_rates = compute_derivative (times [1 :], psis )
83+ lat_accels = yaw_rates * vs [1 :]
8384 g = 9.81
84- longitudinal_gs = axs / g
85- lateral_gs = ays / g
86- return longitudinal_gs , lateral_gs
85+ longitudinal_gs = long_accels / g
86+ lateral_gs = lat_accels / g
87+ return longitudinal_gs , lateral_gs , vs , lat_accels , long_accels
8788
8889def plot_position (axis , x_actual , y_actual , x_desired , y_desired , safe_thresh = 1 , unsafe_thresh = 2.5 ):
8990 """Plots vehicle actual and desired positions vs. time"""
@@ -100,6 +101,23 @@ def plot_position(axis, x_actual, y_actual, x_desired, y_desired, safe_thresh=1,
100101 axis .legend ()
101102 axis .grid (True )
102103
104+ def plot_speeds (axis , speed_actual , comptued_speed , time ):
105+ axis .plot (time , comptued_speed , label = 'computed speed' )
106+ axis .plot (time , speed_actual , linestyle = "--" , label = 'current speed' )
107+ axis .set_xlabel ("time" )
108+ axis .set_ylabel ("speed m/s" )
109+ axis .set_title ("current speed vs computed speed" )
110+ axis .legend ()
111+ axis .grid (True )
112+
113+ def plot_accelerations (axis , accelerations , time ):
114+ axis .plot (time , accelerations , label = 'accelerationn' )
115+ axis .set_xlabel ("time" )
116+ axis .set_ylabel ("accel m/s^2" )
117+ axis .set_title ("long accelerations" )
118+ axis .legend ()
119+ axis .grid (True )
120+
103121def plot_gg_diagram (axis , longitudinal_gs , lateral_gs ):
104122 """Plots gg diagram"""
105123 # Plot G-G diagram
@@ -139,13 +157,15 @@ def plot_gg_diagram(axis, longitudinal_gs, lateral_gs):
139157
140158 # Pure pursuit tracker file exists: parse and plot all metrics
141159 if os .path .exists (tracker_file ):
142- vehicle_time , cte , x_actual , y_actual , x_desired , y_desired = parse_tracker_csv (tracker_file )
160+ vehicle_time , cte , x_actual , y_actual , x_desired , y_desired , speed_actual = parse_tracker_csv (tracker_file )
143161
144- longitudinal_gs , lateral_gs = compute_gs (vehicle_time , x_actual , y_actual )
162+ longitudinal_gs , lateral_gs , calculated_speed , lat_accels , long_accels = compute_gs (vehicle_time , x_actual , y_actual )
145163 # print(longitudinal_gs)
146- fig , axs = plt .subplots (1 , 2 , figsize = (12 , 4 ))
147- plot_gg_diagram (axs [0 ], longitudinal_gs , lateral_gs )
148- plot_position (axs [1 ], x_actual , y_actual , x_desired , y_desired )
164+ fig , axs = plt .subplots (2 , 2 , figsize = (12 , 4 ))
165+ plot_gg_diagram (axs [0 , 0 ], longitudinal_gs , lateral_gs )
166+ plot_position (axs [0 , 1 ], x_actual , y_actual , x_desired , y_desired )
167+ plot_speeds (axs [1 , 0 ], speed_actual [1 :], calculated_speed , vehicle_time [1 :])
168+ plot_accelerations (axs [1 , 1 ], long_accels , vehicle_time [2 :])
149169 plt .show ()
150170 # Pure pursuit tracker file is missing: plot only behavior.json metrics
151171 else :
0 commit comments