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


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