recognizer_prediction_psm_test.py
Go to the documentation of this file.
1 '''
2 Copyright (c) 2016, Braun Kai, Meissner Pascal
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 
9 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 
11 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12 
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 '''
15 
16 from asr_msgs.msg import AsrObject
18 import roslib
19 import rospy
20 import os
21 from visualization_msgs.msg import Marker
22 from visualization_msgs.msg import MarkerArray
23 import signal
24 import sys
25 import rospkg
26 
27 from geometry_msgs.msg import PoseWithCovariance
28 
29 def main():
30  objects = []
31 
32  obj = AsrObject()
33  obj.type = 'VitalisSchoko'
34  obj.identifier = '/map'
35  obj.header.frame_id = '/map'
36  poseWithCovariance = PoseWithCovariance()
37  poseWithCovariance.pose.position.x = -0.3
38  poseWithCovariance.pose.position.y = -1
39  poseWithCovariance.pose.position.z = -0.6
40  poseWithCovariance.pose.orientation.w = 0.5
41  poseWithCovariance.pose.orientation.x = 0
42  poseWithCovariance.pose.orientation.y = 0
43  poseWithCovariance.pose.orientation.z = -0.5
44  obj.sampledPoses.append(poseWithCovariance)
45  objects.append(obj)
46 
47  obj2 = AsrObject()
48  obj2.type = 'PlateDeep'
49  obj2.identifier = '/map'
50  obj2.header.frame_id = '/map'
51  poseWithCovariance.pose.position.x = -0.51
52  poseWithCovariance.pose.position.y = -1.2
53  poseWithCovariance.pose.position.z = -0.65
54  poseWithCovariance.pose.orientation.w = 0.5
55  poseWithCovariance.pose.orientation.x = 0.0
56  poseWithCovariance.pose.orientation.y = 0.0
57  poseWithCovariance.pose.orientation.z = -0.5
58  obj2.sampledPoses.append(poseWithCovariance)
59  #objects.append(obj2)
60 
61  obj2 = AsrObject()
62  obj2.type = 'Cup'
63  obj2.identifier = '/map'
64  obj2.header.frame_id = '/map'
65  poseWithCovariance.pose.position.x = 0
66  poseWithCovariance.pose.position.y = -1.13
67  poseWithCovariance.pose.position.z = -0.65
68  poseWithCovariance.pose.orientation.w = 0.5
69  poseWithCovariance.pose.orientation.x = 0.0
70  poseWithCovariance.pose.orientation.y = 0.0
71  poseWithCovariance.pose.orientation.z = -0.5
72  obj2.sampledPoses.append(poseWithCovariance)
73  #objects.append(obj2)
74 
75 
76 
77  path = rospkg.RosPack().get_path('asr_recognizer_prediction_psm') + '/models/dome_scene1.xml'
78 
79  scenes = []
80  scenes.append('background')
81  scenes.append('marker_scene1')
82  scenes.append('marker_scene2')
83 
84 
85  scene_probabilities = []
86  scene_probabilities.append(0.25)
87  scene_probabilities.append(0.5)
88  scene_probabilities.append(0.25)
89 
90  num_overall_hypothesis = 10
91 
92  base_frame = '/map'
93 
94 
95  try:
96  rospy.wait_for_service('/recognizer_prediction_psm', timeout=5)
97 
98  except rospy.exceptions.ROSException, e:
99  rospy.loginfo('Could not reach service')
100 
101  try:
102  generate_hypothesis = rospy.ServiceProxy('/recognizer_prediction_psm', recognizer_prediction_psm)
103 
104  # call the service
105  # the parameters are: the path to the xml file,
106  # a list of the scenes,
107  # a list of the scene probabilities,
108  # the number of hypothesis that should be generated,
109  # a list of already observed objects,
110  # the frame to which the objects and the hypothesis should be transformed into
111  response = generate_hypothesis(path,
112  scenes,
113  scene_probabilities,
114  num_overall_hypothesis,
115  objects,
116  base_frame)
117 
118  # print the results
119  #print(response)
120  print('All scene objects found: ' + str(response.all_scene_objects_found))
121 
122  return response.pose_hypothesis.elements
123 
124 
125 
126  except rospy.ServiceException, e:
127  rospy.loginfo('Could not generate hyps')
128 
129  return []
130 
131 # This method catches the abort signal crtl + c
132 def signal_handler(signal, frame):
133  sys.exit(0)
134 
135 
136 
137 if __name__ == '__main__':
138  # catch ctrl + c
139  signal.signal(signal.SIGINT, signal_handler)
140 
141 
142  topic = '/recognizer_prediction_psm/hypothesis_psm_marker_array'
143  hypothesis_cloud = []
144 
145 
146  try:
147  hypothesis_cloud = main()
148  except rospy.ROSInterruptException: pass
149 
150 
151 
152 
153 
154 
155 
156 
157 


asr_recognizer_prediction_psm
Author(s): Braun Kai, Meißner Pascal
autogenerated on Wed Feb 19 2020 03:31:30