test_hironx_derivedmethods_rostest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2014, Tokyo Opensource Robotics Kyokai Association
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
00019 #    names of its contributors may be used to endorse or promote products
00020 #    derived from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 #
00035 # Author: Isaac Isao Saito
00036 
00037 import unittest
00038 
00039 import rospy
00040 from hrpsys import rtm
00041 
00042 from hironx_ros_bridge import hironx_client as hironx
00043 
00044 _ARMGROUP_TESTED = 'larm'
00045 _GOINITIAL_TIME_MIDSPEED = 3  # second
00046 _JOINT_TESTED = (14, 'LARM_JOINT5')  # (%INDEX_IN_LINKGROUP%, %NAME_JOINT%)
00047 _PKG = 'nextage_ros_bridge'
00048 _POSE_LARM_JOINT5 = [-0.0017695671419774017, 0.00019009187609567157,
00049                      -0.99999841624735, 0.3255751238415409,
00050                      0.00012113080903022877, 0.9999999746368694,
00051                      0.00018987782289436872, 0.18236314012331808,
00052                      0.9999984269784911, -0.00012079461563276815,
00053                      -0.0017695901230784174, 1.037624522677471,
00054                      0.0, 0.0, 0.0, 1.0]  # At goInitial.
00055 _INDICES_POSITION = 3, 7, 11  # In pose returned by getCurrentPose.
00056 
00057 
00058 class TestHironxDerivedmethodsFromHrpsys(unittest.TestCase):
00059     '''
00060     Test the derived methods of hrpsys_config.HrpsysConfigurator that are
00061     overridden in hironx_client.HIRONX.
00062 
00063     So far this test can be run by:
00064 
00065         $ rosrun nextage_ros_bridge test_hironx_derivedmethods_rostest.py
00066 
00067     #TODO: rostest (ie. boot from .launch file) not passing with this script
00068     #      for some reasons. Unless this test requires other nodes running,
00069     #      we might not need to run this from .launch?
00070 
00071     #TODO: Merge with the existing unittest scripts in hironx_ros_bridge/test
00072     '''
00073 
00074     @classmethod
00075     def setUpClass(self):
00076         # Robot info tentatively embedded.
00077         modelfile = '/opt/jsk/etc/NEXTAGE/model/main.wrl'
00078         rtm.nshost = 'nxc100'
00079         robotname = "RobotHardware0"
00080 
00081         self._robot = hironx.HIRONX()
00082         self._robot.init(robotname=robotname, url=modelfile)
00083         #TODO: If servo is off, return failure and inform user.
00084 
00085     @classmethod
00086     def tearDownClass(cls):
00087         cls._robot.goOffPose()
00088         True
00089 
00090     def test_setJointAngle_within_pi(self):
00091         # TODO: setJointAngle does not work as expected for me on
00092         # hrpsys_simulator. Therefore make this case always fail for now..
00093         self.assertFalse(True)
00094 
00095     def test_setJointAngle_beyond_pi(self):
00096         # TODO: setJointAngle does not work as expected for me on
00097         # hrpsys_simulator. Therefore make this case always fail for now..
00098         self.assertFalse(True)
00099 
00100     def test_getCurrentPose(self):
00101         self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
00102         pos = self._robot.getCurrentPose(_JOINT_TESTED[1])
00103         rospy.loginfo('test_getCurrentPose compare pos={},' +
00104                       '\n\tPOSE_LARM_JOINT5={}'.format(pos, _POSE_LARM_JOINT5))
00105         self.assertEqual(pos, _POSE_LARM_JOINT5)
00106 
00107     def test_getCurrentPosition(self):
00108         self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
00109         pose = self._robot.getCurrentPose(_JOINT_TESTED[1])
00110         position_from_getcurrentposition = self._robot.getCurrentPosition(
00111             _JOINT_TESTED[1])
00112         position_from_pose = [i for j,
00113                               i in enumerate(pose) if j in _INDICES_POSITION]
00114         rospy.loginfo('test_getCurrentPosition compare position_from_getcurrentposition={},' +
00115                       '\n\tposition_from_pose={}'.format(
00116                           position_from_getcurrentposition, position_from_pose))
00117         self.assertEqual(position_from_getcurrentposition, position_from_pose)
00118 
00119     def test_getCurrentRotation(self):
00120         self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
00121         rot_matrix = self._robot.getCurrentRotation(_JOINT_TESTED[1])
00122         #TODO: Come up with ways to assert the returned value.
00123 
00124     def test_getCurrentRPY(self):
00125         self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
00126         rpy = self._robot.getCurrentRPY(_JOINT_TESTED[1])
00127         #TODO: Come up with ways to assert the returned value.
00128 
00129     def test_getJointAngles(self):
00130         self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
00131         joint_angles = self._robot.getJointAngles()
00132 
00133         # TODO: statically assigning LARM_JOINT5
00134         self.assertEqual(self._robot.InitialPose[3][5],
00135                          joint_angles[_JOINT_TESTED[0]])
00136 
00137 if __name__ == '__main__':
00138     import rostest
00139     rostest.rosrun(_PKG, 'test_hironx_derivedmethods',
00140                    TestHironxDerivedmethodsFromHrpsys)


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed May 15 2019 04:45:36