test_hironx_cartesian.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) 2013, 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. nor the
20 # names of its contributors may be used to endorse or promote products
21 # derived from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 #
36 # Author: Isaac Isao Saito
37 
38 # This should come earlier than later import.
39 # See http://code.google.com/p/rtm-ros-robotics/source/detail?r=6773
40 import unittest
41 import numpy
42 
43 from hironx_ros_bridge import hironx_client as hironx
44 from hrpsys import rtm
45 
46 _ARMGROUP_TESTED = 'larm'
47 _LINK_TESTED = 'LARM_JOINT5'
48 _GOINITIAL_TIME_MIDSPEED = 3 # second
49 _NUM_CARTESIAN_ITERATION = 300
50 _PKG = 'nextage_ros_bridge'
51 
52 
53 class TestNextageopen(unittest.TestCase):
54  '''
55  Test NextageClient with rostest.
56  '''
57 
58  @classmethod
59  def setUpClass(self):
60 
61  #modelfile = rospy.get_param("hironx/collada_model_filepath")
62  #rtm.nshost = 'hiro024'
63  #robotname = "RobotHardware0"
64 
65  self._robot = hironx.HIRONX()
66  #self._robot.init(robotname=robotname, url=modelfile)
67  self._robot.init()
68 
69  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
70 
71 # def test_set_relative_x(self):
72  def _set_relative(self, dx=0, dy=0, dz=0):
73  #print('Start moving dx={0}, dy={0}, dz={0}'.format(dx, dy, dz))
74  self._robot.seq_svc.setMaxIKError(0.00001, 0.01)
75  posi_prev = self._robot.getCurrentPosition(_LINK_TESTED)
76  for i in range(_NUM_CARTESIAN_ITERATION):
77  self._robot.setTargetPoseRelative(_ARMGROUP_TESTED,
78  _LINK_TESTED, dx, dy, dz, tm=0.15)
79  #print(' joint=', nxc.getJointAngles()[3:9])
80  posi_post = self._robot.getCurrentPosition(_LINK_TESTED)
81 
82  diff_result = posi_prev
83  for i in range(len(posi_prev)):
84  diff_result[i] = posi_post[i] - posi_prev[i]
85  diff_expected = _NUM_CARTESIAN_ITERATION*numpy.array([dx,dy,dz])
86  diff_result = numpy.array(diff_result)
87  print('Position diff={}, expected={}'.format(diff_result, diff_expected))
88  numpy.testing.assert_array_almost_equal(diff_result, diff_expected, decimal=3)
89  return True
90 
92  assert(self._set_relative(dx=0.0001))
93  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
94 
96  assert(self._set_relative(dy=0.0001))
97  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
98 
100  assert(self._set_relative(dz=0.0001))
101  self._robot.goInitial(_GOINITIAL_TIME_MIDSPEED)
102 
103 # unittest.main()
104 if __name__ == '__main__':
105  import rostest
106  rostest.rosrun(_PKG, 'test_nxopen', TestNextageopen)
def _set_relative(self, dx=0, dy=0, dz=0)


hironx_ros_bridge
Author(s): Kei Okada , Isaac I.Y. Saito
autogenerated on Thu May 14 2020 03:52:05