00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import numpy as np,math
00032 import roslib; roslib.load_manifest('tf')
00033 from tf import transformations
00034
00035
00036
00037
00038
00039
00040
00041
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
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
00079 cy = 242.9
00080 self.cam_centers = (cx, cy)
00081 self.cam_image_height= 480
00082 self.cam_image_width= 640
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 x = 0.111181322026
00096 y= 0.0201393251186
00097 z= 1.39969502374
00098
00099 rx= -0.625821685412
00100 ry= 0.66370971141
00101 rz= -0.30689909515
00102 rw= 0.271384565597
00103
00104
00105
00106
00107
00108
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)
00116
00117 if device == 'PR2' and tf_msg:
00118
00119
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
00132 M = np.linalg.inv(M)
00133 self.camTlaser = M
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 elif device == 'desktopScanner':
00147 import scanr_transforms as trs
00148 self.webcam_id = 1
00149
00150
00151
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
00171
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
00188
00189
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
00200 self.webcam_id = 0
00201
00202
00203 self.cam_name = 'mekabotUTM'
00204
00205
00206
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,
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
00230
00231
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)
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