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 import roslib; roslib.load_manifest('pr2_calibration_executive')
00035
00036 import sys
00037 import unittest
00038 import rospy
00039
00040 from pr2_calibration_executive.robot_measurement_cache import RobotMeasurementCache
00041 from calibration_msgs.msg import *
00042
00043
00044 class TestCache(unittest.TestCase):
00045
00046 def test_one_sensor_easy(self):
00047 cache = RobotMeasurementCache()
00048 cache.reconfigure(["cam1"], [], [])
00049 cache.set_max_sizes( {"cam1":100}, {}, {})
00050
00051 for n in range(1,11):
00052 msg = CameraMeasurement()
00053 msg.header.stamp = rospy.Time(n*10,0)
00054 cache.add_cam_measurement("cam1", msg)
00055
00056 m_robot = cache.request_robot_measurement(rospy.Time(19,0), rospy.Time(31,0))
00057
00058 self.assertTrue(m_robot is not None)
00059 self.assertEquals( len(m_robot.M_cam), 1 )
00060 self.assertEquals( len(m_robot.M_chain), 0 )
00061 self.assertEquals( len(m_robot.M_laser), 0 )
00062
00063 m_robot = cache.request_robot_measurement(rospy.Time(21,0), rospy.Time(29,0))
00064 self.assertTrue(m_robot is None)
00065
00066 def test_multi_cam_easy(self):
00067 cache = RobotMeasurementCache()
00068 cache.reconfigure(["cam1", "cam2"], [], [])
00069 cache.set_max_sizes( {"cam1":100, "cam2":100}, {}, {})
00070
00071 for n in range(1,11):
00072 msg = CameraMeasurement()
00073 msg.header.stamp = rospy.Time(n*10,0)
00074 cache.add_cam_measurement("cam1", msg)
00075
00076 for n in range(1,11):
00077 msg = CameraMeasurement()
00078 msg.header.stamp = rospy.Time(n*10+1,0)
00079 cache.add_cam_measurement("cam2", msg)
00080
00081 m_robot = cache.request_robot_measurement(rospy.Time(18,0), rospy.Time(32,0))
00082
00083 self.assertTrue(m_robot is not None)
00084 self.assertEquals( len(m_robot.M_cam), 2 )
00085 self.assertEquals( len(m_robot.M_chain), 0 )
00086 self.assertEquals( len(m_robot.M_laser), 0 )
00087
00088 m_robot = cache.request_robot_measurement(rospy.Time(20,0), rospy.Time(30,0))
00089 self.assertTrue(m_robot is None)
00090
00091 def test_chain_easy(self):
00092 cache = RobotMeasurementCache()
00093 cache.reconfigure([], ["chain1"], [])
00094 cache.set_max_sizes( {}, {"chain1":100}, {})
00095
00096 for n in range(1,11):
00097 msg = ChainMeasurement()
00098 msg.header.stamp = rospy.Time(n*10,0)
00099 cache.add_chain_measurement("chain1", msg)
00100
00101 m_robot = cache.request_robot_measurement(rospy.Time(18,0), rospy.Time(32,0))
00102
00103 self.assertTrue(m_robot is not None)
00104 self.assertEquals( len(m_robot.M_cam), 0 )
00105 self.assertEquals( len(m_robot.M_chain), 1 )
00106 self.assertEquals( len(m_robot.M_laser), 0 )
00107
00108 m_robot = cache.request_robot_measurement(rospy.Time(21,0), rospy.Time(29,0))
00109 self.assertTrue(m_robot is None)
00110
00111 def test_laser_easy(self):
00112 cache = RobotMeasurementCache()
00113 cache.reconfigure([], [], ["laser1"])
00114 cache.set_max_sizes( {}, {}, {"laser1":100})
00115
00116 for n in range(1,11):
00117 msg = LaserMeasurement()
00118 cache.add_laser_measurement("laser1", msg, rospy.Time(n*10,0), rospy.Time(n*10+2,0))
00119
00120 m_robot = cache.request_robot_measurement(rospy.Time(19,0), rospy.Time(32,0))
00121
00122 self.assertTrue(m_robot is not None)
00123 self.assertEquals( len(m_robot.M_cam), 0 )
00124 self.assertEquals( len(m_robot.M_chain), 0 )
00125 self.assertEquals( len(m_robot.M_laser), 1 )
00126
00127 m_robot = cache.request_robot_measurement(rospy.Time(20,0), rospy.Time(21,0))
00128 self.assertTrue(m_robot is None)
00129
00130 if __name__ == '__main__':
00131 import rostest
00132 rostest.unitrun('pr2_calibration_executive', 'test_robot_measurement_cache', TestCache)