vs_execute_node.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 #  Copyright (c) 2012, Georgia Institute of Technology
00005 #  All rights reserved.
00006 #
00007 #  Redistribution and use in source and binary forms, with or without
00008 #  modification, are permitted provided that the following conditions
00009 #  are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #     notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #     copyright notice, this list of conditions and the following
00015 #     disclaimer in the documentation and/or other materials provided
00016 #     with the distribution.
00017 #  * Neither the name of the Georgia Institute of Technology nor the names of
00018 #     its contributors may be used to endorse or promote products derived
00019 #     from this software without specific prior written permission.
00020 #
00021 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 #  'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 #  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 #  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 #  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 #  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 #  POSSIBILITY OF SUCH DAMAGE.
00033 
00034 import roslib; roslib.load_manifest('visual_servo')
00035 import rospy
00036 from geometry_msgs.msg import PoseStamped
00037 from geometry_msgs.msg import TwistStamped
00038 from geometry_msgs.msg import Twist
00039 
00040 from std_msgs.msg import Float64
00041 from trajectory_msgs.msg import JointTrajectory
00042 from trajectory_msgs.msg import JointTrajectoryPoint
00043 from geometry_msgs.msg import Pose
00044 import tf
00045 import tf.transformations as tf_trans
00046 import sys
00047 from hrl_pr2_arms.pr2_controller_switcher import ControllerSwitcher
00048 from visual_servo.srv import *
00049 from array import *
00050 
00051 def cleanup():
00052   rospy.loginfo('[IMPORTANT] Shutting Down. Set Twist to 0')
00053   pub = rospy.Publisher('l_cart/command', Twist)
00054   pub.publish(zero)
00055   rospy.sleep(0.5)
00056   pub.publish(zero)
00057 
00058 def adjustVelocity(vel):
00059 <<<<<<< HEAD
00060  clip_vel = 0.05
00061 =======
00062  clip_vel = 0.12
00063 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00064  ret = vel 
00065  if ret > clip_vel:
00066    ret = clip_vel
00067  elif -ret > clip_vel:
00068    ret = -clip_vel
00069  return ret 
00070 
00071 
00072  
00073 def handle_move_request(req):
00074 <<<<<<< HEAD
00075     pub = rospy.Publisher('l_cart/command', Twist)
00076 =======
00077     pub = rospy.Publisher('r_cart/command', Twist)
00078 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00079     t = req.twist # service call
00080     msg = Twist() # this is the message to the twist controller
00081     try:
00082       msg.linear.x = adjustVelocity(t.twist.linear.x)
00083       msg.linear.y = adjustVelocity(t.twist.linear.y)
00084       msg.linear.z = adjustVelocity(t.twist.linear.z)
00085       msg.angular.x = adjustVelocity(t.twist.angular.x)
00086       msg.angular.y = adjustVelocity(t.twist.angular.y)
00087       msg.angular.z = adjustVelocity(t.twist.angular.z)
00088       rospy.loginfo('vx:%+.5f vy:%+.5f vz:%+.5f wx:%+.5f wy:%+.5f wz:%+.5f', msg.linear.x, msg.linear.y, msg.linear.z, msg.angular.x, msg.angular.y, msg.angular.z)
00089       pub.publish(msg)
00090     except rospy.ServiceException, e:
00091       pub.publish(zero)
00092 <<<<<<< HEAD
00093 
00094     return VisualServoTwistResponse()
00095          
00096 
00097 
00098 =======
00099 
00100     return VisualServoTwistResponse()
00101          
00102 
00103 
00104 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00105 class VisualServoExecutionNode:
00106   def initial_arm(self, cs):
00107     rospy.loginfo('Setting to Initial msg...')
00108     cs.carefree_switch('l', '%s_arm', '$(find visual_servo)/params/rmc_joint_trajectory_params.yaml' )
00109     rospy.sleep(0.5)
00110     pub = rospy.Publisher('l_arm/command', JointTrajectory)
00111     msg = JointTrajectory()
00112     pts = JointTrajectoryPoint()
00113 <<<<<<< HEAD
00114     pts.positions = array('d', [0.323, -0.6460, 0.00,
00115         -1.273, -10.512, 0.0570, 0.163])
00116  
00117     pts.time_from_start = rospy.Duration(3.0)
00118     msg.points = [pts]
00119    
00120     msg.joint_names = ['l_shoulder_pan_joint', 'l_shoulder_lift_joint', 'l_upper_arm_roll_joint','l_elbow_flex_joint', 'l_forearm_roll_joint','l_wrist_flex_joint','l_wrist_roll_joint']
00121     # msg.joint_names = ['r_shoulder_pan_joint', 'r_shoulder_lift_joint', 'r_upper_arm_roll_joint','r_elbow_flex_joint', 'r_forearm_roll_joint','r_wrist_flex_joint','r_wrist_roll_joint']
00122 =======
00123     pts.positions = array('d', [-1.32734204881265387, -0.64601608409943324, -1.4620635485239604,
00124                                       -1.2729772622637399, -10.5123303230158518, 0.0570651396529178, 0.163787989862169])
00125     pts.time_from_start = rospy.Duration(3.0)
00126     msg.points = [pts]
00127     msg.joint_names = ['r_shoulder_pan_joint', 'r_shoulder_lift_joint', 'r_upper_arm_roll_joint',
00128                        'r_elbow_flex_joint', 'r_forearm_roll_joint','r_wrist_flex_joint','r_wrist_roll_joint']
00129 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00130     # pub.publish(msg)
00131     rospy.sleep(0.5)
00132     # pub.publish(msg)
00133     rospy.sleep(3)
00134 
00135 <<<<<<< HEAD
00136     pts.positions = array('d', [0.35, 0.167, 1.604, -1.89,
00137       -15.25, -1.282, 1.72])
00138  
00139 =======
00140     pts.positions = array('d', [-0.750, +0.237, -1.60411927, 
00141                                 -2.25, -15.85, -1.282, -1.72])
00142 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00143     msg.points = [pts]
00144     pub.publish(msg)
00145     rospy.sleep(0.5)
00146     pub.publish(msg)
00147     
00148     rospy.sleep(5) 
00149     cs.carefree_switch('l', '%s_cart', '$(find visual_servo)/params/rmc_cartTwist_params.yaml')
00150     rospy.sleep(0.5)
00151     pub = rospy.Publisher('l_cart/command', Twist)
00152     pub.publish(zero)
00153     rospy.sleep(0.5)
00154     pub.publish(zero)
00155 
00156 if __name__ == '__main__':
00157   try:
00158     node = VisualServoExecutionNode()
00159     rospy.init_node('vs_execute_node', log_level=rospy.DEBUG)
00160     global zero
00161     global service
00162     zero = Twist()
00163     zero.linear.x = 0.0
00164     zero.linear.y = 0.0
00165     zero.linear.z = 0.0
00166     zero.angular.x = 0.0
00167     zero.angular.y = 0.0
00168     zero.angular.z = 0.0
00169     rospy.on_shutdown(cleanup)
00170     
00171     cs = ControllerSwitcher()
00172     node.initial_arm(cs)
00173 #    service = rospy.ServiceProxy('visual_servo_twist', VisualServoTwist)
00174     
00175     rospy.loginfo('Done initializing... Now advertise the Service')
00176     s = rospy.Service('movearm', VisualServoTwist , handle_move_request)
00177 <<<<<<< HEAD
00178     rospy.loginfo('Ready to move arm')
00179 =======
00180 >>>>>>> 04206a0d0c433a3c0ca22cced7672835d0b6a8a5
00181     rospy.spin()
00182   
00183   except rospy.ROSInterruptException: pass
00184 
00185 


visual_servo
Author(s): Stephan Lee
autogenerated on Wed Nov 27 2013 11:44:03