00001
00002 import roslib; roslib.load_manifest('zyonz_apps')
00003 import rospy
00004 import smach
00005 import smach_ros
00006
00007
00008 import os, sys
00009 _root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
00010 sys.path.insert(0, _root_dir)
00011
00012 from smach_ros import ServiceState
00013 from geometry_msgs.msg import PoseStamped
00014 from iri_pointcloud_to_pcd.srv import StorePointcloud, StorePointcloudRequest
00015 from iri_wam_smach.sm_wam_move_from_pose import SM_WAM_MoveFromPose
00016 from iri_common_smach.st_get_pcl import GetPCL
00017 from iri_common_smach.st_transform_pose import TransformPoseStamped
00018 from iri_common_smach.st_sleep import WaitSeconds
00019 from zyonz_apps_base.move import SM_ZYONZ_GoHome
00020
00021 class StorePCDService(smach.State):
00022 def __init__(self):
00023 smach.State.__init__(self, outcomes = ['success','fail'],
00024 input_keys = ['filename','pose_st','pcl'])
00025 def execute(self, userdata):
00026 handler = rospy.ServiceProxy('/zyonz/pointcloud_to_pcd/store_pointcloud', StorePointcloud)
00027
00028 analysis_request = StorePointcloudRequest()
00029 analysis_request.file_name.data = userdata.filename
00030 analysis_request.sensor_pose = userdata.pose_st
00031 analysis_request.point_cloud = userdata.pcl
00032
00033 try:
00034 response = handler(analysis_request)
00035 except rospy.ServiceException, e:
00036 return 'fail'
00037
00038 if (not response):
00039 return 'fail'
00040
00041 return 'success'
00042
00043 class SM_ZYONZ_StorePCD():
00044 def __init__(self):
00045 pass
00046
00047 def build_sm(self):
00048 sm = smach.StateMachine(outcomes = ['succeeded','aborted'],
00049 input_keys = ['pcl_topic',
00050 'store_service',
00051 'pose_st',
00052 'target_frame',
00053 'filename'])
00054 with sm:
00055 smach.StateMachine.add('CAPTURE_PCL', GetPCL(),
00056 transitions = {'success' : 'GET_POSE',
00057 'fail' : 'aborted'},
00058 remapping = {'pcl_topic' : 'pcl_topic',
00059 'pcl_RGB' : 'sm_pcl'})
00060
00061 smach.StateMachine.add('GET_POSE', TransformPoseStamped(),
00062 transitions = {'success' : 'CALL_STORE_SERVICE',
00063 'fail' : 'aborted'},
00064 remapping = {'pose_st' : 'pose_st',
00065 'target_frame' : 'target_frame',
00066 'transformed_pose_st' : 'sm_pose_st'})
00067
00068 smach.StateMachine.add('CALL_STORE_SERVICE', StorePCDService(),
00069 transitions = {'success' : 'succeeded',
00070 'fail' : 'aborted'},
00071 remapping = {'filename' : 'filename',
00072 'pose_st' : 'sm_pose_st',
00073 'pcl' : 'sm_pcl'})
00074
00075 return sm
00076
00077
00078
00079
00080 class SM_ZYONZ_CapturePoint():
00081 def __init__(self):
00082 pass
00083
00084 def build_sm(self):
00085 sm_approching_factory = SM_WAM_MoveFromPose("/zyonz/wam_wrapper/joints_move", "/zyonz/iri_wam_camboard_ik/get_wam_ik")
00086 sm_approching = sm_approching_factory.build_sm()
00087 sm_store_factory = SM_ZYONZ_StorePCD()
00088 sm_store_pcd = sm_store_factory.build_sm()
00089
00090 sm = smach.StateMachine(outcomes = ['succeeded', 'aborted'],
00091 input_keys = ['pcl_topic', 'store_service',
00092 'pose_st_00','pose_st_01',
00093 'pose_st_02','pose_st_03',
00094 'pose_st_04','pose_st_05',
00095 'pose_st_06','pose_st_07',
00096 'filename_00','filename_01',
00097 'filename_02','filename_03',
00098 'filename_04','filename_05',
00099 'filename_06','filename_07',
00100 'target_frame'])
00101
00102 with sm:
00103 smach.StateMachine.add('GO_TO_POSE_00', sm_approching,
00104 transitions={'success': 'STORE_PCD_00',
00105 'no_kinematic_solution': 'aborted',
00106 'aborted': 'aborted' },
00107 remapping = {'pose_st': 'pose_st_00'})
00108
00109 smach.StateMachine.add('STORE_PCD_00', sm_store_pcd,
00110 transitions = {'succeeded' : 'GO_TO_POSE_01',
00111 'aborted' : 'aborted' },
00112 remapping = {'pcl_topic' : 'pcl_topic',
00113 'store_service' : 'store_service',
00114 'pose_st' : 'pose_st_00',
00115 'target_frame' : 'target_frame',
00116 'filename' : 'filename_00'})
00117
00118 smach.StateMachine.add('GO_TO_POSE_01', sm_approching,
00119 transitions={'success': 'STORE_PCD_01',
00120 'no_kinematic_solution': 'aborted',
00121 'aborted': 'aborted' },
00122 remapping = {'pose_st': 'pose_st_01'})
00123
00124 smach.StateMachine.add('STORE_PCD_01', sm_store_pcd,
00125 transitions = {'succeeded': 'GO_TO_POSE_02',
00126 'aborted': 'aborted' },
00127 remapping = {'pcl_topic' : 'pcl_topic',
00128 'store_service' : 'store_service',
00129 'pose_st' : 'pose_st_01',
00130 'target_frame' : 'target_frame',
00131 'filename' : 'filename_01'})
00132
00133 smach.StateMachine.add('GO_TO_POSE_02', sm_approching,
00134 transitions={'success': 'STORE_PCD_02',
00135 'no_kinematic_solution': 'aborted',
00136 'aborted': 'aborted' },
00137 remapping = {'pose_st': 'pose_st_02'})
00138
00139 smach.StateMachine.add('STORE_PCD_02', sm_store_pcd,
00140 transitions = {'succeeded': 'GO_TO_POSE_03',
00141 'aborted': 'aborted' },
00142 remapping = {'pcl_topic' : 'pcl_topic',
00143 'store_service' : 'store_service',
00144 'pose_st' : 'pose_st_02',
00145 'target_frame' : 'target_frame',
00146 'filename' : 'filename_02'})
00147
00148 smach.StateMachine.add('GO_TO_POSE_03', sm_approching,
00149 transitions={'success': 'STORE_PCD_03',
00150 'no_kinematic_solution': 'aborted',
00151 'aborted': 'aborted' },
00152 remapping = {'pose_st': 'pose_st_03'})
00153
00154 smach.StateMachine.add('STORE_PCD_03', sm_store_pcd,
00155 transitions = {'succeeded': 'GO_TO_POSE_04',
00156 'aborted': 'aborted' },
00157 remapping = {'pcl_topic' : 'pcl_topic',
00158 'store_service' : 'store_service',
00159 'pose_st' : 'pose_st_03',
00160 'target_frame' : 'target_frame',
00161 'filename' : 'filename_03'})
00162
00163 smach.StateMachine.add('GO_TO_POSE_04', sm_approching,
00164 transitions={'success': 'STORE_PCD_04',
00165 'no_kinematic_solution': 'aborted',
00166 'aborted': 'aborted' },
00167 remapping = {'pose_st': 'pose_st_04'})
00168
00169 smach.StateMachine.add('STORE_PCD_04', sm_store_pcd,
00170 transitions = {'succeeded': 'GO_TO_POSE_05',
00171 'aborted': 'aborted' },
00172 remapping = {'pcl_topic' : 'pcl_topic',
00173 'store_service' : 'store_service',
00174 'pose_st' : 'pose_st_04',
00175 'target_frame' : 'target_frame',
00176 'filename' : 'filename_04'})
00177
00178 smach.StateMachine.add('GO_TO_POSE_05', sm_approching,
00179 transitions={'success': 'STORE_PCD_05',
00180 'no_kinematic_solution': 'aborted',
00181 'aborted': 'aborted' },
00182 remapping = {'pose_st': 'pose_st_05'})
00183
00184 smach.StateMachine.add('STORE_PCD_05', sm_store_pcd,
00185 transitions = {'succeeded': 'GO_TO_POSE_06',
00186 'aborted': 'aborted' },
00187 remapping = {'pcl_topic' : 'pcl_topic',
00188 'store_service' : 'store_service',
00189 'pose_st' : 'pose_st_05',
00190 'target_frame' : 'target_frame',
00191 'filename' : 'filename_05'})
00192
00193 smach.StateMachine.add('GO_TO_POSE_06', sm_approching,
00194 transitions={'success': 'STORE_PCD_06',
00195 'no_kinematic_solution': 'aborted',
00196 'aborted': 'aborted' },
00197 remapping = {'pose_st': 'pose_st_06'})
00198
00199 smach.StateMachine.add('STORE_PCD_06', sm_store_pcd,
00200 transitions = {'succeeded': 'GO_TO_POSE_07',
00201 'aborted': 'aborted' },
00202 remapping = {'pcl_topic' : 'pcl_topic',
00203 'store_service' : 'store_service',
00204 'pose_st' : 'pose_st_06',
00205 'target_frame' : 'target_frame',
00206 'filename' : 'filename_06'})
00207
00208 smach.StateMachine.add('GO_TO_POSE_07', sm_approching,
00209 transitions={'success': 'STORE_PCD_07',
00210 'no_kinematic_solution': 'aborted',
00211 'aborted': 'aborted' },
00212 remapping = {'pose_st': 'pose_st_07'})
00213
00214 smach.StateMachine.add('STORE_PCD_07', sm_store_pcd,
00215 transitions = {'succeeded': 'succeeded',
00216 'aborted': 'aborted' },
00217 remapping = {'pcl_topic' : 'pcl_topic',
00218 'store_service' : 'store_service',
00219 'pose_st' : 'pose_st_07',
00220 'target_frame' : 'target_frame',
00221 'filename' : 'filename_07'})
00222
00223 return sm
00224
00225 def construct_main_sm():
00226 sm_factory = SM_ZYONZ_CapturePoint()
00227 sm_capture = sm_factory.build_sm()
00228
00229 sm = smach.StateMachine(outcomes = ['succeeded','aborted'])
00230
00231 sm.userdata.pcl_topic = '/zyonz/outlier_removal/output'
00232 sm.userdata.store_service = '/zyonz/pointcloud_to_pcd/store_pointcloud'
00233
00234 sm.userdata.pose_st_00 = PoseStamped();
00235 sm.userdata.pose_st_00.header.frame_id = '/wam_link0';
00236 sm.userdata.pose_st_00.pose.position.x = 0.778;
00237 sm.userdata.pose_st_00.pose.position.y = -0.165;
00238 sm.userdata.pose_st_00.pose.position.z = 0.350;
00239 sm.userdata.pose_st_00.pose.orientation.x = 0.822;
00240 sm.userdata.pose_st_00.pose.orientation.y = -0.532;
00241 sm.userdata.pose_st_00.pose.orientation.z = 0.114;
00242 sm.userdata.pose_st_00.pose.orientation.w = -0.171;
00243 sm.userdata.pose_st_01 = PoseStamped();
00244 sm.userdata.pose_st_01.header.frame_id = '/wam_link0';
00245 sm.userdata.pose_st_01.pose.position.x = 0.742;
00246 sm.userdata.pose_st_01.pose.position.y = -0.224;
00247 sm.userdata.pose_st_01.pose.position.z = 0.329;
00248 sm.userdata.pose_st_01.pose.orientation.x = 0.818;
00249 sm.userdata.pose_st_01.pose.orientation.y = -0.538;
00250 sm.userdata.pose_st_01.pose.orientation.z = 0.097;
00251 sm.userdata.pose_st_01.pose.orientation.w = -0.176;
00252 sm.userdata.pose_st_02 = PoseStamped();
00253 sm.userdata.pose_st_02.header.frame_id = '/wam_link0';
00254 sm.userdata.pose_st_02.pose.position.x = 0.686;
00255 sm.userdata.pose_st_02.pose.position.y = -0.267;
00256 sm.userdata.pose_st_02.pose.position.z = 0.297;
00257 sm.userdata.pose_st_02.pose.orientation.x = 0.832;
00258 sm.userdata.pose_st_02.pose.orientation.y = -0.500;
00259 sm.userdata.pose_st_02.pose.orientation.z = 0.073;
00260 sm.userdata.pose_st_02.pose.orientation.w = -0.229;
00261 sm.userdata.pose_st_03 = PoseStamped();
00262 sm.userdata.pose_st_03.header.frame_id = '/wam_link0';
00263 sm.userdata.pose_st_03.pose.position.x = 0.610;
00264 sm.userdata.pose_st_03.pose.position.y = -0.241;
00265 sm.userdata.pose_st_03.pose.position.z = 0.259;
00266 sm.userdata.pose_st_03.pose.orientation.x = 0.837;
00267 sm.userdata.pose_st_03.pose.orientation.y = -0.471;
00268 sm.userdata.pose_st_03.pose.orientation.z = 0.141;
00269 sm.userdata.pose_st_03.pose.orientation.w = -0.242;
00270 sm.userdata.pose_st_04 = PoseStamped();
00271 sm.userdata.pose_st_04.header.frame_id = '/wam_link0';
00272 sm.userdata.pose_st_04.pose.position.x = 0.556;
00273 sm.userdata.pose_st_04.pose.position.y = -0.221;
00274 sm.userdata.pose_st_04.pose.position.z = 0.209;
00275 sm.userdata.pose_st_04.pose.orientation.x = 0.813;
00276 sm.userdata.pose_st_04.pose.orientation.y = -0.478;
00277 sm.userdata.pose_st_04.pose.orientation.z = 0.186;
00278 sm.userdata.pose_st_04.pose.orientation.w = -0.273;
00279 sm.userdata.pose_st_05 = PoseStamped();
00280 sm.userdata.pose_st_05.header.frame_id = '/wam_link0';
00281 sm.userdata.pose_st_05.pose.position.x = 0.478;
00282 sm.userdata.pose_st_05.pose.position.y = -0.215;
00283 sm.userdata.pose_st_05.pose.position.z = 0.143;
00284 sm.userdata.pose_st_05.pose.orientation.x = 0.768;
00285 sm.userdata.pose_st_05.pose.orientation.y = -0.516;
00286 sm.userdata.pose_st_05.pose.orientation.z = 0.211;
00287 sm.userdata.pose_st_05.pose.orientation.w = -0.317;
00288 sm.userdata.pose_st_06 = PoseStamped();
00289 sm.userdata.pose_st_06.header.frame_id = '/wam_link0';
00290 sm.userdata.pose_st_06.pose.position.x = 0.416;
00291 sm.userdata.pose_st_06.pose.position.y = -0.236;
00292 sm.userdata.pose_st_06.pose.position.z = 0.084;
00293 sm.userdata.pose_st_06.pose.orientation.x = 0.746;
00294 sm.userdata.pose_st_06.pose.orientation.y = -0.475;
00295 sm.userdata.pose_st_06.pose.orientation.z = 0.278;
00296 sm.userdata.pose_st_06.pose.orientation.w = -0.375;
00297 sm.userdata.pose_st_07 = PoseStamped();
00298 sm.userdata.pose_st_07.header.frame_id = '/wam_link0';
00299 sm.userdata.pose_st_07.pose.position.x = 0.407;
00300 sm.userdata.pose_st_07.pose.position.y = -0.273;
00301 sm.userdata.pose_st_07.pose.position.z = 0.025;
00302 sm.userdata.pose_st_07.pose.orientation.x = 0.675;
00303 sm.userdata.pose_st_07.pose.orientation.y = -0.481;
00304 sm.userdata.pose_st_07.pose.orientation.z = 0.361;
00305 sm.userdata.pose_st_07.pose.orientation.w = -0.427;
00306 sm.userdata.filename_00 = '/tmp/plant00.pcd'
00307 sm.userdata.filename_01 = '/tmp/plant01.pcd'
00308 sm.userdata.filename_02 = '/tmp/plant02.pcd'
00309 sm.userdata.filename_03 = '/tmp/plant03.pcd'
00310 sm.userdata.filename_04 = '/tmp/plant04.pcd'
00311 sm.userdata.filename_05 = '/tmp/plant05.pcd'
00312 sm.userdata.filename_06 = '/tmp/plant06.pcd'
00313 sm.userdata.filename_07 = '/tmp/plant07.pcd'
00314 sm.userdata.target_frame = '/wam_link0'
00315
00316 with sm:
00317 smach.StateMachine.add('CAPTURE_APP', sm_capture)
00318 return sm
00319
00320 def main():
00321 rospy.init_node("base_probing_sm")
00322 sm_main = construct_main_sm()
00323
00324
00325 sis = smach_ros.IntrospectionServer('zyonz_capture_sequential_pointcloud', sm_main,
00326 '/zyonz_capture_sequential_pointcloud')
00327
00328 sis.start()
00329
00330 outcome = sm_main.execute()
00331
00332 rospy.spin()
00333 sis.stop()
00334
00335 if __name__ == "__main__":
00336 main()
00337