sm_deformable_analysis.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('estirabot_apps_base')
00004 import rospy
00005 import smach
00006 import smach_ros
00007 
00008 from sensor_msgs.msg import PointCloud2
00009 from iri_deformable_analysis.srv import DoDeformableAnalysis, DoDeformableAnalysisRequest
00010 from iri_common_smach.st_topic_publisher import TopicPublisher
00011 
00012 class PerformAnalysis(smach.State):
00013     def __init__(self):
00014         smach.State.__init__(self, outcomes=['success','fail','timeout'],
00015                                    input_keys=['pcl_RGB','deformable_config'],
00016                                    output_keys=['best_grasp_pose'])
00017 
00018     def execute(self, userdata):
00019         # Config and launch the deformable analysis
00020         handler = rospy.ServiceProxy(
00021                                 '/estirabot/skills/deformable_analysis/do_deformable_analysis',
00022                                 DoDeformableAnalysis)
00023 
00024         analysis_request                    = DoDeformableAnalysisRequest()
00025         analysis_request.pcl_to_analyze     = userdata.pcl_RGB
00026         analysis_request.fusion_criteria_id = userdata.deformable_config.best_pose_algorithm_id
00027 
00028         try:
00029             response = handler(analysis_request)
00030 
00031             if (not response):
00032                 return 'fail'
00033 
00034         except rospy.ServiceException, e:
00035             return 'timeout'
00036 
00037         pose_st = response.deformable_analysis.graspability.best_grasp_pose
00038         userdata.best_grasp_pose = pose_st
00039 
00040         return 'success'
00041 
00042 class SM_ESTIRABOT_DeformableAnalysis():
00043     """
00044     State machine to perform a deformable analysis
00045 
00046     Currently composed of logging state and service call
00047     """
00048     def __init__(self, pcl_log = True, log_topic = '/log/pcl_table_scene'):
00049        self.sm = smach.StateMachine(outcomes    = ['success','fail','timeout'],
00050                                     input_keys  = ['pcl_RGB','deformable_config'],
00051                                     output_keys = ['best_grasp_pose'])
00052        self.pcl_log   = pcl_log
00053        self.log_topic = log_topic
00054 
00055     def build_sm(self):
00056         with self.sm:
00057             if (self.pcl_log):
00058                 smach.StateMachine.add('LOG_PCL_TO_ANALYSE', 
00059                                        TopicPublisher(self.log_topic, PointCloud2),
00060                         transitions = {'finish' : 'CALL_PERFORM_ANALYSIS'},
00061                         remapping   = {'msg'    : 'pcl_RGB'})
00062 
00063             smach.StateMachine.add('CALL_PERFORM_ANALYSIS', PerformAnalysis(),
00064                     transitions = {'success' : 'success',
00065                                    'fail'    : 'fail',
00066                                    'timeout' : 'timeout'},
00067                     remapping   = {'pcl_RGB' : 'pcl_RGB',
00068                                    'deformable_config' : 'deformable_config',
00069                                    'best_grasp_pose'   : 'best_grasp_pose'})
00070         return self.sm


estirabot_apps_base
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 21:07:07