configuration.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2010, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 
00028 #  \author Martin Schuster (Healthcare Robotics Lab, Georgia Tech.)
00029 
00030 
00031 import numpy as np,math
00032 import roslib; roslib.load_manifest('tf')
00033 from tf import transformations
00034 
00035 # Optional imports below:
00036 #     import scanr_transforms as trs [for camTlaser(cam_vec) , when "DesktopScanner"]
00037 #  x  import codyRobot_camera_config as cc [for camera properties when "CodyRobot"]
00038 
00039 
00040 # WARNING: THE "PR2" configurations are for a fixed demo setup.  Actual values are 
00041 #   populated by "acquire_pr2_data.py", or something similar
00042 
00043 class configuration(object):
00044     '''
00045     Define camera properties matrix: fx, fy, and optical center in x,y
00046     Define rotation/translation matrix between camera origin and laser cloud origin
00047     Three types of robot/device accepted:
00048         "desktopScanner" -- used to collect dataset of tablescans
00049         "codyRobot" -- demonstrated object placement in clutter first on this platform
00050         "dummyScanner" -- esentially same as codyRobot, with no dependancies.
00051         "Other" -- quits with warning
00052         "PR2" or  -- requires tf_msg (geometry_msgs.msg.StampedTransform) to be passed
00053             also.  This is because the Transform is dynamic, unlike our other robots which have had a
00054             fixed relative placement between the camera and tilting hokuyo.
00055         "PR2example" -- initialized with a fixed transform between pointcloud 
00056              and camera, good for example data only.              
00057     
00058     '''
00059 
00060     def __init__(self, path = '../data/', device = 'desktopScanner', tf_msg = None):
00061         '''
00062         set default values
00063         '''
00064         self.path = path
00065         self.pointcloud_max_dist = 5.0
00066         self.pointcloud_min_dist = 0.1    
00067         
00068         self.device = device
00069         
00070         if device == 'PR2' or device == 'PR2example':
00071         
00072             self.cam_name = 'wide_stereo/right/image_rect_color'
00073             fx = 428.48 #focal lengths in pixels
00074             fy = 428.35
00075             self.cam_proj_mat = np.matrix([[fx, 0, 0,   0],
00076                                            [0, fy, 0,   0],
00077                                            [0,  0, 1,   0]])
00078             cx = 323.4 #in pixels
00079             cy = 242.9 #in pixels
00080             self.cam_centers = (cx, cy)
00081             self.cam_image_height= 480 #px
00082             self.cam_image_width= 640 #px
00083             
00084             #Transform properties will depend on wide_stereo_optical_frame
00085             #    -to-base_footprint TF since the PR2
00086             #can move its head relative to the tilting hokuyo.
00087             #
00088             
00089             ######### EXAMPLE result from TF on PR2 ##############
00090             #  header: --
00091             #  frame_id: /base_footprint
00092             #    child_frame_id: /wide_stereo_optical_frame 
00093             #    transform: 
00094             #      translation: 
00095             x = 0.111181322026
00096             y= 0.0201393251186 #-0.09 #Using right camera is shifted over by 9cm.
00097             z= 1.39969502374 #+0.051 #- 1.32  #****MY data was in BASE_LINK FRAME??
00098             #      rotation:  (rotation same as optical frame of Gazebo_R and Gazebo_L_ optical)
00099             rx= -0.625821685412
00100             ry= 0.66370971141
00101             rz= -0.30689909515
00102             rw= 0.271384565597
00103             #euler_angles = transformations.euler_from_quaternion([rx,ry,rz,rw])
00104             #In euler: (-132, -1.4, -94) in degrees.
00105             #####################################################
00106             
00107             #kill soon
00108             # Initialize THOK
00109             self.thok_l1 = 0
00110             self.thok_l2 = -0.055
00111             self.thok_tilt_angles = (math.radians(40.0),math.radians(-40.0))
00112             self.thok_devname = '/dev/robot/servo0'
00113             self.thok_servonum = 5
00114             self.thok_hoknum = 0
00115             self.thok_scan_speed = math.radians(10.0) #speed=10 in lpi
00116             
00117             if device == 'PR2' and tf_msg: 
00118                 #requires an appropriate TF message (type=TransformStamped) called tf_msg.
00119                 #Condition: header.frame_id = '/base_footprint', child_frame_id = '/wide_stereo_optical_frame'
00120                 t = tf_msg.transform.translation
00121                 r = tf_msg.transform.rotation
00122                 (x,y,z) = (t.x, t.y, t.z)
00123                 (rx, ry, rz, rw) = (r.x, r.y, r.z, r.w)             
00124             T = transformations.translation_matrix([x,y,z])
00125             R = transformations.quaternion_matrix([rx,ry,rz,rw])
00126             print 'R=',R
00127             print 'T=',T
00128             M = np.matrix(R);
00129             M[:3,3] = np.matrix(T)[:3,3]
00130             print 'M=',M
00131             #hack
00132             M = np.linalg.inv(M)
00133             self.camTlaser = M
00134 #   (wrong)  TRmatrix = [[-0.06939527, -0.66415251,  0.74436936,  0.11118132],
00135 #                        [-0.99730322,  0.02832033, -0.06770713, -0.06986067],
00136 #                        [ 0.02388707, -0.74706051, -0.66432673,  1.39969502],
00137 #                        [ 0.        ,  0.        ,  0.        ,  1.        ]]
00138             #Result is a 4x4 array: [ R | t ]
00139             #                       [ 0 | 1 ]
00140 
00141 #            np.array([[ 0.74436936,  0.06939527,  0.66415251,  0.        ],
00142 #                      [-0.06770713,  0.99730322, -0.02832033,  0.        ],
00143 #                      [-0.66432673, -0.02388707,  0.74706051,  0.        ],
00144 #                      [ 0.        ,  0.        ,  0.        ,  1.        ]])
00145           
00146         elif device == 'desktopScanner':
00147             import scanr_transforms as trs
00148             self.webcam_id = 1
00149             
00150             #From webcam_config definition formerly in robot1-->hrl_lib
00151             #  Parameter definitions for camera used on desktopScanner
00152             webcam_parameters = {
00153                 'DesktopWebcam':
00154                 {  
00155                     'calibration_image_width' : 960.0,
00156                     'calibration_image_height' : 720.0, 
00157                     'focal_length_x_in_pixels' : 794.985,
00158                     'focal_length_y_in_pixels' : 797.122,
00159                     'optical_center_x_in_pixels' : 491.555,
00160                     'optical_center_y_in_pixels' : 344.289,
00161                     'lens_distortion_radial_1' :    0.0487641,
00162                     'lens_distortion_radial_2' :    -0.128722,
00163                     'lens_distortion_tangential_1' : 0,
00164                     'lens_distortion_tangential_2' : 0,
00165                     'opencv_bayer_pattern' : None,
00166                     'color': True,
00167                 }
00168             }
00169             
00170             #most code from travis scanr-class:
00171             # Initialize webcam
00172             self.cam_name = 'DesktopWebcam'
00173             cp = webcam_parameters[self.cam_name]
00174             fx = cp['focal_length_x_in_pixels']
00175             fy = cp['focal_length_y_in_pixels']
00176             self.cam_proj_mat =  np.matrix([[fx, 0, 0,   0],
00177                                             [0, fy, 0,   0],
00178                                             [0,  0, 1,   0]])
00179     
00180             self.cam_centers = ( cp['optical_center_x_in_pixels'], cp['optical_center_y_in_pixels'] )
00181             self.cam_deltas = np.array([0.1, 0.1, 0.1, 0.1, 0.001, 0.001, 0.001 ])
00182             self.cam_names = ['Ry_0', 'Rz_0', 'Rx_-90', 'Rz_-90', 'dx', 'dy', 'dz']
00183             self.cam_vec = np.array([  1.8000  ,  1.7000  , -2.6000 ,   4.7500 ,   0.0620  ,  0.0320  , -0.0270  ])             
00184 
00185             self.camTlaser = trs.camTlaser(self.cam_vec)
00186 
00187             self.scanner_metal_plate_offset = 0.05 #TODO
00188     
00189             # Initialize THOK
00190             self.thok_l1 = 0
00191             self.thok_l2 = 0.035
00192             self.thok_tilt_angles = (math.radians(40.0),math.radians(-40.0))
00193             self.thok_devname = '/dev/robot/desktopServos'
00194             self.thok_servonum = 19
00195             self.thok_hoknum = 0
00196             self.thok_scan_speed = math.radians(5.0)
00197                        
00198         elif device == 'codyRobot' or device == 'dummyScanner': 
00199             #just for testing/demonstration without dependencies outside of gt-ros-pkg            
00200             self.webcam_id = 0
00201             
00202             #values from equilibrium_point_control/lpi.py
00203             self.cam_name = 'mekabotUTM' #also: 'dummyUTM'
00204 
00205             #Values copied from Cody
00206             #Please update with current values if they are expected to have changed.
00207             cp =     {'calibration_image_width' : 640.0,
00208                       'calibration_image_height' : 480.0, 
00209                       'focal_length_x_in_pixels' : 362.381,
00210                       'focal_length_y_in_pixels' : 362.260,
00211                       'optical_center_x_in_pixels' : 275.630,
00212                       'optical_center_y_in_pixels' : 267.914,
00213                       'lens_distortion_radial_1' :    -0.270544,
00214                       'lens_distortion_radial_2' :    0.0530850,
00215                       'lens_distortion_tangential_1' : 0,
00216                       'lens_distortion_tangential_2' : 0,
00217                       'opencv_bayer_pattern' :  48, #same as cv.CV_BayerBG2BGR
00218                       'color': True,
00219                       'uid': 8520228
00220             }
00221             fx = cp['focal_length_x_in_pixels']
00222             fy = cp['focal_length_y_in_pixels']
00223             
00224             self.cam_proj_mat =  np.matrix([[fx, 0, 0,   0],
00225                                             [0, fy, 0,   0],
00226                                             [0,  0, 1,   0]])
00227             self.cam_centers = ( cp['optical_center_x_in_pixels'], cp['optical_center_y_in_pixels'] )
00228             
00229             #self.camTlaser = mcf.utmcam0Tglobal(mcf.globalTthok0(m),self.image_angle)
00230             
00231             # Initialize THOK
00232             self.thok_l1 = 0
00233             self.thok_l2 = -0.055
00234             self.thok_tilt_angles = (math.radians(40.0),math.radians(-40.0))
00235             self.thok_devname = '/dev/robot/servo0'
00236             self.thok_servonum = 5
00237             self.thok_hoknum = 0
00238             self.thok_scan_speed = math.radians(10.0) #speed=10 in lpi
00239 
00240         else:
00241             print '[configuration] ERROR: configuration.py: Device "%s" not recognized:' %( device )
00242             print 'Exiting.  Cannot fetch transformation and camera properties for this device.'
00243             
00244             


clutter_segmentation
Author(s): Jason Okerman, Martin Schuster, Advisors: Prof. Charlie Kemp and Jim Regh, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 12:07:15