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
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
00080 msg = Twist()
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
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
00131 rospy.sleep(0.5)
00132
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
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