00001
00002
00003 import sys
00004 import numpy as np
00005
00006 import roslib
00007 roslib.load_manifest('hrl_pr2_arms')
00008 roslib.load_manifest('smach_ros')
00009 roslib.load_manifest('actionlib')
00010 import rospy
00011 import rosbag
00012
00013 import smach
00014 from smach_ros import SimpleActionState, ServiceState, IntrospectionServer
00015 import actionlib
00016 import tf
00017 import tf.transformations as tf_trans
00018 from std_msgs.msg import Bool, Float32, Float64MultiArray
00019 from std_srvs.srv import Empty
00020 from geometry_msgs.msg import PoseStamped, Vector3
00021 from actionlib_msgs.msg import GoalStatus
00022
00023 from hrl_generic_arms.pose_converter import PoseConverter
00024 from hrl_pr2_arms.pr2_arm import create_pr2_arm
00025 from hrl_pr2_arms.pr2_arm_hybrid import PR2ArmHybridForce
00026
00027 def main():
00028 rospy.init_node("teleop_positioner")
00029
00030 from optparse import OptionParser
00031 p = OptionParser()
00032 p.add_option('-r', '--rate', dest="rate", default=10,
00033 help="Set rate.")
00034 (opts, args) = p.parse_args()
00035
00036 arm = create_pr2_arm('l', PR2ArmHybridForce)
00037 rospy.sleep(0.1)
00038
00039 arm.zero_sensor()
00040 cur_pose = arm.get_end_effector_pose()
00041 arm.set_ep(cur_pose, 1)
00042 arm.set_force_directions([])
00043 arm.set_force_gains(p_trans=[3, 1, 1], p_rot=0.5, i_trans=[0.002, 0.001, 0.001], i_max_trans=[10, 5, 5], i_rot=0, i_max_rot=0)
00044 arm.set_motion_gains(p_trans=400, d_trans=[16, 10, 10], p_rot=[10, 10, 10], d_rot=0)
00045 arm.set_tip_frame("/l_gripper_tool_frame")
00046 arm.update_gains()
00047 arm.set_force(6 * [0])
00048
00049 r = rospy.Rate(float(opts.rate))
00050 while not rospy.is_shutdown():
00051 ep_pose = arm.get_ep()
00052 cur_pose = arm.get_end_effector_pose()
00053 err_ep = arm.ep_error(cur_pose, ep_pose)
00054 if np.linalg.norm(err_ep[0:3]) > 0.012 or np.linalg.norm(err_ep[3:]) > np.pi / 8.:
00055 arm.set_ep(cur_pose, 1)
00056 r.sleep()
00057 cur_pose = arm.get_end_effector_pose()
00058 arm.set_ep(cur_pose, 1)
00059 q = arm.get_joint_angles()
00060 q_posture = q.tolist()[0:3] + 4 * [9999]
00061 arm.set_posture(q_posture)
00062 arm.set_motion_gains(p_trans=400, d_trans=[16, 10, 10], p_rot=[20, 50, 50], d_rot=0)
00063 arm.update_gains()
00064 print PoseConverter.to_pos_quat(cur_pose)
00065 pkg_dir = roslib.rospack.rospackexec(["find", "hrl_phri_2011"])
00066 bag = rosbag.Bag(pkg_dir + "/data/saved_teleop_pose.bag", 'w')
00067 bag.write("/teleop_pose", PoseConverter.to_pose_msg(cur_pose))
00068 q_posture_msg = Float64MultiArray()
00069 q_posture_msg.data = q_posture
00070 bag.write("/teleop_posture", q_posture_msg)
00071 bag.close()
00072
00073 if __name__ == "__main__":
00074 main()