network_plot.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import Gnuplot
4 import time
5 import numpy
6 import rospy
7 from std_msgs.msg import Float32
8 
9 gp=Gnuplot.Gnuplot()
10 
11 plot_topic = rospy.get_param("~plot_topic", [('/eth0/receive', 'reveive'), ('eth0/transmit', 'transmit')])
12 
13 max_y = rospy.get_param("~max_y", 1200000)
14 data_scale = rospy.get_param("~data_scale", 0.001)
15 
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) #drop 9 topic out of 10
19 drop_index = [0 for i in range(len(plot_topic))]
20 
21 xrange = (period, 0)
22 yrange = (0, (int)(max_y * data_scale))
23 
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")
27 
28 plot_size = data_rate * period / drop_num
29 
30 y_list = [numpy.zeros(plot_size) for i in range(len(plot_topic))]
31 x = numpy.arange(plot_size) / float(plot_size / period)
32 
33 def callback(msg, index):
34  global drop_index
35  if drop_index[index] != drop_num:
36  drop_index[index] = drop_index[index] + 1
37  return
38  drop_index[index] = 0
39 
40  global y_list
41 
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)
44  try:
45  d_list = [Gnuplot.Data(x, y, title=plot_topic[i][1], with_='lines linewidth 2') for (i, y) in enumerate(y_list)]
46  if len(d_list) == 1:
47  gp.plot(d_list[0])
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])
58  except:
59  pass
60 
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)
66 
67  gp.set(xrange=xrange, yrange=yrange, title=title, xlabel=xlabel, ylabel=ylabel)
68  rospy.spin()


jsk_network_tools
Author(s): Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:07