pr2_arm_jt_task.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 #
00003 # Class for interacting with the PR2 J Transpose Task realtime controller.
00004 #
00005 # Copyright (c) 2012, Georgia Tech Research Corporation
00006 # 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 are met:
00010 #     * Redistributions of source code must retain the above copyright
00011 #       notice, this list of conditions and the following disclaimer.
00012 #     * Redistributions in binary form must reproduce the above copyright
00013 #       notice, this list of conditions and the following disclaimer in the
00014 #       documentation and/or other materials provided with the distribution.
00015 #     * Neither the name of the Georgia Tech Research Corporation nor the
00016 #       names of its contributors may be used to endorse or promote products
00017 #       derived from this software without specific prior written permission.
00018 # 
00019 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00020 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00025 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00026 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00027 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 #
00030 # Author: Kelsey Hawkins
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 


hrl_pr2_arms
Author(s): Kelsey Hawkins, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab
autogenerated on Wed Nov 27 2013 11:41:30