cob_place_action_client.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 
18 import random
19 from math import pi
20 
21 import rospy
22 import actionlib
23 from geometry_msgs.msg import PoseStamped
24 from tf.transformations import *
25 import cob_pick_place_action.msg
26 
28  # Creates the SimpleActionClient, passing the type of the action
29  # (CobPlaceAction) to the constructor.
30  place_action_client = actionlib.SimpleActionClient('cob_place_action', cob_pick_place_action.msg.CobPlaceAction)
31 
32  # Waits until the action server has started up and started
33  # listening for goals.
34  place_action_client.wait_for_server()
35 
36  # Creates a goal to send to the action server.
37  goal = cob_pick_place_action.msg.CobPlaceGoal()
38  #goal.object_class = 18
39  #goal.object_name = "yellowsaltcube"
40  goal.object_class = 50
41  goal.object_name = "instantsoup"
42 
43  pose = PoseStamped()
44 
45  pose.header.stamp = rospy.Time.now()
46  pose.header.frame_id = "base_footprint"
47  #pose.pose.position.x = random.uniform(-0.8, -0.6)
48  #pose.pose.position.y = random.uniform(-0.3, 0.3)
49  #pose.pose.position.z = random.uniform( 0.8, 1.1)
50  #pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w = quaternion_from_euler(random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2),random.uniform(-pi/2, pi/2))
51  pose.pose.position.x = -0.7
52  pose.pose.position.y = -0.5
53  pose.pose.position.z = 0.9
54  pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z, pose.pose.orientation.w = quaternion_from_euler(0,0,0)
55  goal.destinations.append(pose)
56 
57 
58  # Sends the goal to the action server.
59  place_action_client.send_goal(goal)
60 
61  # Waits for the server to finish performing the action.
62  finished_before_timeout=place_action_client.wait_for_result(rospy.Duration(300, 0))
63 
64  if finished_before_timeout:
65  state=place_action_client.get_state()
66  print "Action finished: %s"%state
67  # Prints out the result of executing the action
68  return state # State after waiting for CobPlaceAction
69 
70 if __name__ == '__main__':
71  try:
72  # Initializes a rospy node so that the SimpleActionClient can
73  # publish and subscribe over ROS.
74  rospy.init_node('CobPlaceAction_client_py')
76  except rospy.ROSInterruptException:
77  print "program interrupted before completion"


cob_pick_place_action
Author(s): Felix Messmer
autogenerated on Mon Jun 10 2019 13:10:02