plot_data_to_csv.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import os.path as osp
5 
6 import rospy
7 from jsk_recognition_msgs.msg import PlotData
8 import csv
9 
10 counter = 0
11 
12 
13 def callback(msg):
14  global counter
15 
16  try:
17  file_i = osp.expanduser(filename % counter)
18  except TypeError:
19  file_i = osp.expanduser(filename)
20  rospy.loginfo("Output file %s will be overwritten." % file_i)
21 
22  rospy.loginfo("writing to %s" % file_i)
23 
24  dst_dir = osp.dirname(file_i)
25  if not osp.isdir(dst_dir):
26  os.makedirs(dst_dir)
27 
28  with open(file_i, "w") as f:
29  writer = csv.writer(f, delimiter=',')
30  writer.writerow(["x", "y"])
31  for x, y in zip(msg.xs, msg.ys):
32  writer.writerow([x, y])
33  rospy.loginfo("done")
34  counter = counter + 1
35 
36 
37 if __name__ == "__main__":
38  rospy.init_node("plot_data_to_csv")
39  filename = rospy.get_param("~filename", "output_%04d.csv")
40  sub = rospy.Subscriber("~input", PlotData, callback, queue_size=1)
41  rospy.spin()


jsk_recognition_msgs
Author(s):
autogenerated on Mon May 3 2021 03:02:56