@@ -25,30 +25,32 @@ def plot_mpc_debug(csv_path):
2525 yaw = df ['mpc/state_yaw' ]
2626 target_theta = df ['mpc/target_theta' ]
2727
28+ position_error = df ['mpc/position_error' ]
29+ heading_error = df ['mpc/heading_error' ]
30+
2831 jerk_time = time [1 :]
2932 jerk = np .diff (accel ) / np .diff (time )
30- heading_acc = np .diff (yaw ) / np .diff (time )
3133
3234 fig , axs = plt .subplots (2 , 2 , figsize = (12 , 8 ))
33- fig .subplots_adjust (hspace = 0.4 , wspace = 0.3 )
35+ fig .subplots_adjust (hspace = 0.5 , wspace = 0.3 )
3436
3537 axs [0 ,0 ].plot (jerk_time , jerk , color = 'blue' )
3638 axs [0 ,0 ].set_title ("Vehicle Jerk Over Time" )
3739 axs [0 ,0 ].set_xlabel ("Time (s)" )
3840 axs [0 ,0 ].set_ylabel ("Jerk (m/s³)" )
3941 axs [0 ,0 ].grid (True )
4042
41- axs [0 ,1 ].plot (jerk_time , heading_acc , color = 'orange ' )
42- axs [0 ,1 ].set_title ("Heading Acceleration Over Time" )
43+ axs [0 ,1 ].plot (time , position_error , label = "Position Error" , color = 'green ' )
44+ axs [0 ,1 ].set_title ("Position Error Over Time" )
4345 axs [0 ,1 ].set_xlabel ("Time (s)" )
44- axs [0 ,1 ].set_ylabel ("Heading Acceleration (rad/s²)" )
46+ axs [0 ,1 ].set_ylabel ("Error (m)" )
47+ axs [0 ,1 ].legend ()
4548 axs [0 ,1 ].grid (True )
4649
47- axs [1 ,0 ].plot (time , state_x - target_x , label = "CTE X" , color = 'green' )
48- axs [1 ,0 ].plot (time , state_y - target_y , label = "CTE Y" , color = 'purple' )
49- axs [1 ,0 ].set_title ("Cross Track Error Over Time" )
50+ axs [1 ,0 ].plot (time , heading_error , label = "Heading Error" , color = 'red' )
51+ axs [1 ,0 ].set_title ("Heading Error Over Time" )
5052 axs [1 ,0 ].set_xlabel ("Time (s)" )
51- axs [1 ,0 ].set_ylabel ("CTE (m )" )
53+ axs [1 ,0 ].set_ylabel ("Error (rad )" )
5254 axs [1 ,0 ].legend ()
5355 axs [1 ,0 ].grid (True )
5456
@@ -62,6 +64,13 @@ def plot_mpc_debug(csv_path):
6264
6365 plt .show ()
6466
67+ print ("Max (abs) position error:" , np .max (np .abs (position_error )))
68+ print ("Avg position error:" , np .mean (np .abs (position_error )))
69+ print ("Max (abs) heading error:" , np .max (np .abs (heading_error )))
70+ print ("Avg heading error:" , np .mean (np .abs (heading_error )))
71+ print ("Max (abs) jerk:" , np .max (np .abs (jerk )))
72+ print ("Avg jerk:" , np .mean (np .abs (jerk )))
73+
6574if __name__ == '__main__' :
6675 if len (sys .argv ) != 2 :
6776 print ("Usage: python3 logplot_mpc.py <log_directory>" )
@@ -79,4 +88,3 @@ def plot_mpc_debug(csv_path):
7988 except Exception as e :
8089 print (f"Error: { e } " )
8190 sys .exit (1 )
82-
0 commit comments