Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 import roslib; roslib.load_manifest('modeling_forces')
00009 import rospy
00010
00011 from checkerboard_detector.msg import ObjectDetection
00012 import hrl_lib.util as ut
00013 import hrl_lib.transforms as tr
00014 from std_msgs.msg import Empty
00015
00016 import numpy as np
00017 import time
00018
00019 def pose_cb(data, d):
00020 global t_pose_cb
00021 t_pose_cb = time.time()
00022
00023 for obj in data.objects:
00024 p = obj.pose.position
00025 pos = np.matrix([p.x, p.y, p.z]).T
00026
00027 q = obj.pose.orientation
00028 rot = tr.quaternion_to_matrix([q.x, q.y, q.z, q.w])
00029 t = data.header.stamp.to_sec()
00030
00031 d[obj.type]['pos_list'].append(pos)
00032 d[obj.type]['rot_list'].append(rot)
00033 d[obj.type]['time_list'].append(t)
00034
00035 print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
00036 print 'pos:', pos.T
00037 print 'rot:', rot
00038
00039 def got_trigger_cb(data, d):
00040 d['flag'] = True
00041
00042
00043 if __name__ == '__main__':
00044
00045 print 'Hello World.'
00046 rospy.init_node('checkerboard_poses_to_pickle', anonymous=False)
00047
00048 topic_name = '/checkerdetector/ObjectDetection'
00049 d = {'mechanism': {}, 'hand': {}}
00050 d['mechanism'] = {'pos_list': [], 'rot_list': [], 'time_list': []}
00051 d['hand'] = {'pos_list': [], 'rot_list': [], 'time_list': []}
00052
00053 rospy.Subscriber(topic_name, ObjectDetection, pose_cb, d)
00054
00055 got_trigger_dict = {'flag': False}
00056 rospy.Subscriber('/checker_to_poses/trigger', Empty, got_trigger_cb,
00057 got_trigger_dict)
00058
00059
00060 global t_pose_cb
00061 t_pose_cb = time.time()
00062 while got_trigger_dict['flag'] == False:
00063 time.sleep(0.05)
00064 if (time.time() - t_pose_cb) > 60.:
00065 raise RuntimeError('haven\'t received a pose_cb in 60 secs')
00066
00067
00068 print 'Number of poses:', len(d['mechanism']['time_list'])
00069
00070 ut.save_pickle(d, 'poses_dict.pkl')
00071
00072
00073