cob_lookat_action_client.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('cob_lookat_action')
00004 import rospy
00005 import random
00006 
00007 # Brings in the SimpleActionClient
00008 import actionlib
00009 
00010 import cob_lookat_action.msg
00011 from geometry_msgs.msg import PoseStamped
00012 from moveit_msgs.srv import *
00013 from moveit_msgs.msg import *
00014 
00015 def cob_lookat_action_client():
00016     # Creates the SimpleActionClient, passing the type of the action
00017     # (FibonacciAction) to the constructor.
00018     client = actionlib.SimpleActionClient('lookat_action', cob_lookat_action.msg.LookAtAction)
00019     print "Waiting for Server..."
00020     client.wait_for_server()
00021     print "...done!"
00022     
00023     focus_pub = rospy.Publisher('/lookat_target', PoseStamped)
00024     rospy.sleep(1.0)
00025     
00026     #print "Waiting for IK-Services..."
00027     #rospy.wait_for_service('/compute_fk')
00028     #print "...done!"
00029     #get_fk = rospy.ServiceProxy('/compute_fk', GetPositionFK)
00030     
00031     #fk_req = moveit_msgs.srv.GetPositionFKRequest()
00032 
00033     #fk_req.header.stamp = rospy.Time.now()
00034     #fk_req.header.frame_id = "base_link"
00035     #fk_req.fk_link_names = ["lookat_focus_frame"]
00036     #fk_req.robot_state.joint_state.name = ["torso_lower_neck_tilt_joint","torso_pan_joint","torso_upper_neck_tilt_joint","lookat_lin_joint","lookat_x_joint","lookat_y_joint","lookat_z_joint"]
00037     #fk_req.robot_state.joint_state.position = [random.uniform(-0.25,0.25), random.uniform(-0.2,0.2), random.uniform(-0.4,0.4), random.uniform(-5.0,5.0), random.uniform(-3.141,3.141), random.uniform(-3.141,3.141), random.uniform(-3.141,3.141)]
00038     ##print "REQUEST: ", fk_req
00039     
00040     #fk_res = moveit_msgs.srv.GetPositionFKResponse()
00041     #try:
00042         #fk_res = get_fk(fk_req)
00043         ##print "RESPONSE:", fk_res
00044     #except rospy.ServiceException, e:
00045         #print "Service call failed: %s"%e
00046         #return False
00047 
00048 
00049     # Creates a goal to send to the action server.
00050     goal = cob_lookat_action.msg.LookAtGoal()
00051     #goal.target = fk_res.pose_stamped[0]
00052     focus = PoseStamped()
00053     focus.header.stamp = rospy.Time.now()
00054     focus.header.frame_id = "base_link"
00055     focus.pose.position.x = random.uniform(-5.0, 5.0)
00056     focus.pose.position.y = random.uniform(-1.0, 1.0)
00057     focus.pose.position.z = random.uniform(0.0, 3.0)
00058     focus.pose.orientation.x = 0.0
00059     focus.pose.orientation.y = 0.0
00060     focus.pose.orientation.z = 0.0
00061     focus.pose.orientation.w = 1.0
00062     goal.target = focus
00063     #print "GOAL: ", goal
00064     
00065     #Debug
00066     focus_pub.publish(goal.target)
00067     rospy.sleep(1.0)
00068    
00069  
00070     # Sends the goal to the action server.
00071     client.send_goal(goal)
00072 
00073     # Waits for the server to finish performing the action.
00074     client.wait_for_result()
00075     
00076     result = client.get_result()
00077     print result
00078 
00079     return result.success
00080 
00081 if __name__ == '__main__':
00082     try:
00083         # Initializes a rospy node so that the SimpleActionClient can
00084         # publish and subscribe over ROS.
00085         rospy.init_node('cob_lookat_action_client')
00086         result = cob_lookat_action_client()
00087     except rospy.ROSInterruptException:
00088         print "program interrupted before completion"


cob_lookat_action
Author(s): Felix Messmer
autogenerated on Wed Aug 26 2015 11:01:21