pr2_sample_chooser.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 import roslib; roslib.load_manifest('pr2_calibration_launch')
35 import rospy
36 import yaml
37 import sys
38 import capture_executive.capture_exec
39 import time
40 from calibration_msgs.msg import RobotMeasurement
41 import os
42 import string
43 
44 print("Starting executive...")
45 time.sleep(7.0)
46 
47 rospy.init_node("pr2_capture_executive_node")
48 
49 samples_dir = rospy.myargv()[1]
50 config_dir = rospy.myargv()[2]
51 
52 executive = capture_executive.capture_exec.CaptureExecutive(config_dir)
53 time.sleep(1.0)
54 
55 left_sample_names = [x for x in os.listdir(samples_dir + "/left/") if ".yaml" in x]
56 right_sample_names = []
57 far_sample_names = []
58 right_sample_names = [x for x in os.listdir(samples_dir + "/right/") if ".yaml" in x]
59 far_sample_names = [x for x in os.listdir(samples_dir + "/far/") if ".yaml" in x]
60 
61 left_sample_names.sort()
62 right_sample_names.sort()
63 far_sample_names.sort()
64 
65 print("Left Samples: \n - %s" % "\n - ".join(left_sample_names))
66 print("Right Samples: \n - %s" % "\n - ".join(right_sample_names))
67 print("Far Samples: \n - %s" % "\n - ".join(far_sample_names))
68 
69 pub = rospy.Publisher("robot_measurement", RobotMeasurement)
70 
71 far_success_count = 0
72 left_success_count = 0
73 left_fail_count = 0
74 right_success_count = 0
75 right_fail_count = 0
76 
77 
78 try:
79  # Capture Far Checkerboards
80  keep_collecting = True
81 
82  while not rospy.is_shutdown() and keep_collecting:
83  print("Choose L,R, or F")
84  resp = input("> ")
85  if string.upper(resp) == "L":
86  print("Choose sample index")
87  resp = input("> ")
88  cur_sample_path = samples_dir + "/left/" + left_sample_names[int(resp)]
89  elif string.upper(resp) == "R":
90  print("Choose sample index")
91  resp = input("> ")
92  cur_sample_path = samples_dir + "/right/" + right_sample_names[int(resp)]
93  elif string.upper(resp) == "F":
94  cur_sample_path = samples_dir + "/far/" + far_sample_names[0]
95  elif string.upper(resp) == "":
96  print("Repeating Previous Command")
97  else:
98  print("Unknown input. Exiting")
99  break
100 
101  print("On sample [%s]" % cur_sample_path)
102  cur_config = yaml.load(open(cur_sample_path))
103 
104  print("Choose Timeout")
105  timeout = input("> ")
106  if timeout == "":
107  timeout = "1.0"
108 
109  m_robot = executive.capture(cur_config, rospy.Duration(float(timeout)))
110  if m_robot is None:
111  print("--------------- Failed To Capture a Far Sample -----------------")
112  else:
113  print("++++++++++++++ Successfully Captured a Far Sample ++++++++++++++")
114  pub.publish(m_robot)
115 
116 
117 except EOFError:
118  print("Exiting")
119 


pr2_calibration_launch
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:59