DockDriveActionClient.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2012, Yujin Robot
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Yujin Robot nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 # Author: Younghun Ju <yhju@yujinrobot.com> <yhju83@gmail.com>
36 
37 import roslib; roslib.load_manifest('kobuki_auto_docking')
38 import rospy
39 
40 import actionlib
41 from kobuki_msgs.msg import AutoDockingAction, AutoDockingGoal
42 from actionlib_msgs.msg import GoalStatus
43 
44 def doneCb(status, result):
45  if 0: print ''
46  elif status == GoalStatus.PENDING : state='PENDING'
47  elif status == GoalStatus.ACTIVE : state='ACTIVE'
48  elif status == GoalStatus.PREEMPTED : state='PREEMPTED'
49  elif status == GoalStatus.SUCCEEDED : state='SUCCEEDED'
50  elif status == GoalStatus.ABORTED : state='ABORTED'
51  elif status == GoalStatus.REJECTED : state='REJECTED'
52  elif status == GoalStatus.PREEMPTING: state='PREEMPTING'
53  elif status == GoalStatus.RECALLING : state='RECALLING'
54  elif status == GoalStatus.RECALLED : state='RECALLED'
55  elif status == GoalStatus.LOST : state='LOST'
56  # Print state of action server
57  print 'Result - [ActionServer: ' + state + ']: ' + result.text
58 
59 def activeCb():
60  if 0: print 'Action server went active.'
61 
62 def feedbackCb(feedback):
63  # Print state of dock_drive module (or node.)
64  print 'Feedback: [DockDrive: ' + feedback.state + ']: ' + feedback.text
65 
67  # add timeout setting
68  client = actionlib.SimpleActionClient('dock_drive_action', AutoDockingAction)
69  while not client.wait_for_server(rospy.Duration(5.0)):
70  if rospy.is_shutdown(): return
71  print 'Action server is not connected yet. still waiting...'
72 
73  goal = AutoDockingGoal();
74  client.send_goal(goal, doneCb, activeCb, feedbackCb)
75  print 'Goal: Sent.'
76  rospy.on_shutdown(client.cancel_goal)
77  client.wait_for_result()
78 
79  #print ' - status:', client.get_goal_status_text()
80  return client.get_result()
81 
82 if __name__ == '__main__':
83  try:
84  rospy.init_node('dock_drive_client_py', anonymous=True)
86  #print ''
87  #print "Result: ", result
88  except rospy.ROSInterruptException:
89  print "program interrupted before completion"
def doneCb(status, result)


kobuki_auto_docking
Author(s): Younghun Ju
autogenerated on Mon Jun 10 2019 13:44:57