$search
00001 #!/usr/bin/env python 00002 00003 # Software License Agreement (BSD License) 00004 # 00005 # Copyright (c) 2008, Willow Garage, Inc. 00006 # All rights reserved. 00007 # 00008 # Redistribution and use in source and binary forms, with or without 00009 # modification, are permitted provided that the following conditions 00010 # are met: 00011 # 00012 # * Redistributions of source code must retain the above copyright 00013 # notice, this list of conditions and the following disclaimer. 00014 # * Redistributions in binary form must reproduce the above 00015 # copyright notice, this list of conditions and the following 00016 # disclaimer in the documentation and/or other materials provided 00017 # with the distribution. 00018 # * Neither the name of Willow Garage, Inc. nor the names of its 00019 # contributors may be used to endorse or promote products derived 00020 # from this software without specific prior written permission. 00021 # 00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 # POSSIBILITY OF SUCH DAMAGE. 00034 # 00035 # Author: Bhaskara Marthi 00036 00037 # Script to visualize saved scans 00038 00039 00040 import roslib 00041 roslib.load_manifest('flirtlib_ros') 00042 00043 import sys 00044 import geometry_msgs.msg as gm 00045 import sensor_msgs.msg as sm 00046 import rospy 00047 import tf.transformations as trans 00048 from math import sin, cos 00049 import mongo_ros as mr 00050 import flirtlib_ros.msg as fm 00051 00052 def scan2cloud(scan, pose): 00053 x0 = pose.position.x 00054 y0 = pose.position.y 00055 print "Angle is ", pose.orientation 00056 theta0 = trans.euler_from_quaternion([pose.orientation.x, pose.orientation.y, 00057 pose.orientation.z, pose.orientation.w])[2] 00058 print "Base pos is {0}, {1}, {2}".format(x0, y0, theta0) 00059 cloud = sm.PointCloud() 00060 cloud.header.frame_id='/map' 00061 cloud.header.stamp = rospy.Time.now() 00062 cloud.points = [] 00063 for i, r in enumerate(scan.ranges): 00064 theta = theta0 + scan.angle_min + i*scan.angle_increment 00065 p = gm.Point32(x0+cos(theta)*r, y0+sin(theta)*r, 0) 00066 cloud.points.append(p) 00067 00068 return cloud 00069 00070 00071 def main(): 00072 rospy.init_node('test_scan') 00073 c=mr.MessageCollection('flirtlib_place_rec', 'scans', fm.RefScanRos, 00074 db_host='mongo.willowgarage.com') 00075 l = list(c.query({})) 00076 if len(sys.argv!=2): 00077 print "Usage: {0} SCAN_NUM".format(sys.argv[0]) 00078 i = int(sys.argv[1]) 00079 print "Visualizing scan ", i 00080 msg = l[i][0] 00081 cl = scan2cloud(msg.scan, msg.pose) 00082 pub = rospy.Publisher('saved_cloud', sm.PointCloud, latch=True) 00083 pub.publish(cl) 00084 rospy.spin() 00085 00086 if __name__=='__main__': 00087 sys.exit(main()) 00088 00089 00090