test_robot_measurement_cache.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import roslib; roslib.load_manifest('calibration_launch')
00035 
00036 import sys
00037 import unittest
00038 import rospy
00039 
00040 from capture_executive.robot_measurement_cache import RobotMeasurementCache
00041 from calibration_msgs.msg import *
00042 
00043 ## A sample python unit test
00044 class TestCache(unittest.TestCase):
00045     ## test 1 == 1
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)


calibration_launch
Author(s): Michael Ferguson
autogenerated on Tue Sep 27 2016 04:06:51