handoff_node.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import roslib; 
00004 roslib.load_manifest('hrl_pr2_kinematics_tutorials')
00005 roslib.load_manifest('rfid_behaviors')
00006 roslib.load_manifest('hrl_lib')
00007 roslib.load_manifest('std_srvs')
00008 import rospy
00009 
00010 import hrl_pr2_kinematics_tutorials.hrl_pr2 as hrl_pr2
00011 import hrl_lib.transforms as tr
00012 import rfid_behaviors.tactile_sensors as tsen
00013 from rfid_behaviors.srv import ArmSrv
00014 from rfid_behaviors.srv import HandoffSrv
00015 
00016 import numpy as np, math
00017 import os
00018 import time
00019 
00020 class HandoffNode():
00021     def __init__( self ):
00022         rospy.init_node( 'handoff', anonymous = True )
00023         rospy.logout( 'handoff_node: Have run hrl_pr2_gains/change_gains.sh yet?' )
00024 
00025         self.robot = hrl_pr2.HRL_PR2()
00026         if not (os.environ.has_key('ROBOT') and os.environ['ROBOT'] == 'sim'):
00027             self.ts = tsen.TactileSensor()
00028         self.arm = 'right_arm'
00029 
00030         self.start_ja = [0.040304940763152608, 1.2398003444166741, -1.2204088251845415, -1.9324078526157087, -31.197472992401149, -1.7430222641585842, -1.5358378047038517]
00031         #self.target_ja = [0.35891507126604916, 0.13778228113494312, -0.01277662779292843, -1.4992538841561938, -28.605807802842136, -0.96590944225972863, -3.0950669743130161]
00032         self.target_ja = [0.0818, 0.377, -0.860, -2.144, -3.975, -1.479, 3.907]
00033 
00034         self.grasp_ja = [ -1.57263428749, -0.347376409246, -1.58724516843, -1.61707941489, -51.4022142048, -1.36894875484, -5.9965378332 ]
00035         self.stowgrasp_ja = [-0.130, 1.18, -1.410, -1.638, -141.06, -1.695, 48.616 ]
00036 
00037 
00038         self._sh = rospy.Service( '/rfid_handoff/handoff' , HandoffSrv, self.handoff )
00039         self._si = rospy.Service( '/rfid_handoff/initialize' , HandoffSrv, self.initialize )
00040         self._sj = rospy.Service( '/rfid_handoff/handoff_pos' , ArmSrv, self.handoff_pos )
00041         self._ss = rospy.Service( '/rfid_handoff/stow' , HandoffSrv, self.stow )
00042         self._sp = rospy.Service( '/rfid_handoff/pre_stow' , HandoffSrv, self.pre_stow )
00043         self._sg = rospy.Service( '/rfid_handoff/grasp' , HandoffSrv, self.grasp )
00044         self._senough = rospy.Service( '/rfid_handoff/stow_grasp' , HandoffSrv, self.stow_grasp )
00045         self._swave = rospy.Service( '/rfid_handoff/wave' , HandoffSrv, self.wave )
00046 
00047         # self.initialize()  # Prefer to do this manually... (rosservice call /rfid_handoff/initialize)
00048         rospy.logout( 'handoff_node: Waiting for service calls.' )
00049 
00050     def initialize( self, msg = None ):
00051         rospy.logout( 'handoff_node: Initializing. Hand me an object!' )
00052 
00053         # Put into handoff position, ready to accept object
00054         self.robot.set_jointangles( self.arm, self.target_ja, 3.0 )
00055         rospy.sleep( rospy.Duration( 3.0 ))
00056         self.robot.open_gripper( self.arm )
00057         rospy.sleep( rospy.Duration( 2.0 ))
00058 
00059         self.stow()
00060         return True
00061 
00062     def wave( self, msg = None ):
00063         wave_a = [0.0131, 0.325, -0.832, -1.762,-6.511, -0.191, 0.162]
00064         wave_b = [-0.180, 0.034, 0.108, -1.295, -6.224, -0.383, 0.119]
00065         self.robot.set_jointangles( self.arm, wave_a, 2.0 )
00066         rospy.sleep( rospy.Duration( 2.0 ))
00067         self.robot.set_jointangles( self.arm, wave_b, 1.0 )
00068         rospy.sleep( rospy.Duration( 1.0 ))
00069         self.robot.set_jointangles( self.arm, wave_a, 1.0 )
00070         rospy.sleep( rospy.Duration( 1.0 ))
00071         self.robot.set_jointangles( self.arm, wave_b, 1.0 )
00072         rospy.sleep( rospy.Duration( 1.0 ))
00073         self.robot.set_jointangles( self.arm, wave_a, 1.0 )
00074         rospy.sleep( rospy.Duration( 1.0 ))
00075         self.robot.set_jointangles( self.arm, self.start_ja, 3.0 )
00076         rospy.sleep( rospy.Duration( 3.0 ))
00077         return True
00078                 
00079 
00080 
00081     def stow( self, msg=None ):
00082         # Grab object
00083         self.robot.close_gripper( self.arm )
00084         rospy.sleep( rospy.Duration( 2.5 ))
00085 
00086         # Stow
00087         self.robot.set_jointangles( self.arm, self.start_ja, 3.0 )
00088         rospy.sleep( rospy.Duration( 3.0 ))
00089         return True
00090 
00091     def pre_stow( self, msg=None ):
00092         # Grab object
00093         self.robot.close_gripper( self.arm )
00094         rospy.sleep( rospy.Duration( 2.0 ))
00095 
00096         # Stow
00097         self.robot.set_jointangles( self.arm, self.target_ja, 3.0 )
00098         rospy.sleep( rospy.Duration( 3.0 ))
00099         return True
00100 
00101     def grasp( self, msg=None ):
00102         # Grab object
00103         self.robot.close_gripper( self.arm )
00104         rospy.sleep( rospy.Duration( 2.0 ))
00105 
00106         # Stow
00107         self.robot.set_jointangles( self.arm, self.grasp_ja, 3.0 )
00108         rospy.sleep( rospy.Duration( 3.0 ))
00109         return True
00110 
00111     def stow_grasp( self, msg=None ):
00112         # Stow
00113         self.robot.set_jointangles( self.arm, self.stowgrasp_ja, 3.0 )
00114         rospy.sleep( rospy.Duration( 3.0 ))
00115         return True
00116 
00117 
00118     def open( self ):
00119         self.robot.open_gripper( self.arm )
00120         rospy.sleep( rospy.Duration( 2.0 ))
00121 
00122 
00123     def close( self ):
00124         self.robot.close_gripper( self.arm )
00125         rospy.sleep( rospy.Duration( 2.0 ))
00126 
00127 
00128     def handoff( self, msg = None ):
00129         # Put into handoff position.
00130         self.robot.set_jointangles( self.arm, self.target_ja, 3.0 )
00131         rospy.sleep( rospy.Duration( 3.0 ))
00132 
00133         # Tactile Sensor detector
00134         rospy.sleep( rospy.Duration( 0.5 ))
00135         self.ts.thresh_detect( 3000 )
00136 
00137         # Release object
00138         self.robot.open_gripper( self.arm )
00139         rospy.sleep( rospy.Duration( 2.0 ))
00140         
00141         # Stow
00142         self.robot.set_jointangles( self.arm, self.start_ja, 3.0 )
00143         rospy.sleep( rospy.Duration( 3.0 ))
00144         return True
00145 
00146     def handoff_pos( self, msg ):
00147         #pos = np.matrix([0.6977, -0.03622, 0.2015]).T
00148         #ang = tr.Rx(math.radians(0.))
00149         print msg
00150         pos = np.matrix([ msg.x, msg.y, msg.z ]).T
00151         ang = tr.Rx( msg.ang )
00152         
00153         q = [0, 0, 0, 0, 0, 0, 0]
00154         j = self.robot.IK('right_arm', pos, ang, self.target_ja)
00155         #j = self.robot.IK('right_arm', pos, ang, q)
00156         self.robot.set_jointangles( 'right_arm', j, 3.0 )
00157 
00158         # Tactile Sensor detector
00159         rospy.sleep( rospy.Duration( 0.5 ))
00160         self.ts.thresh_detect( 3000 )
00161 
00162         # Release object
00163         self.robot.open_gripper( self.arm )
00164         rospy.sleep( rospy.Duration( 2.0 ))
00165         
00166         # Stow
00167         self.robot.set_jointangles( self.arm, self.start_ja, 3.0 )
00168         rospy.sleep( rospy.Duration( 3.0 ))
00169 
00170         return True
00171         
00172 
00173 
00174 if __name__ == '__main__':
00175     hon = HandoffNode()
00176     #hon.handoff_pos()
00177     rospy.spin()
00178 
00179     #ho.handoff()
00180     


rfid_behaviors
Author(s): Travis Deyle
autogenerated on Wed Nov 27 2013 11:50:14