samplerobot-test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 PKG = 'hrpsys_tutorials'
00004 import roslib; roslib.load_manifest(PKG)
00005 import rospkg
00006 
00007 import numpy
00008 import unittest
00009 
00010 import sys; sys.path.insert (0, roslib.packages.get_pkg_dir('hrpsys')+'/scripts'); ## add python
00011 from hrpsys import HrpsysConfigurator
00012 
00013 class TestSampleRobot(unittest.TestCase):
00014 
00015     @classmethod
00016     def setUpClass(self):
00017         self.robot = HrpsysConfigurator()
00018         self.robot.init("SampleRobot(Robot)0", rospkg.RosPack().get_path("openhrp3")+"/share/OpenHRP-3.1/sample/model/sample1.wrl")
00019 
00020 
00021     def test_ik(self):
00022         self.robot.seq_svc.addJointGroup("LARM", ["LARM_SHOULDER_P", "LARM_SHOULDER_R", "LARM_SHOULDER_Y", "LARM_ELBOW", "LARM_WRIST_Y", "LARM_WRIST_P", "LARM_WRIST_R"])
00023         lav = [60,0,0,-90,0,0,0]
00024         for av in [[60, 0, 0, -80, 0, 0, 0],[30, 30, 0,-80, 0, 0, 0],
00025                    [40,40,20, -20, 0, 0, 0],[30, 30,20,-80,20,0, 20]]:
00026             self.robot.setJointAnglesOfGroup("LARM", av, 5)
00027             self.robot.waitInterpolationOfGroup("LARM")
00028             pos1 = self.robot.getReferencePosition("LARM_WRIST_R")
00029             rpy1 = self.robot.getReferenceRPY("LARM_WRIST_R")
00030             self.robot.setJointAnglesOfGroup("LARM", lav, 5)
00031             self.robot.waitInterpolationOfGroup("LARM")
00032             self.assertTrue(self.robot.setTargetPose("LARM", pos1, rpy1, 10))
00033             self.robot.waitInterpolationOfGroup("LARM")
00034             pos2 = self.robot.getReferencePosition("LARM_WRIST_R")
00035             rpy2 = self.robot.getReferenceRPY("LARM_WRIST_R")
00036             print "pos", pos1, pos2, numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))
00037             print "rpy", rpy1, rpy2, numpy.linalg.norm(numpy.array(rpy1)-numpy.array(rpy2))
00038             self.assertTrue(numpy.linalg.norm(numpy.array(pos1)-numpy.array(pos2))<5.0e-3)
00039             self.assertTrue(numpy.linalg.norm(numpy.array(rpy1)-numpy.array(rpy2))<5.0e-3)
00040             lav = av
00041 
00042 
00043 
00044 if __name__ == '__main__':
00045     import rostest
00046     rostest.rosrun(PKG, 'test_samplerobot', TestSampleRobot) 
00047 
00048 
00049 
00050 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


hrpsys_tutorials
Author(s): AIST, ROS package is maintained by Kei Okada
autogenerated on Tue Jul 23 2013 11:50:52