test_calib_chest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2017, TORK (Tokyo Opensource Robotics Kyokai Association)
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Tokyo Opensource Robotics Kyokai Association
20 # nor the names of its contributors may be used to endorse or promote
21 # products derived from this software without specific prior written
22 # permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 # POSSIBILITY OF SUCH DAMAGE.
36 
37 # Author: Isaac I.Y. Saito
38 
39 import numpy
40 import unittest
41 
42 import time
43 import rospy
44 import tf
45 from tf.transformations import quaternion_from_euler
46 
47 class TestNxoCalib(unittest.TestCase):
48 
49  def setUp(self):
50  rospy.init_node('test_calib')
52  # wait for tf
53  time.sleep(2) # need to wait to initialize listener
54  while len(self.tflistener.getFrameStrings()) < 10:
55  time.sleep(2) # need to wait to initialize listener
56  rospy.loginfo(self.tflistener.getFrameStrings())
57  rospy.loginfo(self.tflistener.getFrameStrings())
58 
59  def tearDown(self):
60  True #TODO impl something meaningful
61 
63  '''
64  @summary: Check if the translation between 2 frames, head and
65  the camera mounted on top of the head, fall into the intended
66  range. See the image if you want to get an idea of these 2
67  frames: https://cloud.githubusercontent.com/assets/3119480/22644078/8858459c-eca4-11e6-9fb5-4b624d79d499.png
68  '''
69  FRAME_CAMERA = "/camera_link"
70  FRAME_HEAD = "/HEAD_JOINT1_Link"
71  TRANS_EXPECTED = [0.103, -0.023, 0.171]
72  QUARTERNION_EXPECTED = [0.002, 0.706, -0.002, 0.708]
73 
74  # frameExisits does not work with tf_static?
75  #self.assertTrue(self.tflistener.frameExists(FRAME_HEAD))
76  rospy.loginfo("Check if {} exists".format(FRAME_HEAD))
77  self.assertTrue(self.tflistener.lookupTransform(FRAME_HEAD, FRAME_HEAD, rospy.Time(0)), "Frame {} does not exists".format(FRAME_HEAD))
78  rospy.loginfo("Check if {} exists".format(FRAME_CAMERA))
79  self.assertTrue(self.tflistener.lookupTransform(FRAME_CAMERA, FRAME_CAMERA, rospy.Time(0)), "Frame {} does not exists".format(FRAME_CAMERA))
80 
81  return True
82  # TODO need to find checker board within travis
83  t = None
84  while t == None:
85  try :
86  time.sleep(2) # need to wait to initialize listener
87  rospy.loginfo("Get common time between {} and {}".format(FRAME_HEAD, FRAME_CAMERA))
88  t = self.tflistener.getLatestCommonTime(FRAME_HEAD, FRAME_CAMERA)
89  rospy.loginfo(t)
90  except:
91  pass
92  # These tests are too difficult
93  pos, quaternion = self.tflistener.lookupTransform(FRAME_HEAD, FRAME_CAMERA, t)
94  numpy.testing.assert_almost_equal(pos, TRANS_EXPECTED, 2)
95  numpy.testing.assert_almost_equal(quaternion, QUARTERNION_EXPECTED, 2)
96 
97 if __name__ == '__main__':
98  import rostest
99  rostest.rosrun('nextage_calibration', 'test_calib', TestNxoCalib)
100 


nextage_calibration
Author(s): Yosuke Yamamoto, TORK
autogenerated on Wed Jun 17 2020 04:15:19