34 import roslib; roslib.load_manifest(
'calibration_launch')
39 from bisect
import bisect
42 return cmp(x.header.stamp, y.header.stamp)
45 return cmp(x[0].header.stamp, y[0].header.stamp)
63 for cam_id
in [x
for x
in cam_ids
if x
not in self.
_cam_sizes]:
65 for chain_id
in [x
for x
in chain_ids
if x
not in self.
_chain_sizes]:
67 for laser_id
in [x
for x
in laser_ids
if x
not in self.
_laser_sizes]:
79 cur_cache.sort(stamped_cmp)
80 while len(cur_cache) > self.
_cam_sizes[cam_id]:
86 cur_cache.sort(stamped_cmp)
92 cur_cache.append( [m, interval_start, interval_end] )
93 cur_cache.sort(laser_cmp)
99 req_duration = interval_end - interval_start
100 req_center = interval_start + rospy.Duration(req_duration.to_sec()*.5)
102 if req_duration < min_duration:
106 cam_measurements = dict( [ (x,
None)
for x
in self._cam_caches.keys() ] )
107 for cam_id
in self._cam_caches.keys():
110 right_center_index = bisect( [x.header.stamp
for x
in cur_cache], req_center )
114 if right_center_index >= len(cur_cache):
115 cam_measurements[cam_id] =
None 116 elif cur_cache[right_center_index].header.stamp > interval_end
or cur_cache[right_center_index].header.stamp < interval_start:
117 cam_measurements[cam_id] =
None 119 cam_measurements[cam_id] = cur_cache[right_center_index]
122 chain_measurements = dict( [ (x,
None)
for x
in self._chain_caches.keys() ] )
123 for chain_id
in self._chain_caches.keys():
126 right_center_index = bisect( [x.header.stamp
for x
in cur_cache], req_center )
130 if right_center_index >= len(cur_cache):
131 chain_measurements[chain_id] =
None 132 elif cur_cache[right_center_index].header.stamp > interval_end
or cur_cache[right_center_index].header.stamp < interval_start:
133 chain_measurements[chain_id] =
None 135 chain_measurements[chain_id] = cur_cache[right_center_index]
138 laser_measurements = dict( [ (x,
None)
for x
in self._laser_caches.keys() ] )
139 for laser_id
in self._laser_caches.keys():
141 sub_list = [x
for x
in cur_cache
if x[2] <= interval_end
and x[1] >= interval_start]
142 if len(sub_list) > 0:
143 laser_measurements[laser_id] = sub_list[0][0]
145 laser_measurements[laser_id] =
None 151 for cam_id, m
in cam_measurements.items():
153 failed_sensors.append(cam_id)
155 good_sensors.append(cam_id)
157 for chain_id, m
in chain_measurements.items():
159 failed_sensors.append(chain_id)
161 good_sensors.append(chain_id)
163 for laser_id, m
in laser_measurements.items():
165 failed_sensors.append(laser_id)
167 good_sensors.append(laser_id)
169 if len(failed_sensors) > 0:
170 if len(failed_sensors) > 1:
171 m=
"Failed to capture samples from %s"%(
', '.join(failed_sensors))
173 m=
"Failed to capture a sample from %s"%(failed_sensors[0])
177 print "Received everything!" 180 m_robot = RobotMeasurement()
181 m_robot.M_cam = cam_measurements.values()
182 m_robot.M_chain = chain_measurements.values()
183 m_robot.M_laser = laser_measurements.values()
def add_laser_measurement(self, laser_id, m, interval_start, interval_end)
def reconfigure(self, cam_ids, chain_ids, laser_ids)
def set_max_sizes(self, cam_sizes, chain_sizes, laser_sizes)
def add_chain_measurement(self, chain_id, m)
def request_robot_measurement(self, interval_start, interval_end, min_duration=rospy.Duration(2, 0))
def add_cam_measurement(self, cam_id, m)