test_hironx_ros_bridge_controller.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) 2014, JSK Lab, University of Tokyo
00007 # Copyright (c) 2014, TORK
00008 # All rights reserved.
00009 #
00010 # Redistribution and use in source and binary forms, with or without
00011 # modification, are permitted provided that the following conditions
00012 # are met:
00013 #
00014 #  * Redistributions of source code must retain the above copyright
00015 #    notice, this list of conditions and the following disclaimer.
00016 #  * Redistributions in binary form must reproduce the above
00017 #    copyright notice, this list of conditions and the following
00018 #    disclaimer in the documentation and/or other materials provided
00019 #    with the distribution.
00020 #  * Neither the name of JSK Lab, University of Tokyo, TORK, nor the
00021 #    names of its contributors may be used to endorse or promote products
00022 #    derived from this software without specific prior written 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 import numpy
00038 import rospy
00039 from tf.transformations import quaternion_matrix, euler_from_matrix
00040 import time
00041 
00042 from hironx_ros_bridge.testutil.test_rosbridge import TestHiroROSBridge
00043 
00044 PKG = 'hironx_ros_bridge'
00045 
00046 
00047 class TestHiroROSBridgeController(TestHiroROSBridge):
00048 
00049     def test_tf_and_controller(self):
00050         goal = self.goal_RArm()
00051         for av in [[-0.6, 0, -100, 15.2, 9.4, 3.2]]: #[  25,-139,-157,  45,   0,   0]]:
00052             goal = self.setup_Positions(goal, [av])
00053             self.rarm.send_goal_and_wait(goal)
00054             # check if tf and current link is same
00055             rospy.sleep(1)
00056             now = rospy.Time.now()
00057             self.listener.waitForTransform("WAIST", "RARM_JOINT5_Link", now, rospy.Duration(1.0))
00058             (pos_tf, rot_tf) = self.listener.lookupTransform("WAIST", "RARM_JOINT5_Link", now)
00059             rot_tf = quaternion_matrix(rot_tf)[0:3,0:3]
00060             pos_c = self.robot.getCurrentPosition('RARM_JOINT5','WAIST')
00061             rot_c = self.robot.getCurrentRotation('RARM_JOINT5','WAIST')
00062             numpy.testing.assert_array_almost_equal(pos_tf, pos_c, decimal=3)
00063             numpy.testing.assert_array_almost_equal(rot_tf, rot_c, decimal=2)
00064 
00065         goal = self.goal_LArm()
00066         for av in [[0.6, 0, -100, -15.2, 9.4, -3.2]]: #[  25,-139,-157,  45,   0,   0]]:
00067             goal = self.setup_Positions(goal, [av])
00068             self.larm.send_goal_and_wait(goal)
00069             # check if tf and current link is same
00070             rospy.sleep(1)
00071             now = rospy.Time.now()
00072             self.listener.waitForTransform("WAIST", "LARM_JOINT5_Link", now, rospy.Duration(1.0))
00073             (pos_tf, rot_tf) = self.listener.lookupTransform("WAIST", "LARM_JOINT5_Link", now)
00074             rot_tf = quaternion_matrix(rot_tf)[0:3,0:3]
00075             pos_c = self.robot.getCurrentPosition('LARM_JOINT5','WAIST')
00076             rot_c = self.robot.getCurrentRotation('LARM_JOINT5','WAIST')
00077             numpy.testing.assert_array_almost_equal(pos_tf, pos_c, decimal=3)
00078             numpy.testing.assert_array_almost_equal(rot_tf, rot_c, decimal=2)
00079 
00080 if __name__ == '__main__':
00081     import rostest
00082     rostest.rosrun(PKG, 'test_hronx_ros_bridge_controller', TestHiroROSBridgeController)
00083 
00084 
00085 


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu Feb 21 2019 03:42:37