test_hironx_ik.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 PKG = 'hironx_ros_bridge'
5 # rosbuild needs load_manifest
6 try:
7  import roslib
8  import hironx_ros_bridge
9 except:
10  import roslib; roslib.load_manifest(PKG)
11  import hironx_ros_bridge
12 
13 from hironx_ros_bridge import hironx_client as hironx
14 from hrpsys import rtm
15 from hrpsys.hrpsys_config import euler_from_matrix
16 
17 import numpy
18 import unittest
19 import time
20 import tempfile
21 
22 import random
23 import numpy as np
24 
25 from rtm import connectPorts, disconnectPorts
26 
27 from distutils.version import StrictVersion
28 
29 class TestHiroIK(unittest.TestCase):
30 
31  @classmethod
32  def setUpClass(self):
33  #modelfile = rospy.get_param("hironx/collada_model_filepath")
34  #rtm.nshost = 'hiro014'
35  #robotname = "RobotHardware0"
36 
37  self.robot = hironx.HIRONX()
38  #self.robot.init(robotname=robotname, url=modelfile)
39  self.robot.init()
40 
42  for i0 in range(-80,80,80):
43  for i1 in range(-130,50,90):
44  for i2 in range(-150,10,80):
45  for i3 in range(-160,100,130):
46  for i4 in range(-80,80,80):
47  for i5 in range(-160,160,160):
48  yield [i0, i1, i2, i3, i4, i5]
49 
50 # 3/9/2014 Isaac comments out the entire test_ik_joint_angle that can cause left arm to hit its shoulder.
51 # def test_ik_joint_angle(self):
52 # lav = self.angle_vector_generator().next()
53 # for av in self.angle_vector_generator():
54 # print "av", av
55 # self.robot.setJointAnglesOfGroup("LARM", av, 2)
56 # self.robot.waitInterpolationOfGroup("LARM")
57 # pos1 = self.robot.getReferencePosition("LARM_JOINT5")
58 # rpy1 = self.robot.getReferenceRPY("LARM_JOINT5")
59 # if numpy.linalg.norm(numpy.array(lav) - numpy.array(av)) > 10:
60 # lav = av
61 # self.robot.setJointAnglesOfGroup("LARM", lav, 2)
62 # self.robot.waitInterpolationOfGroup("LARM")
63 # self.assertTrue(self.robot.setTargetPose("LARM", pos1, rpy1, 5))
64 # self.robot.waitInterpolationOfGroup("LARM")
65 # pos2 = self.robot.getReferencePosition("LARM_JOINT5")
66 # rpy2 = self.robot.getReferenceRPY("LARM_JOINT5")
67 # print "pos", pos1, pos2, numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))
68 # print "rpy", rpy1, rpy2, numpy.linalg.norm(numpy.array(rpy1)-numpy.array(rpy2))
69 # self.assertTrue(numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))<1.0e-4) # 0.1 mm
70 # self.assertTrue(numpy.linalg.norm(numpy.array(rpy1)-numpy.array(rpy2))<1.0e-3) # 0.001 rad = 0.057296 deg
71 # lav = av
72 
73  def target_point_generator(self,xmin,xmax,ymin,ymax,zmin,zmax,step):
74  for x in range(xmin,xmax,step):
75  for y in range(ymin,ymax,step):
76  for z in range (zmin,zmax,step):
77  yield [x/1000.0, y/1000.0, z/1000.0]
78 
79  def test_ik_left(self):
80  self.pos_ik_test("LARM", 220,400, -5,320, 5,300, 100) # zmax=390
81 
82  def test_ik_right(self):
83  self.pos_ik_test("RARM", 220,400, -320,5, 5,300, 100) # zmax=390
84 
85  def pos_ik_test(self, arm, xmin,xmax,ymin,ymax,zmin,zmax,step):
86  arm_target = arm+"_JOINT5"
87  rot1 = [[0,0,-1],[0,1,0],[1,0,0]]
88  for pos1 in self.target_point_generator(xmin,xmax,ymin,ymax,zmin,zmax,step):
89  self.robot.goInitial(tm=2)
90  print self.robot.getReferenceRPY(arm_target)
91  self.assertTrue(self.robot.setTargetPose(arm, pos1, euler_from_matrix(rot1), 1))
92  self.robot.waitInterpolationOfGroup(arm)
93  pos2 = self.robot.getReferencePosition(arm_target)
94  rot2 = self.robot.getReferenceRotation(arm_target)
95  print "pos", pos1, pos2, numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))
96  print "rpy", rot1, rot2, numpy.linalg.norm(numpy.array(rot1)-numpy.array(rot2))
97  self.assertTrue(numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))<1.0e-4) # 0.1 mm
98  self.assertTrue(numpy.linalg.norm(numpy.array(rot1)-numpy.array(rot2))<1.0e-3) # 0.001 rad = 0.057296 deg
99 
101  self.robot.setJointAnglesOfGroup("TORSO",[45],3)
102  self.robot.waitInterpolationOfGroup("TORSO")
103  ret = self.robot.setTargetPose("larm", [0.3255627368715471, 0.1823638733778268, 0.07462449717662004+0.2], [-3.0732189053889805, -1.5690225912054285, 3.0730289207320203], 5, "CHEST_JOINT0")
104  self.assertTrue(ret)
105 
107  if StrictVersion(self.robot.hrpsys_version) < StrictVersion('315.5.0'):
108  return
109  self.robot.goInitial(tm=3)
110  # https://github.com/tork-a/rtmros_nextage/issues/332
111  self.robot.connectLoggerPort(self.robot.el, 'beepCommand') # Just for checking
112  ret = self.robot.setTargetPose("larm", [0.3255627368715471, 0.1823638733778268, 0.07462449717662004+0.2], [-3.0732189053889805, -1.5690225912054285, 3.0730289207320203], 5, "CHEST_JOINT0")
113  self.robot.waitInterpolationOfGroup("larm")
114  self.assertTrue(ret)
115 
116  ret = self.robot.setTargetPose("larm", [0.3255627368715471, 0.1823638733778268, 0.07462449717662004-0.1], [-3.0732189053889805, -1.5690225912054285, 3.0730289207320203], 5, "CHEST_JOINT0")
117  import time
118  time.sleep(1)
119  self.robot.clearOfGroup('larm')
120  self.assertTrue(ret)
121 
122  self.robot.clearLog()
123  self.robot.setMaxLogLength(2000)
124  ret = self.robot.setTargetPose("larm", [0.3255627368715471, 0.1823638733778268, 0.07462449717662004+0.2], [-3.0732189053889805, -1.5690225912054285, 3.0730289207320203], 5, "CHEST_JOINT0")
125  self.robot.waitInterpolationOfGroup("larm")
126  self.robot.saveLog(fname='/tmp/test_hironx_ik')
127  print("check /tmp/test_hironx_ik.el_beepCommand")
128  fp = open('/tmp/test_hironx_ik.el_beepCommand', "r")
129  for l in fp:
130  print l
131  assert(False)
132 
133 
134  def test_set_target_pose_relative_319(self): # https://github.com/start-jsk/rtmros_hironx/issues/319
135  self.robot.goInitial(tm=3)
136  ret = self.robot.setTargetPoseRelative('larm', 'LARM_JOINT5', dz=0.01, tm=0.5)
137  self.assertTrue(ret)
138  ret = self.robot.setTargetPoseRelative('larm', 'LARM_JOINT5', dz=0, tm=0.5)
139  self.assertTrue(ret)
140 
141 # for debug
142 # $ python -m unittest test_hironx_ik.TestHiroIK.test_set_target_pose
143 #
144 if __name__ == '__main__':
145  import rostest
146  rostest.rosrun(PKG, 'test_hronx_ik', TestHiroIK)
def test_set_target_pose_relative_319(self)
def target_point_generator(self, xmin, xmax, ymin, ymax, zmin, zmax, step)
def pos_ik_test(self, arm, xmin, xmax, ymin, ymax, zmin, zmax, step)


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