Go to the documentation of this file.00001
00002
00003 import rospy
00004 from jsk_recognition_msgs.msg import PlotData
00005 import csv
00006
00007 counter = 0
00008 def callback(msg):
00009 global counter
00010 rospy.loginfo("writing to %s" % (filename % counter))
00011 with open(filename % counter, "w") as f:
00012 writer = csv.writer(f, delimiter=',')
00013 writer.writerow(["x", "y"])
00014 for x, y in zip(msg.xs, msg.ys):
00015 writer.writerow([x, y])
00016 rospy.loginfo("done")
00017 counter = counter + 1
00018
00019 if __name__ == "__main__":
00020 rospy.init_node("plot_data_to_csv")
00021 filename = rospy.get_param("~filename", "output_%04d.csv")
00022 sub = rospy.Subscriber("~input", PlotData, callback, queue_size=1)
00023 rospy.spin()