Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 import sys
00023 import time
00024
00025 import rospy
00026 from actionlib import SimpleActionClient, GoalStatus
00027 from play_motion_msgs.msg import PlayMotionAction, PlayMotionGoal
00028
00029
00030 def show_usage():
00031 """Show usage information giving the possible motions to use."""
00032
00033 param_names = rospy.get_param_names()
00034 motion_names = []
00035 for param_name in param_names:
00036
00037 if "/play_motion/motions" in param_name and '/joints' in param_name:
00038 motion_name = param_name.replace('/play_motion/motions/', '')
00039 motion_name = motion_name.replace('/joints', '')
00040 motion_names.append(motion_name)
00041
00042 rospy.loginfo("""Usage:
00043
00044 \trosrun run_motion run_motion_python_node.py MOTION_NAME"
00045
00046 \twhere MOTION_NAME must be one of the motions listed in: """ + str(motion_names))
00047
00048
00049 def wait_for_valid_time(timeout):
00050 """Wait for a valid time (non-zero), this is important
00051 when using a simulated clock"""
00052
00053
00054
00055
00056
00057 start_time = time.time()
00058 while not rospy.is_shutdown():
00059 if not rospy.Time.now().is_zero():
00060 return
00061 if time.time() - start_time > timeout:
00062 rospy.logerr("Timed-out waiting for valid time.")
00063 exit(0)
00064 time.sleep(0.1)
00065
00066 exit(0)
00067
00068
00069 def get_status_string(status_code):
00070 return GoalStatus.to_string(status_code)
00071
00072 if __name__ == '__main__':
00073 rospy.init_node('run_motion_python')
00074 if len(sys.argv) < 2:
00075 show_usage()
00076 exit(0)
00077
00078 rospy.loginfo("Starting run_motion_python application...")
00079 wait_for_valid_time(10.0)
00080
00081 client = SimpleActionClient('/play_motion', PlayMotionAction)
00082
00083 rospy.loginfo("Waiting for Action Server...")
00084 client.wait_for_server()
00085
00086 goal = PlayMotionGoal()
00087 goal.motion_name = sys.argv[1]
00088 goal.skip_planning = False
00089 goal.priority = 0
00090
00091 rospy.loginfo("Sending goal with motion: " + sys.argv[1])
00092 client.send_goal(goal)
00093
00094 rospy.loginfo("Waiting for result...")
00095 action_ok = client.wait_for_result(rospy.Duration(30.0))
00096
00097 state = client.get_state()
00098
00099 if action_ok:
00100 rospy.loginfo("Action finished succesfully with state: " + str(get_status_string(state)))
00101 else:
00102 rospy.logwarn("Action failed with state: " + str(get_status_string(state)))