tuck_arms_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2009, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of the Willow Garage nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 
35 """
36 usage: tuck_arms.py [-l ACTION] [-r ACTION]
37 
38 Options:
39  -l or --left Action for left arm
40  -r or --right Action for right arm
41 
42 Actions:
43  t or tuck
44  u or untuck
45 
46 NB: If action unspecified for an arm, defaults to tuck
47 
48 """
49 
50 
51 import getopt
52 
53 import rospy
54 
55 import actionlib
56 
57 from pr2_common_action_msgs.msg import TuckArmsAction, TuckArmsGoal
58 
59 def main():
60  action_name = 'tuck_arms'
61 
62  # check for command line arguments, and send goal to action server if required
63  myargs = rospy.myargv()[1:]
64  if len(myargs):
65  goal = TuckArmsGoal()
66  goal.tuck_left = True
67  goal.tuck_right = True
68  opts, args = getopt.getopt(myargs, 'hql:r:', ['quit','left','right'])
69  for arm, action in opts:
70  if arm in ('-l', '--left'):
71  if action in ('tuck', 't'):
72  goal.tuck_left = True
73  elif action in ('untuck', 'u'):
74  goal.tuck_left = False
75  else:
76  rospy.logerr('Invalid action for right arm: %s'%action)
77  rospy.signal_shutdown("ERROR")
78 
79  if arm in ('-r', '--right'):
80  if action in ('tuck', 't'):
81  goal.tuck_right = True
82  elif action in ('untuck', 'u'):
83  goal.tuck_right = False
84  else:
85  rospy.logerr('Invalid action for left arm: %s'%action)
86  rospy.signal_shutdown("ERROR")
87 
88  if arm in ('--help', '-h'):
89  print __doc__ % vars()
90 
91  tuck_arm_client = actionlib.SimpleActionClient(action_name, TuckArmsAction)
92  rospy.logdebug('Waiting for action server to start')
93  tuck_arm_client.wait_for_server(rospy.Duration(10.0))
94  rospy.logdebug('Sending goal to action server')
95  tuck_arm_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
96 
97 if __name__ == "__main__":
98  rospy.init_node('tuck_amrs_test')
99  main()


pr2_tuck_arms_action
Author(s): Wim Meeussen
autogenerated on Fri Jun 7 2019 22:06:46