TranslatePomdp3piles.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 pprint import pprint
00009 from iri_common_smach.utils_msg import build_pose_stamped_msg, build_transform_msg
00010 from estirabot_msgs.msg         import PomdpGraspConfig
00011 from estirabot_apps_base.utils_pomdp            import PomdpConfigFactory 
00012 
00013 class TranslatePomdp(smach.State):
00014     def __init__(self):
00015         smach.State.__init__(self, outcomes    = ['fail','image_from_left','image_from_right','drop'],
00016                                    input_keys  = ['pomdp_action','place_handler'],
00017                                    output_keys = ['sm_pomdp_config','place_handler'])
00018 
00019     def get_config_from_pomdp_action(self, pomdp_action):
00020         """
00021         Translate a pomdp_action number into a PomdpConfig object
00022         """
00023     
00024         if (pomdp_action > 22):
00025             rospy.logfatal("Pomdp action id out of range: " + str(pomdp_action))
00026     
00027         server = PomdpConfigFactory()
00028     
00029         if   (pomdp_action == 0 or pomdp_action == 10): #grabb
00030             magic_number = 1 
00031         elif (pomdp_action == 1 or pomdp_action == 11): #grabb
00032             magic_number = 3
00033         elif (pomdp_action == 2 or pomdp_action == 12): #grabb
00034             magic_number = 5
00035         elif (pomdp_action == 3 or pomdp_action == 13): #grabb
00036             magic_number = 11
00037         elif (pomdp_action == 4 or pomdp_action == 14): #grabb
00038             magic_number = 14
00039         elif (pomdp_action == 5 or pomdp_action == 15): #grabb
00040             magic_number = 101
00041         elif (pomdp_action == 6 or pomdp_action == 16): #grabb
00042             magic_number = 103
00043         elif (pomdp_action == 7 or pomdp_action == 17): #grabb
00044             magic_number = 105
00045         elif (pomdp_action == 8 or pomdp_action == 18): #grabb
00046             magic_number = 111
00047         elif (pomdp_action == 9 or pomdp_action == 19): #grabb
00048             magic_number = 114
00049         elif (pomdp_action == 20): #dropb
00050             magic_number = 114
00051         elif (pomdp_action == 21): #dropa
00052             magic_number = 114
00053         elif (pomdp_action == 22): #dropout
00054             magic_number = 114
00055 
00056         # From magic number get configuration
00057         config = server.get_instance(magic_number)
00058     
00059         if (pomdp_action >= 0 and pomdp_action <= 19):
00060             config.actiontype = config.GRAB
00061         elif (pomdp_action == 20 or pomdp_action == 21 or pomdp_action == 22):
00062             config.actiontype = config.DROP
00063         else:
00064             rospy.logfatal("Pomdp action id out of range: " + str(pomdp_action))
00065             
00066         # Also set the grabbing zone
00067         if (pomdp_action >= 0 and pomdp_action <= 9):
00068             config.grabbing_zone = config.RIGHT_ZONE
00069         elif (pomdp_action >= 10 and pomdp_action <= 19):
00070             config.grabbing_zone = config.LEFT_ZONE
00071         elif (pomdp_action == 20):
00072             config.grabbing_zone = config.RIGHT_ZONE
00073         elif (pomdp_action == 21):
00074             config.grabbing_zone = config.LEFT_ZONE
00075         else:
00076             #drop action does not have a grasping zone
00077             pass 
00078     
00079         # dropout should get an special value for place.
00080         # Hack for this is set place_point to None and check for it
00081         # in PlaceHandler. Dirty as hell.
00082         if (pomdp_action == 22):
00083             config.place_point = None
00084     
00085         return config
00086 
00087     def execute(self, userdata):
00088         # Stupid trick to not declare sm_pomdp_config as input (SMACH goodies)
00089         config                    = self.get_config_from_pomdp_action(userdata.pomdp_action)
00090         config.place_point        = userdata.place_handler.calculate_place_pose(config)
00091 
00092         userdata.sm_pomdp_config = config
00093 
00094         pub_config = rospy.Publisher('/debug/pomdp_config', PomdpGraspConfig, None, False, True)
00095         pub_config.publish(config)
00096         pprint(config)
00097 
00098         if (config.actiontype == config.DROP):
00099             return 'drop'
00100 
00101         if (config.grabbing_zone == config.LEFT_ZONE):
00102             return 'image_from_left'
00103         else:
00104             return 'image_from_right'
00105 


estirabot_apps
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 23:20:59