test_calib_chest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 # Software License Agreement (BSD License)
00005 #
00006 # Copyright (c) 2017, TORK (Tokyo Opensource Robotics Kyokai Association) 
00007 # All rights reserved.
00008 #
00009 # Redistribution and use in source and binary forms, with or without
00010 # modification, are permitted provided that the following conditions
00011 # are met:
00012 #
00013 #  * Redistributions of source code must retain the above copyright
00014 #    notice, this list of conditions and the following disclaimer.
00015 #  * Redistributions in binary form must reproduce the above
00016 #    copyright notice, this list of conditions and the following
00017 #    disclaimer in the documentation and/or other materials provided
00018 #    with the distribution.
00019 #  * Neither the name of Tokyo Opensource Robotics Kyokai Association
00020 #    nor the names of its contributors may be used to endorse or promote 
00021 #    products derived from this software without specific prior written 
00022 #    permission.
00023 #
00024 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035 # POSSIBILITY OF SUCH DAMAGE.
00036 
00037 # Author: Isaac I.Y. Saito
00038 
00039 import numpy
00040 import unittest
00041 
00042 import time
00043 import rospy
00044 import tf
00045 from tf.transformations import quaternion_from_euler
00046 
00047 class TestNxoCalib(unittest.TestCase):
00048 
00049     def setUp(self):
00050         rospy.init_node('test_calib')
00051         self.tflistener = tf.TransformListener()
00052         # wait for tf
00053         time.sleep(2) # need to wait to initialize listener
00054         while len(self.tflistener.getFrameStrings()) < 10:
00055             time.sleep(2) # need to wait to initialize listener
00056             rospy.loginfo(self.tflistener.getFrameStrings())
00057         rospy.loginfo(self.tflistener.getFrameStrings())
00058 
00059     def tearDown(self):
00060         True  #TODO impl something meaningful
00061 
00062     def test_tf_head_checkerboard_chest(self):
00063         '''
00064         @summary: Check if the translation between 2 frames, head and
00065                   the camera mounted on top of the head, fall into the intended
00066                   range. See the image if you want to get an idea of these 2
00067                   frames: https://cloud.githubusercontent.com/assets/3119480/22644078/8858459c-eca4-11e6-9fb5-4b624d79d499.png
00068         '''
00069         FRAME_CAMERA = "/camera_link"
00070         FRAME_HEAD = "/HEAD_JOINT1_Link"
00071         TRANS_EXPECTED = [0.103, -0.023, 0.171]
00072         QUARTERNION_EXPECTED = [0.002, 0.706, -0.002, 0.708]
00073 
00074         # frameExisits does not work with tf_static?
00075         #self.assertTrue(self.tflistener.frameExists(FRAME_HEAD))
00076         rospy.loginfo("Check if {} exists".format(FRAME_HEAD))
00077         self.assertTrue(self.tflistener.lookupTransform(FRAME_HEAD, FRAME_HEAD, rospy.Time(0)), "Frame {} does not exists".format(FRAME_HEAD))
00078         rospy.loginfo("Check if {} exists".format(FRAME_CAMERA))
00079         self.assertTrue(self.tflistener.lookupTransform(FRAME_CAMERA, FRAME_CAMERA, rospy.Time(0)), "Frame {} does not exists".format(FRAME_CAMERA))
00080 
00081         return True
00082         # TODO need to find checker board within travis
00083         t = None
00084         while t == None:
00085             try :
00086                 time.sleep(2) # need to wait to initialize listener
00087                 rospy.loginfo("Get common time between {} and {}".format(FRAME_HEAD, FRAME_CAMERA))
00088                 t = self.tflistener.getLatestCommonTime(FRAME_HEAD, FRAME_CAMERA)
00089                 rospy.loginfo(t)
00090             except:
00091                 pass
00092         # These tests are too difficult
00093         pos, quaternion = self.tflistener.lookupTransform(FRAME_HEAD, FRAME_CAMERA, t)
00094         numpy.testing.assert_almost_equal(pos, TRANS_EXPECTED, 2)
00095         numpy.testing.assert_almost_equal(quaternion, QUARTERNION_EXPECTED, 2)
00096 
00097 if __name__ == '__main__':
00098     import rostest
00099     rostest.rosrun('nextage_calibration', 'test_calib', TestNxoCalib)
00100 


nextage_calibration
Author(s): Yosuke Yamamoto, TORK
autogenerated on Wed May 15 2019 04:46:59