Go to the documentation of this file.00001
00002
00003 import roslib
00004 roslib.load_manifest('tf')
00005 roslib.load_manifest('rosparam')
00006 roslib.load_manifest('sensor_msgs')
00007
00008 import rospy
00009 import rosparam
00010 import rosbag
00011 from sensor_msgs.msg import PointCloud2
00012 from hrl_generic_arms.pose_converter import PoseConverter
00013
00014 from kelsey_sandbox.msg import PHRIPointCloudCapture
00015
00016 class PCSaver:
00017 def __init__(self, pc_topic, base_frame, frames, filename):
00018 self.base_frame = base_frame
00019 self.frames = frames
00020 self.seq = 0
00021 self.bag = rosbag.Bag(filename, 'w')
00022 rospy.Subscriber(pc_topic, PointCloud2, self.store_pc)
00023
00024 def store_pc(self, msg):
00025 pcc = PHRIPointCloudCapture()
00026 pcc.pc_capture = msg
00027 pcc.saved_frames.header.seq = self.seq
00028 pcc.saved_frames.header.frame_id = self.base_frame
00029 pcc.saved_frames.header.stamp = rospy.Time.now()
00030 for frame in self.frames:
00031 try:
00032 pos, quat = self.tf_list.lookupTransform(self.base_frame,
00033 frame, rospy.Time(0))
00034 pcc.saved_frames.poses.append(PoseConverter.to_pose_msg(pos, quat))
00035 except:
00036 print "FAILED TO CAPTURE POINTCLOUD, MISSING FRAME: %s" % frame
00037 return
00038 self.pcc = pcc
00039
00040 def save_pc(self):
00041 self.bag.write("/point_cloud_captures", self.pcc)
00042 self.seq += 1
00043
00044 def main():
00045 rospy.init_node('phri_setup_capture')
00046
00047 from optparse import OptionParser
00048 p = OptionParser()
00049 p.add_option('-l', '--load_file', dest="load_file", default="",
00050 help="YAML file to load parameters from.")
00051 p.add_option('-b', '--bagfile', dest="bagname", default="phri_output.bag",
00052 help="Bag file to save to.")
00053 opts, args = p.parse_args()
00054 assert opts.load_file != ""
00055
00056 params = rosparam.load_file(opts.load_file, "phri_setup_capture")[0][0]
00057 base_frame = params['base_frame']
00058 frames = params['frames_to_save']
00059 pc_topic = params['pc_topic']
00060
00061 pcs = PCSaver(pc_topic, base_frame, frames, opts.bagname)
00062 while not rospy.is_shutdown():
00063 raw_input("Type 'd' when done: ")
00064 pcs.save_pc()
00065 pcs.bag.close()
00066
00067
00068 if __name__ == "__main__":
00069 main()