pr2_arm_jt.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 #
00003 # Class for interacting with the PR2 J Transpose 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 robot_mechanism_controllers.msg import JTCartesianControllerState
00039 
00040 from ep_arm_base import EPArmBase, create_ep_arm
00041 from pr2_arm_cart_base import PR2ArmCartPostureBase, extract_twist
00042 from hrl_geom.pose_converter import PoseConv
00043 import hrl_geom.transformations as trans
00044 
00045 ##
00046 # Class for interacting with the Cartesian controllers on the PR2.
00047 # Controller type: robot_mechanism_controllers/JTCartesianController
00048 # The equilibrium points are pose-like objects.
00049 class PR2ArmJTranspose(PR2ArmCartPostureBase):
00050     def __init__(self, arm_side, urdf, base_link='torso_lift_link', end_link='%s_gripper_tool_frame', 
00051                  controller_name='/%s_cart', kdl_tree=None, timeout=1.):
00052         super(PR2ArmJTranspose, self).__init__(arm_side, urdf, base_link, end_link, 
00053                                                controller_name, kdl_tree, timeout)
00054         rospy.Subscriber(self.controller_name + '/state', JTCartesianControllerState, 
00055                          self._ctrl_state_cb)
00056         if self.wait_for_joint_angles(0):
00057             if not self.wait_for_ep(timeout):
00058                 rospy.logwarn("[pr2_arm_jt] Timed out waiting for EP.")
00059 
00060     def _ctrl_state_cb(self, ctrl_state):
00061         self._save_ep(PoseConv.to_homo_mat(ctrl_state.x_desi_filtered))
00062         with self.ctrl_state_lock:
00063             self.ctrl_state_dict["frame"] = ctrl_state.header.frame_id
00064             self.ctrl_state_dict["x_desi"] = PoseConv.to_pos_rot(ctrl_state.x_desi)
00065             self.ctrl_state_dict["xd_desi"] = extract_twist(ctrl_state.xd_desi)
00066             self.ctrl_state_dict["x_act"] = PoseConv.to_pos_rot(ctrl_state.x)
00067             self.ctrl_state_dict["xd_act"] = extract_twist(ctrl_state.xd)
00068             self.ctrl_state_dict["x_desi_filt"] = PoseConv.to_pos_rot(
00069                                                                 ctrl_state.x_desi_filtered)
00070             self.ctrl_state_dict["x_err"] = extract_twist(ctrl_state.x_err)
00071             self.ctrl_state_dict["tau_pose"] = np.array(ctrl_state.tau_pose)
00072             self.ctrl_state_dict["tau_posture"] = np.array(ctrl_state.tau_posture)
00073             self.ctrl_state_dict["tau"] = np.array(ctrl_state.tau)
00074             self.ctrl_state_dict["F"] = np.array([ctrl_state.F.force.x, 
00075                                                   ctrl_state.F.force.y,
00076                                                   ctrl_state.F.force.z,
00077                                                   ctrl_state.F.torque.x,
00078                                                   ctrl_state.F.torque.y,
00079                                                   ctrl_state.F.torque.z])


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