00001 #!/usr/bin/env python 00002 00003 # Software License Agreement (BSD License) 00004 # 00005 # Copyright (c) 2013, JSK lab at University of Tokyo All rights reserved. 00006 # 00007 # Redistribution and use in source and binary forms, with or without 00008 # modification, are permitted provided that the following conditions 00009 # are met: 00010 # 00011 # * Redistributions of source code must retain the above copyright 00012 # notice, this list of conditions and the following disclaimer. 00013 # * Redistributions in binary form must reproduce the above 00014 # copyright notice, this list of conditions and the following 00015 # disclaimer in the documentation and/or other materials provided 00016 # with the distribution. 00017 # * Neither the name of University of Tokyo. nor the names of its 00018 # contributors may be used to endorse or promote products derived 00019 # from this software without specific prior written permission. 00020 # 00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 # POSSIBILITY OF SUCH DAMAGE. 00033 00034 # Author: Kenji Miyake, Isaac Isao Saito 00035 00036 # This test script needs improved so that it becomes call-able from ROS test 00037 # structure. 00038 00039 import time 00040 import unittest 00041 00042 from geometry_msgs.msg import Pose, PoseStamped 00043 from moveit_commander import MoveGroupCommander, conversions 00044 import rospy 00045 00046 _PKG = 'hironx_ros_bridge' 00047 _SEC_WAIT_BETWEEN_TESTCASES = 3 00048 00049 class TestHironxMoveit(unittest.TestCase): 00050 00051 @classmethod 00052 def setUpClass(self): 00053 00054 rospy.init_node("test_hironx_moveit") 00055 00056 self.rarm = MoveGroupCommander("right_arm") 00057 self.larm = MoveGroupCommander("left_arm") 00058 00059 self.rarm_current_pose = self.rarm.get_current_pose().pose 00060 self.larm_current_pose = self.larm.get_current_pose().pose 00061 00062 def _set_target_random(self): 00063 ''' 00064 @type self: moveit_commander.MoveGroupCommander 00065 @param self: In this particular test script, the argument "self" is either 00066 'rarm' or 'larm'. 00067 ''' 00068 global current, current2, target 00069 current = self.get_current_pose() 00070 print "*current*", current 00071 target = self.get_random_pose() 00072 print "*target*", target 00073 self.set_pose_target(target) 00074 self.go() 00075 current2 = self.get_current_pose() 00076 print "*current2*", current2 00077 00078 # Associate a method to MoveGroupCommander class. This enables users to use 00079 # the method on interpreter. 00080 # Although not sure if this is the smartest Python code, this works fine from 00081 # Python interpreter. 00082 ##MoveGroupCommander._set_target_random = _set_target_random 00083 00084 # ****** Usage ****** 00085 # 00086 # See wiki tutorial 00087 # https://code.google.com/p/rtm-ros-robotics/wiki/hironx_ros_bridge_en#Manipulate_Hiro_with_Moveit_via_Python 00088 # 00089 00090 def test_set_pose_target_rpy(self): 00091 # #rpy ver 00092 target=[0.2035, -0.5399, 0.0709, 0,-1.6,0] 00093 self.rarm.set_pose_target(target) 00094 self.rarm.go() 00095 time.sleep(_SEC_WAIT_BETWEEN_TESTCASES) 00096 00097 def test_set_pose_target_quarternion(self): 00098 # #Quaternion ver 00099 target2=[0.2035, -0.5399, 0.0709, 0.000427, 0.000317, -0.000384, 0.999999] 00100 self.rarm.set_pose_target(target2) 00101 self.rarm.go() 00102 time.sleep(_SEC_WAIT_BETWEEN_TESTCASES) 00103 00104 if __name__ == '__main__': 00105 import rostest 00106 rostest.rosrun(_PKG, 'test_hironx_moveit_run', TestHironxMoveit)