Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 import numpy as np
00033 
00034 import roslib
00035 roslib.load_manifest('hrl_pr2_arms')
00036 
00037 import rospy
00038 from std_msgs.msg import Header
00039 from pr2_manipulation_controllers.msg import JTTaskControllerState
00040 from object_manipulation_msgs.msg import CartesianGains
00041 
00042 from ep_arm_base import EPArmBase, create_ep_arm
00043 from pr2_arm_cart_base import PR2ArmCartPostureBase, extract_twist
00044 from hrl_geom.pose_converter import PoseConv
00045 import hrl_geom.transformations as trans
00046 
00047 class PR2ArmJTransposeTask(PR2ArmCartPostureBase):
00048     def __init__(self, arm_side, urdf, base_link='torso_lift_link', end_link='%s_gripper_tool_frame', 
00049                  controller_name='/%s_cart', kdl_tree=None, timeout=1.):
00050         super(PR2ArmJTransposeTask, self).__init__(arm_side, urdf, base_link, end_link, 
00051                                                controller_name, kdl_tree, timeout)
00052         self.command_gains_pub = rospy.Publisher(self.controller_name + '/gains', CartesianGains)
00053         rospy.Subscriber(self.controller_name + '/state', JTTaskControllerState, 
00054                          self._ctrl_state_cb)
00055         if self.wait_for_joint_angles(0):
00056             if not self.wait_for_ep(timeout):
00057                 rospy.logwarn("[pr2_arm_jt_task] Timed out waiting for EP.")
00058 
00059     def _ctrl_state_cb(self, ctrl_state):
00060         self._save_ep(PoseConv.to_homo_mat(ctrl_state.x_desi_filtered))
00061         with self.ctrl_state_lock:
00062             self.ctrl_state_dict["frame"] = ctrl_state.header.frame_id
00063             self.ctrl_state_dict["x_desi"] = PoseConv.to_pos_rot(ctrl_state.x_desi)
00064             self.ctrl_state_dict["xd_desi"] = extract_twist(ctrl_state.xd_desi)
00065             self.ctrl_state_dict["x_act"] = PoseConv.to_pos_rot(ctrl_state.x)
00066             self.ctrl_state_dict["xd_act"] = extract_twist(ctrl_state.xd)
00067             self.ctrl_state_dict["x_desi_filt"] = PoseConv.to_pos_rot(
00068                                                                 ctrl_state.x_desi_filtered)
00069             self.ctrl_state_dict["x_err"] = extract_twist(ctrl_state.x_err)
00070             self.ctrl_state_dict["tau_pose"] = np.array(ctrl_state.tau_pose)
00071             self.ctrl_state_dict["tau_posture"] = np.array(ctrl_state.tau_posture)
00072             self.ctrl_state_dict["tau"] = np.array(ctrl_state.tau)
00073             self.ctrl_state_dict["F"] = np.array([ctrl_state.F.force.x, 
00074                                                   ctrl_state.F.force.y,
00075                                                   ctrl_state.F.force.z,
00076                                                   ctrl_state.F.torque.x,
00077                                                   ctrl_state.F.torque.y,
00078                                                   ctrl_state.F.torque.z])
00079 
00080     def set_gains(self, p_gains, d_gains, frame=None):
00081         if frame is None:
00082             frame = self.end_link
00083         all_gains = list(p_gains) + list(d_gains)
00084         gains_msg = CartesianGains(Header(0, rospy.Time.now(), frame),
00085                                    all_gains, [])
00086         self.command_gains_pub.publish(gains_msg)
00087