00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import roslib; roslib.load_manifest('pr2_calibration_launch')
00035 import rospy
00036 import yaml
00037 import sys
00038 import pr2_calibration_executive.capture_exec
00039 import time
00040 from calibration_msgs.msg import RobotMeasurement
00041 import os
00042
00043 rospy.init_node("capture_executive_node")
00044
00045
00046 autorun = (rospy.myargv()[1] == "auto")
00047 samples_dir = rospy.myargv()[2]
00048 config_dir = rospy.myargv()[3]
00049
00050 executive = pr2_calibration_executive.capture_exec.CaptureExecutive(config_dir)
00051 time.sleep(1.0)
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 sample_names = [x for x in os.listdir(samples_dir) if ".yaml" in x]
00064 sample_names.sort()
00065
00066 print "Going to execute samples: %s" % sample_names
00067
00068 pub = rospy.Publisher("robot_measurement", RobotMeasurement)
00069
00070 ok = True
00071
00072 n = 0
00073 try:
00074 while ok and not rospy.is_shutdown() and n < len(sample_names):
00075 sample_name = sample_names[n]
00076 print "Currently on sample [%s]" % sample_name
00077 print "(L)oad, (B)ackwards, (F)orwards, (Q)uit"
00078 if autorun:
00079 if n == len(sample_names):
00080 print "Done. Exiting..."
00081 ok = False
00082 resp = "Q"
00083 else:
00084 resp = "L"
00085 n += 1
00086 else:
00087 resp = raw_input("> ").upper()
00088 if resp == "L":
00089 cur_config = yaml.load(open(samples_dir + "/" + sample_name))
00090 m_robot = executive.capture(cur_config, rospy.Duration(40))
00091 if m_robot is None:
00092 print "************** Didn't get a sample *****************"
00093 else:
00094 print "__________ Got a sample! ____________________"
00095 pub.publish(m_robot)
00096 elif resp == "B":
00097 if n is 0:
00098 print "Already on first sample. Can't do anything"
00099 else:
00100 n -= 1
00101 elif resp == "F":
00102 if n is len(sample_names)-1:
00103 print "Already on last sample. Can't do anything"
00104 else:
00105 n += 1
00106 elif resp == "Q":
00107 print "Exiting..."
00108 ok = False
00109 else:
00110 print "Unknown request"
00111 print ""
00112 except EOFError:
00113 print "Exiting"
00114
00115 rospy.spin()