7 from std_msgs.msg
import Float32
11 plot_topic = rospy.get_param(
"~plot_topic", [(
'/eth0/receive',
'reveive'), (
'eth0/transmit',
'transmit')])
13 max_y = rospy.get_param(
"~max_y", 1200000)
14 data_scale = rospy.get_param(
"~data_scale", 0.001)
16 data_rate = rospy.get_param(
"~data_rate", 100)
17 period = rospy.get_param(
"~period", 120)
18 drop_num = rospy.get_param(
"~drop_num", 10)
19 drop_index = [0
for i
in range(len(plot_topic))]
22 yrange = (0, (int)(max_y * data_scale))
24 xlabel = rospy.get_param(
"~x_label",
"Time (s)")
25 ylabel = rospy.get_param(
"~y_label",
"Network Data Rates (kbps)")
26 title = rospy.get_param(
"~title",
"Network Status")
28 plot_size = data_rate * period / drop_num
30 y_list = [numpy.zeros(plot_size)
for i
in range(len(plot_topic))]
31 x = numpy.arange(plot_size) / float(plot_size / period)
35 if drop_index[index] != drop_num:
36 drop_index[index] = drop_index[index] + 1
42 y_list[index] = numpy.delete(y_list[index], plot_size - 1)
43 y_list[index] = numpy.insert(y_list[index], 0, msg.data * data_scale)
45 d_list = [Gnuplot.Data(x, y, title=plot_topic[i][1], with_=
'lines linewidth 2')
for (i, y)
in enumerate(y_list)]
48 elif len(d_list) == 2:
49 gp.plot(d_list[0], d_list[1])
50 elif len(y_list) == 3:
51 gp.plot(d_list[0], d_list[1])
52 elif len(y_list) == 4:
53 gp.plot(d_list[0], d_list[1])
54 elif len(y_list) == 5:
55 gp.plot(d_list[0], d_list[1])
56 elif len(y_list) == 6:
57 gp.plot(d_list[0], d_list[1])
61 if __name__ ==
'__main__':
62 rospy.init_node(
"network_plot")
63 for i
in range(len(plot_topic)):
64 topic = plot_topic[i][0]
65 rospy.Subscriber(topic, Float32, callback, callback_args = i)
67 gp.set(xrange=xrange, yrange=yrange, title=title, xlabel=xlabel, ylabel=ylabel)