test_hironx_moveit.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2015, Tokyo Opensource Robotics Kyokai Association 
00006 # (TORK) All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of TORK. nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 # Author: Isaac I.Y. Saito
00036 
00037 # This test script needs improved so that it becomes call-able from ROS test
00038 # structure.
00039 
00040 import numpy
00041 import time
00042 import unittest
00043 
00044 from geometry_msgs.msg import Pose, PoseStamped
00045 from moveit_commander import MoveGroupCommander, conversions
00046 import rospy
00047 
00048 _PKG = 'hironx_ros_bridge'
00049 _SEC_WAIT_BETWEEN_TESTCASES = 3
00050 
00051 class TestHironxMoveit(unittest.TestCase):
00052 
00053     def __init__(self, *args, **kwargs):
00054         super(TestHironxMoveit, self).__init__(*args, **kwargs)
00055 
00056     @classmethod
00057     def setUpClass(self):
00058 
00059         rospy.init_node("test_hironx_moveit")
00060 
00061         self.rarm = MoveGroupCommander("right_arm")
00062         self.larm = MoveGroupCommander("left_arm")
00063         self.botharms = MoveGroupCommander("both_arm")
00064 
00065         # Tentative workaround for https://github.com/tork-a/rtmros_nextage/issues/170
00066         safe_kinematicsolver = "RRTConnectkConfigDefault"
00067         self.larm.set_planner_id(safe_kinematicsolver)
00068         self.rarm.set_planner_id(safe_kinematicsolver)
00069         self.botharms.set_planner_id(safe_kinematicsolver)
00070 
00071         self._botharms_joints = ['LARM_JOINT0', 'LARM_JOINT1',
00072                                  'LARM_JOINT2', 'LARM_JOINT3',
00073                                  'LARM_JOINT4', 'LARM_JOINT5',
00074                                  'RARM_JOINT0', 'RARM_JOINT1',
00075                                  'RARM_JOINT2', 'RARM_JOINT3',
00076                                  'RARM_JOINT4', 'RARM_JOINT5']
00077 
00078         self.rarm_current_pose = self.rarm.get_current_pose().pose
00079         self.larm_current_pose = self.larm.get_current_pose().pose
00080         # For botharms get_current_pose ends with no eef error.
00081 
00082         self.init_rtm_jointvals = [0.010471975511965976, 0.0, -1.7453292519943295, -0.26529004630313807, 0.16406094968746698, -0.05585053606381855, -0.010471975511965976, 0.0, -1.7453292519943295, 0.26529004630313807, 0.16406094968746698, 0.05585053606381855]
00083 
00084         # These represent a pose as in the image https://goo.gl/hYa15h
00085         self.banzai_pose_larm_goal = [-0.0280391167993, 0.558512828409, 0.584801820449, 0.468552399035, -0.546097642377, -0.449475560632, 0.529346516701]
00086         self.banzai_pose_rarm_goal = [0.0765219167208, -0.527210000725, 0.638387081642, -0.185009037721, -0.683111796219, 0.184872589841, 0.681873929223]
00087         self.banzai_jointvals_goal = [1.3591412928962834, -1.5269810342586994, -1.5263864987632225, -0.212938998306429, -0.19093239258017988, -1.5171864827145887,
00088                                       -0.7066724299606867, -1.9314110634425135, -1.4268663042616962, 1.0613942164863952, 0.9037643195141568, 1.835342100423069]
00089 
00090     def _set_target_random(self):
00091         '''
00092         @type self: moveit_commander.MoveGroupCommander
00093         @param self: In this particular test script, the argument "self" is either
00094                      'rarm' or 'larm'.
00095         '''
00096         global current, current2, target
00097         current = self.get_current_pose()
00098         print "*current*", current
00099         target = self.get_random_pose()
00100         print "*target*", target
00101         self.set_pose_target(target)
00102         self.go()
00103         current2 = self.get_current_pose()
00104         print "*current2*", current2
00105 
00106     # Associate a method to MoveGroupCommander class. This enables users to use
00107     # the method on interpreter.
00108     # Although not sure if this is the smartest Python code, this works fine from
00109     # Python interpreter.
00110     ##MoveGroupCommander._set_target_random = _set_target_random
00111     
00112     # ****** Usage ******
00113     #
00114     # See wiki tutorial
00115     #  https://code.google.com/p/rtm-ros-robotics/wiki/hironx_ros_bridge_en#Manipulate_Hiro_with_Moveit_via_Python
00116 
00117     def test_set_pose_target_rpy(self):
00118         # #rpy ver
00119         target = [0.2035, -0.5399, 0.0709, 0,-1.6,0]
00120         self.rarm.set_pose_target(target)
00121         self.rarm.plan()
00122         self.assertTrue(self.rarm.go())
00123 
00124     def test_set_pose_target_quarternion(self):
00125         target = [0.2035, -0.5399, 0.0709, 0.000427, 0.000317, -0.000384, 0.999999]
00126         self.rarm.set_pose_target(target)
00127         self.rarm.plan()
00128         self.assertTrue(self.rarm.go())
00129 
00130     def test_botharms_compare_joints(self):
00131         '''Comparing joint names.'''
00132         self.assertItemsEqual(self.botharms.get_joints(), self._botharms_joints)
00133 
00134     def test_botharms_get_joint_values(self):
00135         '''
00136         "both_arm" move group can't set pose target for now (July, 2015) due to 
00137         missing eef in the moveit config. Here checking if MoveGroup.get_joint_values is working.
00138         '''
00139 
00140         self.larm.set_pose_target(self.banzai_pose_larm_goal)
00141         self.larm.plan()
00142         self.larm.go()
00143         self.rarm.set_pose_target(self.banzai_pose_rarm_goal)
00144         self.rarm.plan()
00145         self.rarm.go()
00146         # Comparing to the 3rd degree seems too aggressive; example output:
00147         #   x: array([ 1.35906843, -1.52695742, -1.52658066, -0.21309358, -0.19092542,
00148         #             -1.51707957, -0.70651268, -1.93170852, -1.42660669,  1.0629058 ,
00149         #              0.90412021,  1.83650476])
00150         #   y: array([ 1.35914129, -1.52698103, -1.5263865 , -0.212939  , -0.19093239,
00151         #             -1.51718648, -0.70667243, -1.93141106, -1.4268663 ,  1.06139422,
00152         #              0.90376432,  1.8353421 ])
00153         numpy.testing.assert_almost_equal(self.botharms.get_current_joint_values(), self.banzai_jointvals_goal, 2)
00154 
00155     def test_botharms_set_named_target(self):
00156         '''
00157         Test if moveit_commander.set_named_target brings the arms to the init_rtm pose defined in HiroNx.srdf.
00158         '''
00159         # Move the arms to non init pose.
00160         self.larm.set_pose_target(self.banzai_pose_larm_goal)
00161         self.larm.plan()
00162         self.larm.go()
00163         self.rarm.set_pose_target(self.banzai_pose_rarm_goal)
00164         self.rarm.plan()
00165         self.rarm.go()
00166 
00167         self.botharms.set_named_target('init_rtm')
00168         self.botharms.plan()
00169         self.botharms.go()
00170 
00171         # Raises AssertException when the assertion fails, which automatically be flagged false by unittest framework.
00172         # http://stackoverflow.com/a/4319836/577001
00173         numpy.testing.assert_almost_equal(self.botharms.get_current_joint_values(), self.init_rtm_jointvals, 3)
00174 
00175 #    def test_simple_unittest(self):
00176 #        self.assertEqual(1, 1)
00177 
00178 
00179 if __name__ == '__main__':
00180     import rostest
00181     rostest.rosrun(_PKG, 'test_hironx_moveit_run', TestHironxMoveit)


hironx_moveit_config
Author(s): MoveIt Setup Assistant , Urko Esnaola
autogenerated on Sun Sep 13 2015 23:22:05