00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 import roslib; roslib.load_manifest('srs_decision_making')
00055 import os
00056
00057
00058 from srs_generic_states import *
00059
00060
00061
00062 from simple_grasp_states import *
00063
00064
00065
00066 from move_arm_states import *
00067
00068 try:
00069
00070 from srs_grasp_states import *
00071 except ImportError:
00072 rospy.logwarn ('Package srs_grasping NOT ready! You can only use simple grasp NOT srs grasp')
00073
00074 from srs_grasp_dummy_states import *
00075
00076 try:
00077
00078 from arm_manip_states import *
00079 except ImportError:
00080 rospy.logwarn ('Package srs_assisted_arm_navigation NOT ready, You can NOT use srs assisted grasp')
00081
00082 from arm_manip_dummy_states import *
00083
00084
00085
00086 from srs_knowledge.srv import *
00087
00088
00089 from srs_common_high_level_statemachines import *
00090 from srs_detection_high_level_statemachines import *
00091
00092
00093
00094
00095
00096
00097 """
00098 This file contains high level state machines for grasp in decision making.
00099 The actual implementation of the states can be found from
00100 srs_states packages
00101
00102 Depend on if there is any user client connected and the type of the user client,
00103 state machines below may switch between semi-autonomous or fully-autonomous mode mode.
00104
00105 If semi_autonomous_mode=True Generic states of user interventions will be loaded for error handling
00106 Otherwise, generic states based on semantic kb for error handling will be loaded
00107
00108 The default mode is semi_autonomous_mode=False assuming no UI connected to the robot
00109
00110 sm_simple_grasp()
00111 #simple detection with no user intervention and no environment confirmation
00112
00113 sm_simple_detection_env()
00114 #simple detection with no user intervention but with environment confirmation
00115
00116 sm_assisted_detection()
00117 #assisted detection with user intervention and no environment confirmation
00118
00119 sm_assisted_detection_env()
00120 #assisted detection with user intervention and environment confirmation
00121 """
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 class sm_srs_grasp_simple (smach.StateMachine):
00143 def __init__(self):
00144 smach.StateMachine.__init__(self,
00145 outcomes=['succeeded', 'not_completed', 'failed', 'preempted'],
00146 input_keys=['target_object_name','target_object_id', 'target_object','target_workspace_name','semi_autonomous_mode'],
00147 output_keys=['grasp_categorisation', 'surface_distance'])
00148 self.userdata.surface_distance = -1000
00149
00150 self.max_retries = 5
00151 try:
00152 self.max_retries = rospy.get_param("srs/common/grasp_max_retries")
00153 except Exception, e:
00154 rospy.INFO('can not read parameter of max retries, use the default value')
00155
00156
00157 with self:
00158 smach.StateMachine.add('SELECT_GRASP-simple', select_simple_grasp(),
00159 transitions={'succeeded':'GRASP-simple', 'failed':'failed', 'preempted':'preempted'},
00160 remapping={'grasp_categorisation':'grasp_categorisation', 'object':'target_object'})
00161
00162 smach.StateMachine.add('GRASP-simple', simple_grasp(self.max_retries),
00163 transitions={'succeeded':'succeeded', 'retry':'GRASP-simple', 'no_more_retries':'not_completed', 'failed':'failed','preempted':'preempted'},
00164 remapping={'object':'target_object', 'grasp_categorisation':'grasp_categorisation'})
00165
00166
00167
00168
00169
00170
00171
00172 class sm_srs_grasp_assisted (smach.StateMachine):
00173 def __init__(self):
00174 smach.StateMachine.__init__(self,
00175 outcomes=['succeeded', 'not_completed', 'failed', 'stopped', 'preempted'],
00176 input_keys=['target_object_name','target_object_id', 'target_object','target_workspace_name','semi_autonomous_mode'],
00177 output_keys=['grasp_categorisation', 'surface_distance'])
00178
00179 self.userdata.grasp_configuration = ""
00180 self.userdata.poses = ""
00181 self.userdata.base_pose = ""
00182 self.userdata.index_of_the_selected_pose = 1
00183 self.pose_of_the_target_object = ''
00184 self.bb_of_the_target_object = ''
00185
00186 self.max_retries = 5
00187 self.detection_type = 'simple'
00188
00189 try:
00190 self.detection_type = rospy.get_param("srs/detection_type")
00191 except Exception, e:
00192 rospy.INFO('can not read parameter of detection type, use the default value')
00193
00194 try:
00195 self.max_retries = rospy.get_param("srs/common/grasp_max_retries")
00196 except Exception, e:
00197 rospy.INFO('can not read parameter of max retries, use the default value')
00198
00199
00200 with self:
00201
00202 smach.StateMachine.add('PREPARE', assisted_arm_navigation_prepare(),
00203 transitions={'succeeded':'GRASP_SELECT', 'failed':'failed', 'preempted':'preempted'},
00204 remapping={'pose_of_the_target_object':'pose_of_the_target_object', 'bb_of_the_target_object':'bb_of_the_target_object', 'object':'target_object'})
00205
00206 smach.StateMachine.add('GRASP_SELECT', select_srs_grasp(),
00207 transitions={'succeeded':'GRASP_MOVE_ARM', 'not_possible':'GRASP_MOVE_ARM', 'failed':'failed', 'preempted':'preempted'},
00208 remapping={'grasp_configuration':'grasp_configuration', 'poses':'poses', 'object':'target_object', 'target_object_id':'target_object_id'})
00209
00210 smach.StateMachine.add('GRASP_MOVE_ARM', move_arm_to_given_positions_assisted(),
00211 transitions={'succeeded':'GRASP_SRS_GRASP', 'not_completed':'not_completed', 'failed':'failed', 'preempted':'preempted'},
00212 remapping={'name_of_the_target_object':'target_object_name', 'list_of_target_positions':'poses', 'pose_of_the_target_object':'pose_of_the_target_object', 'bb_of_the_target_object':'bb_of_the_target_object'})
00213
00214 smach.StateMachine.add('GRASP_SRS_GRASP', srs_grasp(),
00215 transitions={'succeeded':'succeeded', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted'},
00216 remapping={'grasp_configuration_id':'index_of_the_selected_pose', 'grasp_configuration':'grasp_configuration', 'grasp_categorisation':'grasp_categorisation', 'surface_distance':'surface_distance'})
00217
00218
00219
00220
00221
00222
00223
00224 class sm_srs_grasp_planned (smach.StateMachine):
00225 def __init__(self):
00226 smach.StateMachine.__init__(self,
00227 outcomes=['succeeded', 'not_completed', 'failed', 'stopped', 'preempted'],
00228 input_keys=['target_object_name','target_object_id', 'target_object','target_workspace_name','semi_autonomous_mode'],
00229 output_keys=['grasp_categorisation','surface_distance'])
00230
00231 self.userdata.grasp_configuration = ""
00232 self.userdata.poses = ""
00233 self.userdata.base_pose = ""
00234 self.userdata.index_of_the_selected_pose = 0
00235 self.userdata.grasp_categorisation = ""
00236 self.max_retries = 5
00237 self.detection_type = 'simple'
00238
00239 try:
00240 self.detection_type = rospy.get_param("srs/detection_type")
00241 except Exception, e:
00242 rospy.INFO('can not read parameter of detection type, use the default value')
00243
00244 try:
00245 self.max_retries = rospy.get_param("srs/common/grasp_max_retries")
00246 except Exception, e:
00247 rospy.INFO('can not read parameter of max retries, use the default value')
00248
00249
00250 step_after_grasp_select = 'GRASP_SRS_GRASP'
00251
00252 self.ipa_arm_navigation = 'False'
00253
00254
00255 self.step_after_grasp_select = 'failed'
00256
00257 try:
00258 self.ipa_arm_navigation = rospy.get_param("srs/ipa_arm_navigation")
00259 except Exception, e:
00260 rospy.INFO('can not read parameter of srs/ipa_arm_navigation, use the default value planned arm navigation disabled')
00261
00262 if self.ipa_arm_navigation.lower() == 'true':
00263
00264 step_after_grasp_select = 'GRASP_MOVE_ARM'
00265 else:
00266
00267 step_after_grasp_select = 'GRASP_SRS_GRASP'
00268
00269
00270 if self.detection_type.lower() == 'simple':
00271 with self:
00272
00273 smach.StateMachine.add('GRASP_SELECT', select_srs_grasp(),
00274 transitions={'succeeded':step_after_grasp_select, 'not_possible':'GRASP_BEST_BASE_POSE_ESTIMATION', 'failed':'failed', 'preempted':'preempted'},
00275 remapping={'grasp_configuration':'grasp_configuration', 'poses':'poses', 'object':'target_object', 'target_object_id':'target_object_id'})
00276
00277 smach.StateMachine.add('GRASP_MOVE_ARM', move_arm_planned(),
00278 transitions={'succeeded':'GRASP_SRS_GRASP', 'not_completed':'GRASP_SRS_GRASP', 'failed':'failed', 'preempted':'preempted'},
00279 remapping={'poses':'poses', 'index_of_the_selected_pose':'pose_id'})
00280
00281 smach.StateMachine.add('GRASP_SRS_GRASP', srs_grasp(),
00282 transitions={'succeeded':'succeeded', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted', 'retry':'GRASP_BEST_BASE_POSE_ESTIMATION'},
00283 remapping={'grasp_configuration_id':'index_of_the_selected_pose', 'grasp_configuration':'grasp_configuration', 'grasp_categorisation':'grasp_categorisation', 'surface_distance':'surface_distance' })
00284
00285 smach.StateMachine.add('GRASP_BEST_BASE_POSE_ESTIMATION', grasp_base_pose_estimation(),
00286 transitions={'retry':'GRASP_MOVE_BASE', 'not_retry':'not_completed', 'failed':'failed','preempted':'preempted'},
00287 remapping={'object':'target_object', 'target_workspace_name':'target_workspace_name', 'base_pose':'base_pose'})
00288
00289 smach.StateMachine.add('GRASP_MOVE_BASE', approach_pose_without_retry(),
00290 transitions={'succeeded':'GRASP_DETECT_SIMPLE', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted'},
00291 remapping={'object':'target_object', 'grasp_configuration':'grasp_configuration', 'base_pose':'base_pose'})
00292
00293 smach.StateMachine.add('GRASP_DETECT_SIMPLE', sm_simple_detection(),
00294 transitions={'succeeded':'GRASP_SELECT', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted'},
00295 remapping={'target_object':'target_object', 'target_object_name':'target_object_name', 'target_object_id':'target_object_id', 'target_workspace_name':'target_workspace_name'})
00296
00297 else:
00298 with self:
00299
00300 smach.StateMachine.add('GRASP_SELECT', select_srs_grasp(),
00301 transitions={'succeeded':step_after_grasp_select, 'not_possible':'GRASP_BEST_BASE_POSE_ESTIMATION', 'failed':'failed', 'preempted':'preempted'},
00302 remapping={'grasp_configuration':'grasp_configuration', 'poses':'poses', 'object':'target_object', 'target_object_id':'target_object_id'})
00303
00304 smach.StateMachine.add('GRASP_MOVE_ARM', move_arm_planned(),
00305 transitions={'succeeded':'GRASP_SRS_GRASP', 'not_completed':'GRASP_SRS_GRASP', 'failed':'failed', 'preempted':'preempted'},
00306 remapping={'poses':'poses', 'index_of_the_selected_pose':'pose_id'})
00307
00308 smach.StateMachine.add('GRASP_SRS_GRASP', srs_grasp(),
00309 transitions={'succeeded':'succeeded', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted', 'retry':'GRASP_BEST_BASE_POSE_ESTIMATION'},
00310 remapping={'grasp_configuration_id':'index_of_the_selected_pose', 'grasp_configuration':'grasp_configuration', 'grasp_categorisation':'grasp_categorisation', 'surface_distance':'surface_distance' })
00311
00312 smach.StateMachine.add('GRASP_BEST_BASE_POSE_ESTIMATION', grasp_base_pose_estimation(),
00313 transitions={'retry':'GRASP_MOVE_BASE', 'not_retry':'not_completed', 'failed':'failed','preempted':'preempted'},
00314 remapping={'object':'target_object', 'target_workspace_name':'target_workspace_name', 'base_pose':'base_pose'})
00315
00316 smach.StateMachine.add('GRASP_MOVE_BASE', approach_pose_without_retry(),
00317 transitions={'succeeded':'GRASP_DETECT_ASSISTED', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted'},
00318 remapping={'object':'target_object', 'grasp_configuration':'grasp_configuration', 'base_pose':'base_pose'})
00319
00320 smach.StateMachine.add('GRASP_DETECT_ASSISTED', sm_assisted_detection(),
00321 transitions={'succeeded':'GRASP_SELECT', 'not_completed':'not_completed', 'failed':'failed','preempted':'preempted'},
00322 remapping={'target_object':'target_object', 'target_object_name':'target_object_name', 'target_object_id':'target_object_id', 'target_workspace_name':'target_workspace_name'})
00323
00324
00325