tuck_arms.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2009, 2010, 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 # Author: Wim Meeussen
35 """
36 usage: tuck_arms.py [-l ACTION] [-r ACTION] [-q]
37 Options:
38  -l or --left Action for left arm
39  -r or --right Action for right arm
40  -q or --quit Shut down the action client after completing action
41 Actions:
42  t or tuck
43  u or untuck
44 
45 """
46 
47 from pr2_common_action_msgs.msg import TuckArmsAction, TuckArmsGoal
48 import actionlib
49 import getopt
50 import rospy
51 
52 
53 def usage():
54  print __doc__ % vars()
55  rospy.signal_shutdown("Help requested")
56 
57 
58 def main():
59  action_name = 'tuck_arms'
60  quit_when_finished = False
61 
62  # check for command line arguments, and send goal to action server if
63  # required
64  myargs = rospy.myargv()[1:]
65  if len(myargs):
66  goal = TuckArmsGoal()
67  goal.tuck_left = True
68  goal.tuck_right = True
69  opts, args = getopt.getopt(myargs, 'hql:r:', ['quit', 'left', 'right'])
70  for arm, action in opts:
71  if arm in ('-l', '--left'):
72  if action in ('tuck', 't'):
73  goal.tuck_left = True
74  elif action in ('untuck', 'u'):
75  goal.tuck_left = False
76  else:
77  rospy.logerr('Invalid action for right arm: %s' % action)
78  rospy.signal_shutdown("ERROR")
79 
80  if arm in ('-r', '--right'):
81  if action in ('tuck', 't'):
82  goal.tuck_right = True
83  elif action in ('untuck', 'u'):
84  goal.tuck_right = False
85  else:
86  rospy.logerr('Invalid action for left arm: %s' % action)
87  rospy.signal_shutdown("ERROR")
88 
89  if arm in ('--quit', '-q'):
90  quit_when_finished = True
91 
92  if arm in ('--help', '-h'):
93  usage()
94 
95  tuck_arm_client = actionlib.SimpleActionClient(action_name,
96  TuckArmsAction)
97  rospy.logdebug('Waiting for action server to start')
98  tuck_arm_client.wait_for_server(rospy.Duration())
99  rospy.logdebug('Sending goal to action server')
100  tuck_arm_client.send_goal_and_wait(goal, rospy.Duration(30.0),
101  rospy.Duration(5.0))
102 
103  if quit_when_finished:
104  rospy.signal_shutdown("Quitting")
105 
106 
107 if __name__ == '__main__':
108  rospy.init_node('tuck_arms_client')
109  main()
110  rospy.spin()
def main()
Definition: tuck_arms.py:58
def usage()
Definition: tuck_arms.py:53


pr2_tuckarm
Author(s): Wim Meeussen
autogenerated on Sat Feb 27 2021 04:01:07