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 pr2_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"
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"
00083
00084 sensor_type = 'camera_chains'
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"
00091
00092
00093 self.sensors = sensors
00094 self.checkerboard = msg.target_id
00095
00096
00097 def update_config(self, robot_params):
00098 for sensor in self.sensors:
00099 sensor.update_config(robot_params)
00100
00101 def compute_residual(self, target_pts):
00102 r_list = [sensor.compute_residual(target_pts) for sensor in self.sensors]
00103 if len(r_list) == 0:
00104 return array([])
00105
00106 r = concatenate(r_list,0)
00107 return r
00108
00109 def compute_residual_scaled(self, target_pts):
00110 r_list = [sensor.compute_residual_scaled(target_pts) for sensor in self.sensors]
00111 if len(r_list) == 0:
00112 return array([])
00113
00114 r = concatenate(r_list,0)
00115 return r
00116
00117 def compute_marginal_gamma_sqrt(self, target_pts):
00118 gamma_sqrt_list = [sensor.compute_marginal_gamma_sqrt(target_pts) for sensor in self.sensors]
00119 if len(gamma_sqrt_list) == 0:
00120 return matrix([])
00121 gamma_sqrt = block_diag(gamma_sqrt_list)
00122 return gamma_sqrt
00123
00124 def get_residual_length(self):
00125 return sum([sensor.get_residual_length() for sensor in self.sensors])