experiment_setup.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import numpy as np
00004 import sys
00005 
00006 import roslib
00007 roslib.load_manifest('hrl_pr2_arms')
00008 import rospy
00009 import actionlib
00010 from pr2_controllers_msgs.msg import SingleJointPositionAction, SingleJointPositionGoal
00011 from pr2_controllers_msgs.msg import Pr2GripperCommandAction, Pr2GripperCommandGoal
00012 from pr2_controllers_msgs.msg import PointHeadAction, PointHeadGoal
00013 
00014 from hrl_generic_arms.pose_converter import PoseConverter
00015 from hrl_pr2_arms.pr2_controller_switcher import ControllerSwitcher
00016 from hrl_pr2_arms.pr2_arm import create_pr2_arm, PR2ArmJointTrajectory
00017 from hrl_pr2_arms.pr2_arm import PR2ArmJTransposeTask
00018 
00019 joint_deltas = [0.01, 0.01, 0.01, 0.012, 0.01, 0.01, 0.01]
00020 SETUP_ANGLES = [0, 0, np.pi/2, -np.pi/2, -np.pi, -np.pi/2, -np.pi/2]
00021 
00022 
00023 class ExperimentSetup(object):
00024     def __init__(self):
00025         self.ctrl_switcher = ControllerSwitcher()
00026         self.torso_sac = actionlib.SimpleActionClient('torso_controller/position_joint_action',
00027                                                       SingleJointPositionAction)
00028         self.torso_sac.wait_for_server()
00029         self.head_point_sac = actionlib.SimpleActionClient(
00030                                                 '/head_traj_controller/point_head_action',
00031                                                 PointHeadAction)
00032         self.head_point_sac.wait_for_server()
00033         rospy.loginfo("[experiment_setup] ExperimentSetup ready.")
00034 
00035     def point_head(self):
00036         print "Pointing head"
00037         head_goal = PointHeadGoal()
00038         head_goal.target = PoseConverter.to_point_stamped_msg('/torso_lift_link',
00039                                                               np.mat([1., 0.4, 0.]).T,
00040                                                               np.mat(np.eye(3)))
00041         head_goal.target.header.stamp = rospy.Time()
00042         head_goal.min_duration = rospy.Duration(3.)
00043         head_goal.max_velocity = 0.2
00044         self.head_point_sac.send_goal_and_wait(head_goal)
00045 
00046     def adjust_torso(self):
00047         # move torso up
00048         tgoal = SingleJointPositionGoal()
00049         tgoal.position = 0.238  # all the way up is 0.300
00050         tgoal.min_duration = rospy.Duration( 2.0 )
00051         tgoal.max_velocity = 1.0
00052         self.torso_sac.send_goal_and_wait(tgoal)
00053 
00054     def mirror_arm_setup(self):
00055         self.ctrl_switcher.carefree_switch('r', 'r_joint_controller_mirror', 
00056                                 "$(find hrl_ellipsoidal_control)/params/mirror_params.yaml")
00057         rospy.sleep(1)
00058         arm = create_pr2_arm('r', PR2ArmJointTrajectory, 
00059                              controller_name="r_joint_controller_mirror")
00060         arm.set_ep([-0.26880036055585677, 0.71881299774143248, 
00061                     -0.010187938126536471, -1.43747589322259, 
00062                     -12.531293698878677, -0.92339874393497123, 
00063                     3.3566322715405432], 5)
00064         rospy.sleep(6)
00065 
00066     def tool_arm_setup(self):
00067         self.ctrl_switcher.carefree_switch('l', '%s_arm_controller', None)
00068         rospy.sleep(1)
00069         joint_arm = create_pr2_arm('l', PR2ArmJointTrajectory)
00070         setup_angles = SETUP_ANGLES
00071         joint_arm.set_ep(setup_angles, 5)
00072         rospy.sleep(6)
00073 
00074     def mirror_mannequin(self):
00075         arm = create_pr2_arm('r', PR2ArmJointTrajectory, 
00076                              controller_name="r_joint_controller_mirror")
00077         r = rospy.Rate(10)
00078         q_act_last = arm.get_joint_angles()
00079         while not rospy.is_shutdown():
00080             q_act = arm.get_joint_angles()
00081             q_ep = arm.get_ep()
00082             new_ep = q_ep.copy()
00083             for i in range(7):
00084                 if np.fabs(q_act[i] - q_act_last[i]) > joint_deltas[i]:
00085                     new_ep[i] = q_act[i]
00086             arm.set_ep(new_ep, 0.1)
00087             q_act_last = q_act
00088             r.sleep()
00089 
00090     def cart_controller_setup(self):
00091         self.ctrl_switcher.carefree_switch('l', '%s_cart_jt_task', 
00092                                            "$(find hrl_rfh_fall_2011)/params/l_jt_task_shaver45.yaml") 
00093         self.cart_arm = create_pr2_arm('l', PR2ArmJTransposeTask, 
00094                                        controller_name='%s_cart_jt_task', 
00095                                        end_link="%s_gripper_shaver45_frame")
00096         rospy.sleep(2)
00097         setup_angles = SETUP_ANGLES
00098         self.cart_arm.set_posture(setup_angles)
00099         self.cart_arm.set_gains([200, 800, 800, 80, 80, 80], [15, 15, 15, 1.2, 1.2, 1.2])
00100 
00101 def main():
00102     rospy.init_node("experiment_setup")
00103 
00104     setup = ExperimentSetup()
00105     if sys.argv[1] == 'setup':
00106         setup.point_head()
00107         setup.adjust_torso()
00108         setup.mirror_arm_setup()
00109         setup.tool_arm_setup()
00110         setup.cart_controller_setup()
00111         return
00112 
00113     if sys.argv[1] == 'mirror':
00114         setup.mirror_mannequin()
00115         return
00116 
00117 
00118 if __name__ == "__main__":
00119     main()


hrl_ellipsoidal_control
Author(s): Kelsey Hawkins
autogenerated on Wed Nov 27 2013 11:41:49