Go to the documentation of this file.00001
00002
00003 import sys
00004 import numpy as np
00005 import roslib
00006 roslib.load_manifest('hrl_ellipsoidal_control')
00007 roslib.load_manifest("pr2_controllers_msgs")
00008
00009 import rospy
00010 import actionlib
00011
00012 from geometry_msgs.msg import PoseStamped
00013 from pr2_controllers_msgs.msg import SingleJointPositionAction, SingleJointPositionGoal
00014 from pr2_controllers_msgs.msg import Pr2GripperCommandAction, Pr2GripperCommandGoal
00015
00016 from hrl_generic_arms.ep_trajectory_controller import EPArmController
00017 from hrl_generic_arms.pose_converter import PoseConverter
00018 from hrl_pr2_arms.pr2_arm import PR2ArmCartesianPostureBase, PR2ArmJointTrajectory
00019 from hrl_pr2_arms.pr2_arm import create_pr2_arm, PR2ArmJTransposeTask
00020 from hrl_pr2_arms.pr2_controller_switcher import ControllerSwitcher
00021 from hrl_ellipsoidal_control.ellipsoidal_interface_backend import EllipsoidalInterfaceBackend
00022 from hrl_ellipsoidal_control.cartesian_interface_backend import CartesianInterfaceBackend
00023
00024 class EllipsoidControlExperiment(object):
00025 def __init__(self, interface_backend):
00026 self.backend = interface_backend()
00027 self.cart_arm = create_pr2_arm('l', PR2ArmJTransposeTask,
00028 controller_name='%s_cart_jt_task',
00029 end_link="%s_gripper_shaver45_frame")
00030 self.backend.set_arm(self.cart_arm)
00031 rospy.loginfo("[ell_control_experiment] EllipsoidControlExperiment ready.")
00032
00033 def run_experiment(self):
00034 self.backend.disable_interface("Setting up arm.")
00035 pos, rot = PoseConverter.to_pos_rot(self.backend.controller.get_ell_frame())
00036 pos += rot * np.mat([0.3, -0.2, -0.05]).T
00037 _, tool_rot = PoseConverter.to_pos_rot([0, 0, 0], [np.pi, 0, 3./4. * np.pi])
00038 rot *= tool_rot
00039 ep_ac = EPArmController(self.cart_arm)
00040 ep_ac.execute_interpolated_ep((pos, rot), 6.)
00041 self.backend.set_arm(self.cart_arm)
00042 self.backend.enable_interface("Controller ready.")
00043
00044 def main():
00045 if sys.argv[1] == "ell":
00046 interface_backend = EllipsoidalInterfaceBackend
00047 elif sys.argv[1] == "cart":
00048 interface_backend = CartesianInterfaceBackend
00049 else:
00050 print "Argument must be either 'ell' or 'cart'"
00051 rospy.init_node("ell_control_experiment")
00052 ece = EllipsoidControlExperiment(interface_backend)
00053 ece.run_experiment()
00054 rospy.spin()
00055 ece.backend.print_statistics()
00056 if len(sys.argv) >= 3:
00057 ece.backend.save_statistics(sys.argv[2])
00058
00059 if __name__ == "__main__":
00060 main()