pr2_se_exec.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Software License Agreement (BSD License)
3 #
4 # Copyright (c) 2008, Willow Garage, Inc.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following
15 # disclaimer in the documentation and/or other materials provided
16 # with the distribution.
17 # * Neither the name of Willow Garage, Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 
34 # Modified from original executive on 11/11 by Adam Leeper
35 
36 import roslib; roslib.load_manifest('pr2_calibration_launch')
37 import rospy
38 import yaml
39 import sys
40 import pr2_calibration_executive.capture_exec
41 import time
42 from calibration_msgs.msg import RobotMeasurement
43 import os
44 import string
45 
46 print("Starting executive...")
47 time.sleep(7.0)
48 
49 rospy.init_node("pr2_capture_executive_node")
50 
51 samples_dir = rospy.myargv()[1]
52 config_dir = rospy.myargv()[2]
53 
54 executive = pr2_calibration_executive.capture_exec.CaptureExecutive(config_dir)
55 time.sleep(1.0)
56 
57 left_sample_names = [x for x in os.listdir(samples_dir + "/left/") if ".yaml" in x]
58 right_sample_names = []
59 far_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]
62 
63 left_sample_names.sort()
64 right_sample_names.sort()
65 far_sample_names.sort()
66 
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))
70 
71 pub = rospy.Publisher("robot_measurement", RobotMeasurement)
72 
73 far_success_count = 0
74 left_success_count = 0
75 left_fail_count = 0
76 right_success_count = 0
77 right_fail_count = 0
78 
79 # TODO Add support for right OR left arm
80 capture_right_arm_data = True
81 capture_left_arm_data = False
82 
83 try:
84  # Capture Far Checkerboards
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))
89 
90  while not rospy.is_shutdown() and keep_collecting:
91 
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")
95  resp = input("> ")
96  if string.upper(resp) == "N":
97  print("Done collecting far samples")
98  keep_collecting = False
99  else:
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))
104  if m_robot is None:
105  print("--------------- Failed To Capture a Far Sample -----------------")
106  else:
107  print("++++++++++++++ Successfully Captured a Far Sample ++++++++++++++")
108  far_success_count += 1
109  pub.publish(m_robot)
110  print("Succeeded on %u far samples" % far_success_count)
111  if rospy.is_shutdown():
112  break
113 
114  # Capture Left Arm Data
115  if capture_left_arm_data and not rospy.is_shutdown():
116  full_paths = [samples_dir + "/left/" + x for x in left_sample_names]
117 
118  cur_config = yaml.load(open(full_paths[0]))
119  m_robot = executive.capture(cur_config, rospy.Duration(0.01))
120 
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")
125  else:
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))
130  if m_robot is None:
131  print("--------------- Failed To Capture a Left Hand Sample -----------------")
132  left_fail_count += 1
133  else:
134  print("++++++++++++++ Successfully Captured a Left Hand Sample ++++++++++++++")
135  left_success_count += 1
136  pub.publish(m_robot)
137  print("Succeded on %u/%u left arm samples" % (left_success_count, left_fail_count + left_success_count))
138  if rospy.is_shutdown():
139  break
140 
141  # Capture Right Arm Data
142  if capture_right_arm_data and not rospy.is_shutdown():
143  full_paths = [samples_dir + "/right/" + x for x in right_sample_names]
144 
145  cur_config = yaml.load(open(full_paths[0]))
146  m_robot = executive.capture(cur_config, rospy.Duration(0.01))
147 
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")
152  else:
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))
157  if m_robot is None:
158  print("--------------- Failed To Capture a Right Hand Sample -----------------")
159  right_fail_count += 1
160  else:
161  print("++++++++++++++ Successfully Captured a Right Hand Sample ++++++++++++++")
162  right_success_count += 1
163  pub.publish(m_robot)
164  print("Succeded on %u/%u right arm samples" % (right_success_count, right_fail_count + right_success_count))
165  if rospy.is_shutdown():
166  break
167 
168 except EOFError:
169  print("Exiting")
170 
171 time.sleep(1)
172 
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))
177 print("")
178 print("You can now kill this node, along with any other calibration nodes that are running.")


pr2_se_calibration_launch
Author(s): Adam Leeper, Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:51:02