19from bisect
import bisect_left
21import matplotlib.pyplot
as plt
22from matplotlib.widgets
import Slider
31 print(
"Need 1 arguments: process_bag.py <file name> ")
34print(
"Starting To Process Bag")
35bag = rosbag.Bag(sys.argv[1])
37plan_trajectory_time_steps = []
38for topic, msg, t
in bag.read_messages(topics=[
'/guidance/plan_trajectory']):
40 plan_trajectory_time_steps.append([])
41 for point
in msg.trajectory_points:
42 plan_trajectory_time_steps[-1].append(point.target_time.to_sec())
44pure_pursuit_plan_trajectory_time_steps = []
45for topic, msg, t
in bag.read_messages(topics=[
'/guidance/pure_pursuit/plan_trajectory']):
47 pure_pursuit_plan_trajectory_time_steps.append([])
48 for point
in msg.trajectory_points:
49 pure_pursuit_plan_trajectory_time_steps[-1].append(point.target_time.to_sec())
51carma_final_waypoints_times_steps = []
56for topic, msg, t
in bag.read_messages(topics=[
'/guidance/carma_final_waypoints']):
58 carma_final_waypoints_times_steps.append([])
60 for point
in msg.waypoints:
62 first_point.append(point.twist.twist.linear.x)
64 second_point.append(point.twist.twist.linear.x)
66 third_point.append(point.twist.twist.linear.x)
68 fourth_point.append(point.twist.twist.linear.x)
69 carma_final_waypoints_times_steps[-1].append(point.twist.twist.linear.x)
73for topic, msg, t
in bag.read_messages(topics=[
'/guidance/ctrl_raw']):
75 ctrl_raw.append(msg.cmd.linear_velocity)
78for topic, msg, t
in bag.read_messages(topics=[
'/guidance/ctrl_cmd']):
80 ctrl_cmd.append(msg.cmd.linear_velocity)
83for topic, msg, t
in bag.read_messages(topics=[
'/hardware_interface/vehicle_cmd']):
85 if msg.ctrl_cmd.linear_velocity != 0.0:
86 vehicle_cmd.append(msg.ctrl_cmd.linear_velocity)
88print(
"Done Bag Processing")
94 fig = plt.figure(figure_num)
100 l, = plt.plot(range(len(data[0])), data[0],
'.')
102 time_step_ax = plt.axes([0.20, 0.01, 0.65, 0.03])
103 time_step_sldr = Slider(time_step_ax,
'Time Step', 0.0, len(data) - 1.0, valinit=0, valstep=1)
105 def update_timestep(val):
106 time_step = data[int(time_step_sldr.val)]
107 if (int(time_step_sldr.val) < 66
and int(time_step_sldr.val) > 62):
108 print (
"Trajectory Size: " + str(len(time_step)))
109 l.set_xdata(range(len(time_step)))
110 l.set_ydata(time_step)
111 fig.canvas.draw_idle()
113 time_step_sldr.on_changed(update_timestep)
115 return (fig, l, time_step_sldr)
118 "/guidance/plan_trajectory",
"Index",
"Time (s)")
121 "/guidance/pure_pursuit/plan_trajectory",
"Index",
"Time (s)")
124 "/guidance/carma_final_waypoints",
"Index",
"Velocity (m/s)")
131plt.ylabel(
"Velocity (m/s)")
132plt.plot(range(len(ctrl_raw)), ctrl_raw,
'r')
133plt.plot(range(len(ctrl_cmd)), ctrl_cmd,
'g')
139plt.title(
"Points Waypoints")
140plt.xlabel(
"Timestep")
141plt.ylabel(
"Velocity (m/s)")
142plt.plot(range(len(first_point)), first_point,
'r')
143plt.plot(range(len(second_point)), second_point,
'g')
144plt.plot(range(len(third_point)), third_point,
'b')
145plt.plot(range(len(fourth_point)), fourth_point,
'y')
146plt.legend([
"First",
"Second",
"Third",
"Fourth"])
def index_plot_with_slider(figure_num, data, title, xlabel, ylabel)