DockDriveActionClient.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2012, Yujin Robot
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Yujin Robot nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 # Author: Younghun Ju <younghoon.hju@rnd.yujinrobot.com> <yhju83@gmail.com>
00036 
00037 import roslib; roslib.load_manifest('kobuki_auto_docking')
00038 import rospy
00039 
00040 import actionlib
00041 from kobuki_msgs.msg import AutoDockingAction, AutoDockingGoal
00042 from actionlib_msgs.msg import GoalStatus
00043 
00044 def doneCb(status, result):
00045   if 0: print ''
00046   elif status == GoalStatus.PENDING   : state='PENDING'
00047   elif status == GoalStatus.ACTIVE    : state='ACTIVE'
00048   elif status == GoalStatus.PREEMPTED : state='PREEMPTED'
00049   elif status == GoalStatus.SUCCEEDED : state='SUCCEEDED'
00050   elif status == GoalStatus.ABORTED   : state='ABORTED'
00051   elif status == GoalStatus.REJECTED  : state='REJECTED'
00052   elif status == GoalStatus.PREEMPTING: state='PREEMPTING'
00053   elif status == GoalStatus.RECALLING : state='RECALLING'
00054   elif status == GoalStatus.RECALLED  : state='RECALLED'
00055   elif status == GoalStatus.LOST      : state='LOST'
00056   # Print state of action server
00057   print 'Result - [ActionServer: ' + state + ']: ' + result.text
00058 
00059 def activeCb():
00060   if 0: print 'Action server went active.'
00061 
00062 def feedbackCb(feedback):
00063   # Print state of dock_drive module (or node.)
00064   print 'Feedback: [DockDrive: ' + feedback.state + ']: ' + feedback.text
00065 
00066 def dock_drive_client():
00067   # add timeout setting
00068   client = actionlib.SimpleActionClient('dock_drive_action', AutoDockingAction)
00069   while not client.wait_for_server(rospy.Duration(5.0)):
00070     if rospy.is_shutdown(): return
00071     print 'Action server is not connected yet. still waiting...'
00072 
00073   goal = AutoDockingGoal();
00074   client.send_goal(goal, doneCb, activeCb, feedbackCb)
00075   print 'Goal: Sent.'
00076   rospy.on_shutdown(client.cancel_goal)
00077   client.wait_for_result()
00078 
00079   #print '    - status:', client.get_goal_status_text()
00080   return client.get_result()
00081 
00082 if __name__ == '__main__':
00083   try:
00084     rospy.init_node('dock_drive_client_py', anonymous=True)
00085     dock_drive_client()
00086     #print ''
00087     #print "Result: ", result
00088   except rospy.ROSInterruptException: 
00089     print "program interrupted before completion"


kobuki_auto_docking
Author(s): Younghun Ju
autogenerated on Mon Oct 6 2014 01:30:37