NBVTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 '''
4 Copyright (c) 2016, Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meissner Pascal, Trautmann Jeremias, Wittenbeck Valerij
5 
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 
12 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.
13 
14 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.
15 
16 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.
17 '''
18 
19 import roslib; roslib.load_manifest('asr_state_machine')
20 import rospy
21 import smach
22 import smach_ros
23 import json
24 import random
25 import numpy as np
26 import tf
27 import threading
28 #from States import *
29 import __builtin__ # hack for sharing log dir
30 
31 from pose_sampling import *
32 
33 # To import files from parten directories
34 if __name__ == '__main__' and __package__ is None:
35  from os import sys, path
36  sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
37 
38 import common.init
39 from common.common_sm import GetMoveRobotSateMachine
40 from indirect_search.ism import *
41 from indirect_search.nbv import *
42 from common.object_detection import *
43 from common.visualize_waypoints import VisualizeWaypoints
44 
45 """
46 Simple test implementing the same test case than Ralfs NBV test in the NBV
47 package. It samples some points and moves to them to invalidate.
48 """
49 
50 def main():
51  rospy.init_node('nbv_test_automat')
52 
53  log_dir = common.init.create_log_folder()
54  __builtin__.log_dir = log_dir
55  __builtin__.evaluation = False
56 
57 
58  sm_object_search = smach.StateMachine(outcomes=['succeeded', 'aborted',
59  'no_nbv_found'],
60  input_keys=['object_pointcloud'])
61 
62  with sm_object_search:
63  # IN: object_point_cloud
64  smach.StateMachine.add('NBV_SET_POINT_CLOUD',
66  transitions={'succeeded':'NEXT_BEST_VIEW',
67  'aborted':'aborted',
68  'too_many_deactivated_normals':'aborted'},
69  remapping={'object_pointcloud':'object_pointcloud'})
70 
71  # OUT: goal_robot_pose, goal_ptu_position, goal_camera_pose
72  smach.StateMachine.add('NEXT_BEST_VIEW',
73  NextBestView(),
74  transitions={'found_next_best_view':'MOVE_ROBOT_TO_VIEW',
75  'aborted':'aborted',
76  'no_nbv_found':'aborted',
77  'nbv_update_point_cloud':'NBV_UPDATE'},
78  remapping={'goal_camera_pose':'goal_camera_pose',
79  'goal_robot_pose':'goal_robot_pose',
80  'goal_ptu_position':'goal_ptu_position',
81  'searched_object_types':'searched_object_types'})
82 
83  # IN:
84  smach.StateMachine.add('MOVE_ROBOT_TO_VIEW',
86  transitions={'succeeded':'VISUALIZE_WAYPOINT',
87  'aborted':'aborted'},
88  remapping={'goal_robot_pose':'goal_robot_pose',
89  'goal_ptu_position':'goal_ptu_position'})
90 
91  smach.StateMachine.add('VISUALIZE_WAYPOINT',
93  transitions={'succeeded': 'OBJECT_DETECTION'})
94 
95  # smach.StateMachine.add('CURRENT_POSE',
96  # CurrentPose(),
97  # transitions={'succeeded': 'OBJECT_DETECTION'})
98 
99  smach.StateMachine.add('OBJECT_DETECTION',
100  ObjectDetection(),
101  transitions={'no_objects_found':'NBV_UPDATE',
102  'found_objects':'succeeded',
103  'aborted':'aborted'},
104  remapping={'searched_object_types':'object',
105  'detected_objects':'detected_objects'})
106 
107  smach.StateMachine.add('NBV_UPDATE',
109  transitions={'succeeded':'NEXT_BEST_VIEW',
110  'aborted':'aborted',
111  'no_nbv_found':'aborted'},
112  remapping={'goal_camera_pose':'goal_camera_pose',
113  'searched_object_types':'searched_object_types'})
114 
115 
116 
117  sm_main = smach.StateMachine(outcomes=['succeeded',
118  'aborted','no_nbv_found'])
119  with sm_main:
120 
121 
122  smach.StateMachine.add('INIT',
124  transitions={'succeeded':'VISUALIZE_WAYPOINT',
125  'aborted':'aborted'},
126  remapping={'searched_object_types':'searched_object_types'})
127 
128  smach.StateMachine.add('VISUALIZE_WAYPOINT',
130  transitions={'succeeded': 'POSE_SAMPLING'})
131 
132  smach.StateMachine.add('POSE_SAMPLING',
133  PoseSampling(),
134  remapping={'object_pointcloud':
135  'object_pointcloud'},
136  transitions={'succeeded': 'OBJECT_SEARCH',
137  'aborted': 'aborted'})
138 
139  smach.StateMachine.add('OBJECT_SEARCH',
140  sm_object_search,
141  transitions={'succeeded': 'succeeded'})
142 
143  server = smach_ros.IntrospectionServer(
144  'nbv_test_automat',
145  sm_main,
146  '/NBV_TEST_SM')
147  server.start()
148  # smach.set_preempt_hanlder(sm_main)
149  smach_thread = threading.Thread(target = sm_main.execute)
150  smach_thread.start()
151  rospy.spin()
152  server.stop()
153  rospy.signal_shutdown('All done.')
154 
155 
156 if __name__ == '__main__':
157  try:
158  main()
159  except rospy.ROSInterruptException: pass
def GetMoveRobotSateMachine()
Definition: common_sm.py:29


asr_state_machine
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Hutmacher Robin, Karrenbauer Oliver, Marek Felix, Meißner Pascal, Trautmann Jeremias, Wittenbeck Valerij
autogenerated on Mon Feb 28 2022 21:53:50