test_hironx_derivedmethods_rostest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2014, Tokyo Opensource Robotics Kyokai Association
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
19 # names of its contributors may be used to endorse or promote products
20 # derived from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Author: Isaac Isao Saito
36 
37 import unittest
38 
39 import rospy
40 from hrpsys import rtm
41 
42 from hironx_ros_bridge import hironx_client as hironx
43 
44 _ARMGROUP_TESTED = 'larm'
45 _GOINITIAL_TIME_MIDSPEED = 3 # second
46 _JOINT_TESTED = (14, 'LARM_JOINT5') # (%INDEX_IN_LINKGROUP%, %NAME_JOINT%)
47 _PKG = 'nextage_ros_bridge'
48 _POSE_LARM_JOINT5 = [-0.0017695671419774017, 0.00019009187609567157,
49  -0.99999841624735, 0.3255751238415409,
50  0.00012113080903022877, 0.9999999746368694,
51  0.00018987782289436872, 0.18236314012331808,
52  0.9999984269784911, -0.00012079461563276815,
53  -0.0017695901230784174, 1.037624522677471,
54  0.0, 0.0, 0.0, 1.0] # At goInitial.
55 _INDICES_POSITION = 3, 7, 11 # In pose returned by getCurrentPose.
56 
57 
58 class TestHironxDerivedmethodsFromHrpsys(unittest.TestCase):
59  '''
60  Test the derived methods of hrpsys_config.HrpsysConfigurator that are
61  overridden in hironx_client.HIRONX.
62 
63  So far this test can be run by:
64 
65  $ rosrun nextage_ros_bridge test_hironx_derivedmethods_rostest.py
66 
67  #TODO: rostest (ie. boot from .launch file) not passing with this script
68  # for some reasons. Unless this test requires other nodes running,
69  # we might not need to run this from .launch?
70 
71  #TODO: Merge with the existing unittest scripts in hironx_ros_bridge/test
72  '''
73 
74  @classmethod
75  def setUpClass(self):
76  # Robot info tentatively embedded.
77  modelfile = '/opt/jsk/etc/NEXTAGE/model/main.wrl'
78  rtm.nshost = 'nxc100'
79  robotname = "RobotHardware0"
80 
81  self._robot = hironx.HIRONX()
82  self._robot.init(robotname=robotname, url=modelfile)
83  #TODO: If servo is off, return failure and inform user.
84 
85  @classmethod
86  def tearDownClass(cls):
87  cls._robot.goOffPose()
88  True
89 
91  # TODO: setJointAngle does not work as expected for me on
92  # hrpsys_simulator. Therefore make this case always fail for now..
93  self.assertFalse(True)
94 
96  # TODO: setJointAngle does not work as expected for me on
97  # hrpsys_simulator. Therefore make this case always fail for now..
98  self.assertFalse(True)
99 
101  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
102  pos = self._robot.getCurrentPose(_JOINT_TESTED[1])
103  rospy.loginfo('test_getCurrentPose compare pos={},' +
104  '\n\tPOSE_LARM_JOINT5={}'.format(pos, _POSE_LARM_JOINT5))
105  self.assertEqual(pos, _POSE_LARM_JOINT5)
106 
108  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
109  pose = self._robot.getCurrentPose(_JOINT_TESTED[1])
110  position_from_getcurrentposition = self._robot.getCurrentPosition(
111  _JOINT_TESTED[1])
112  position_from_pose = [i for j,
113  i in enumerate(pose) if j in _INDICES_POSITION]
114  rospy.loginfo('test_getCurrentPosition compare position_from_getcurrentposition={},' +
115  '\n\tposition_from_pose={}'.format(
116  position_from_getcurrentposition, position_from_pose))
117  self.assertEqual(position_from_getcurrentposition, position_from_pose)
118 
120  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
121  rot_matrix = self._robot.getCurrentRotation(_JOINT_TESTED[1])
122  #TODO: Come up with ways to assert the returned value.
123 
125  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
126  rpy = self._robot.getCurrentRPY(_JOINT_TESTED[1])
127  #TODO: Come up with ways to assert the returned value.
128 
130  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
131  joint_angles = self._robot.getJointAngles()
132 
133  # TODO: statically assigning LARM_JOINT5
134  self.assertEqual(self._robot.InitialPose[3][5],
135  joint_angles[_JOINT_TESTED[0]])
136 
137 if __name__ == '__main__':
138  import rostest
139  rostest.rosrun(_PKG, 'test_hironx_derivedmethods',
140  TestHironxDerivedmethodsFromHrpsys)


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47