Go to the documentation of this file.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 
00032 
00033 
00034 
00035 from calibration_estimation.sensors import tilting_laser_sensor, chain_sensor, camera_chain_sensor
00036 from numpy import concatenate
00037 from numpy import zeros, cumsum, matrix, array
00038 
00039 def block_diag(m_list):
00040     '''
00041     Given a list of matricies.  Combine into a larger, block diagonal matrix. This really should
00042     exist in numpy
00043     '''
00044     
00045     for m in m_list:
00046         assert(m.shape[0] == m.shape[1])
00047     m_sizes = [m.shape[0] for m in m_list ]
00048     end_ind   = list(cumsum(m_sizes))
00049     start_ind = [0] + end_ind[0:-1]
00050     result = zeros( [end_ind[-1], end_ind[-1] ] )
00051     for first, last, m in zip(start_ind, end_ind, m_list):
00052         result[first:last, first:last] = m
00053     return matrix(result)
00054 
00055 class MultiSensor:
00056     '''
00057     Provides helper methods for dealing with all the sensor measurements
00058     generated from a single RobotMeasurement/CbPose pair
00059     '''
00060     def __init__(self, sensor_configs):
00061         self._sensor_configs = sensor_configs
00062         self.sensors = []
00063         self.checkerboard = "NONE"
00064 
00065     def sensors_from_message(self, msg):
00066         sensors = []
00067 
00068         sensor_type = 'tilting_lasers'
00069         if sensor_type in self._sensor_configs.keys():
00070             cur_bundler = tilting_laser_sensor.TiltingLaserBundler( self._sensor_configs[sensor_type] )
00071             cur_sensors = cur_bundler.build_blocks(msg)
00072             sensors.extend(cur_sensors)
00073         else:
00074             print "[%s] section doesn't exist. Skipping" % sensor_type
00075 
00076         sensor_type = 'chains'
00077         if sensor_type in self._sensor_configs.keys():
00078             cur_bundler = chain_sensor.ChainBundler( self._sensor_configs[sensor_type] )
00079             cur_sensors = cur_bundler.build_blocks(msg)
00080             sensors.extend(cur_sensors)
00081         else:
00082             print "[%s] section doesn't exist. Skipping" % sensor_type
00083 
00084         sensor_type = 'rectified_cams'
00085         if sensor_type in self._sensor_configs.keys():
00086             cur_bundler = camera_chain_sensor.CameraChainBundler( self._sensor_configs[sensor_type] )
00087             cur_sensors = cur_bundler.build_blocks(msg)
00088             sensors.extend(cur_sensors)
00089         else:
00090             print "[%s] section doesn't exist. Skipping" % sensor_type
00091 
00092         
00093         self.sensors = sensors
00094         self.checkerboard = msg.target_id
00095 
00096     def update_config(self, robot_params):
00097         for sensor in self.sensors:
00098             sensor.update_config(robot_params)
00099 
00100     def compute_residual(self, target_pts):
00101         r_list = [sensor.compute_residual(target_pts) for sensor in self.sensors]
00102         if len(r_list) == 0:
00103             return array([])
00104 
00105         r = concatenate(r_list,0)
00106         return r
00107 
00108     def compute_residual_scaled(self, target_pts):
00109         r_list = [sensor.compute_residual_scaled(target_pts) for sensor in self.sensors]
00110         if len(r_list) == 0:
00111             return array([])
00112 
00113         r = concatenate(r_list,0)
00114         return r
00115 
00116     def compute_marginal_gamma_sqrt(self, target_pts):
00117         gamma_sqrt_list = [sensor.compute_marginal_gamma_sqrt(target_pts) for sensor in self.sensors]
00118         if len(gamma_sqrt_list) == 0:
00119             return matrix([])
00120         gamma_sqrt = block_diag(gamma_sqrt_list)
00121         return gamma_sqrt
00122 
00123     def get_residual_length(self):
00124         return sum([sensor.get_residual_length() for sensor in self.sensors])
00125