test01.py
Go to the documentation of this file.
00001 import roslib; roslib.load_manifest('hai_sandbox')
00002 import rospy
00003 
00004 import pr2_msgs.msg as pm
00005 import time
00006 import hrl_lib.util as hru
00007 
00008 class DataAccumulate:
00009     def __init__(self, topic, type):
00010         rospy.Subscriber(topic, type, self.callback)
00011         self.data = []
00012         self.headers = []
00013         self.t = None
00014 
00015     def callback(self, msg):
00016         msg.header.stamp = msg.header.stamp.to_time()
00017         self.data.append(msg)
00018         self.t = time.time()
00019 
00020     def done(self):
00021         if self.t != None:
00022             return (time.time() - self.t) > 2.
00023         else:
00024             return False
00025 
00026 if __name__ == '__main__':
00027     import sys
00028     rospy.init_node('test01')
00029     d = DataAccumulate('/pressure/l_gripper_motor', pm.PressureState)
00030     r = rospy.Rate(10)
00031     while not rospy.is_shutdown():
00032         if d.done():
00033             break
00034     print 'saved to', sys.argv[1]
00035     hru.save_pickle(d.data, sys.argv[1])
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082     #print len(d.data)
00083     #hru.save_pickle(d.data[0]['stamp'], sys.argv[1])
00084     #hru.save_pickle(d.data[0]['frame_id'], sys.argv[1])
00085     #hru.save_pickle(d.data[0]['l_finger_tip'], sys.argv[1])
00086     #hru.save_pickle(d.data[0]['r_finger_tip'], sys.argv[1])
00087     #hru.save_pickle(d.headers, 'headers.pkl')
00088 
00089         #self.data.app
00090         #self.data.append({"stamp": msg.header.stamp.to_time(),
00091         #                  "frame_id": msg.header.frame_id,
00092         #                  "l_finger_tip": msg.l_finger_tip,
00093         #                  "r_finger_tip": msg.r_finger_tip})
00094         #self.headers.append(msg.header)


hai_sandbox
Author(s): Hai Nguyen
autogenerated on Wed Nov 27 2013 11:46:56