36 import roslib; roslib.load_manifest(
'pr2_calibration_launch')
40 import pr2_calibration_executive.capture_exec
42 from calibration_msgs.msg
import RobotMeasurement
46 print(
"Starting executive...")
49 rospy.init_node(
"pr2_capture_executive_node")
51 samples_dir = rospy.myargv()[1]
52 config_dir = rospy.myargv()[2]
54 executive = pr2_calibration_executive.capture_exec.CaptureExecutive(config_dir)
57 left_sample_names = [x
for x
in os.listdir(samples_dir +
"/left/")
if ".yaml" in x]
58 right_sample_names = []
60 right_sample_names = [x
for x
in os.listdir(samples_dir +
"/right/")
if ".yaml" in x]
61 far_sample_names = [x
for x
in os.listdir(samples_dir +
"/far/")
if ".yaml" in x]
63 left_sample_names.sort()
64 right_sample_names.sort()
65 far_sample_names.sort()
67 print(
"Left Samples: \n - %s" %
"\n - ".join(left_sample_names))
68 print(
"Right Samples: \n - %s" %
"\n - ".join(right_sample_names))
69 print(
"Far Samples: \n - %s" %
"\n - ".join(far_sample_names))
71 pub = rospy.Publisher(
"robot_measurement", RobotMeasurement)
74 left_success_count = 0
76 right_success_count = 0
80 capture_right_arm_data =
True 81 capture_left_arm_data =
False 85 keep_collecting =
True 86 full_paths = [samples_dir +
"/far/" + x
for x
in far_sample_names]
87 cur_config = yaml.load(open(full_paths[0]))
88 m_robot = executive.capture(cur_config, rospy.Duration(0.01))
90 while not rospy.is_shutdown()
and keep_collecting:
92 print(
"Please place the large 7x6 checkerboard approx 3m in front of the robot")
93 print(
"in view of the head cameras and tilting laser.")
94 print(
"Press <enter> when ready to collect data, or type \"N\" if done collecting large checkerboards")
96 if string.upper(resp) ==
"N":
97 print(
"Done collecting far samples")
98 keep_collecting =
False 100 for cur_sample_path
in full_paths:
101 print(
"On far sample [%s]" % cur_sample_path)
102 cur_config = yaml.load(open(cur_sample_path))
103 m_robot = executive.capture(cur_config, rospy.Duration(40))
105 print(
"--------------- Failed To Capture a Far Sample -----------------")
107 print(
"++++++++++++++ Successfully Captured a Far Sample ++++++++++++++")
108 far_success_count += 1
110 print(
"Succeeded on %u far samples" % far_success_count)
111 if rospy.is_shutdown():
115 if capture_left_arm_data
and not rospy.is_shutdown():
116 full_paths = [samples_dir +
"/left/" + x
for x
in left_sample_names]
118 cur_config = yaml.load(open(full_paths[0]))
119 m_robot = executive.capture(cur_config, rospy.Duration(0.01))
121 print(
"Please put the checkerboard in the left hand (open/close the gripper with the joystick's left/right D-Pad buttons). press <enter> to continue. Type N to skip")
122 resp = input(
"press <enter> ")
123 if string.upper(resp) ==
"N":
124 print(
"Skipping left arm samples")
126 for cur_sample_path
in full_paths:
127 print(
"On left arm sample [%s]" % cur_sample_path)
128 cur_config = yaml.load(open(cur_sample_path))
129 m_robot = executive.capture(cur_config, rospy.Duration(40))
131 print(
"--------------- Failed To Capture a Left Hand Sample -----------------")
134 print(
"++++++++++++++ Successfully Captured a Left Hand Sample ++++++++++++++")
135 left_success_count += 1
137 print(
"Succeded on %u/%u left arm samples" % (left_success_count, left_fail_count + left_success_count))
138 if rospy.is_shutdown():
142 if capture_right_arm_data
and not rospy.is_shutdown():
143 full_paths = [samples_dir +
"/right/" + x
for x
in right_sample_names]
145 cur_config = yaml.load(open(full_paths[0]))
146 m_robot = executive.capture(cur_config, rospy.Duration(0.01))
148 print(
"Please put the checkerboard in the right hand (open/close the gripper with the joystick's square/circle buttons). press <enter> to continue...")
149 resp = input(
"press <enter> ")
150 if string.upper(resp) ==
"N":
151 print(
"Skipping right arm samples")
153 for cur_sample_path
in full_paths:
154 print(
"On right arm sample [%s]" % cur_sample_path)
155 cur_config = yaml.load(open(cur_sample_path))
156 m_robot = executive.capture(cur_config, rospy.Duration(40))
158 print(
"--------------- Failed To Capture a Right Hand Sample -----------------")
159 right_fail_count += 1
161 print(
"++++++++++++++ Successfully Captured a Right Hand Sample ++++++++++++++")
162 right_success_count += 1
164 print(
"Succeded on %u/%u right arm samples" % (right_success_count, right_fail_count + right_success_count))
165 if rospy.is_shutdown():
173 print(
"Calibration data collection has completed!")
174 print(
"Far Samples: %u" % far_success_count)
175 print(
"Left Arm Samples: %u/%u" % (left_success_count, left_fail_count + left_success_count))
176 print(
"Right Arm Samples: %u/%u" % (right_success_count, right_fail_count + right_success_count))
178 print(
"You can now kill this node, along with any other calibration nodes that are running.")