00001
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 PomdpConfigFactory():
00013 def __init__(self):
00014 self.config = PomdpGraspConfig()
00015 self.config.place_point = build_pose_stamped_msg('/wam_link0',0.5, 0, 0.33, 0.0, 1.0, 0.0, 0.0)
00016
00017 self.config.grabbing_zone = self.config.BOTH_ZONES
00018
00019 self.config.approach_config.pre_grasp_modifier = build_transform_msg(0, 0, -0.1, 0, 0, 0, 1)
00020 self.config.approach_config.grasp_modifier_used = 0
00021
00022 self.config.fingers_grasp_configs.append("GSTO")
00023
00024 def get_instance(self, magic_number):
00025
00026 if (magic_number > 999) or (magic_number < 0):
00027 rospy.logfatal("Pomdp magic number is out of ranges")
00028
00029 alg_id = magic_number / 100
00030 approach_id = (magic_number - (100 * alg_id)) / 10
00031 grasp_id = (magic_number - (100 * alg_id) - (10 * approach_id))
00032
00033 if (alg_id == 0):
00034 self.config.best_pose_algorithm_id = self.config.MAX_HEIGHT_ALG
00035 elif (alg_id == 1):
00036 self.config.best_pose_algorithm_id = self.config.MAX_WRINKLE_ALG
00037 elif (alg_id == 2):
00038 self.config.best_pose_algorithm_id = self.config.FUSION_ALG
00039 else:
00040 rospy.logfatal("Magic number alg_is it out of range")
00041
00042 if (approach_id == self.config.APPROACH_TOP_DEEP):
00043 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, 0, -0.03, 1, 0, 0, 0))
00044 elif (approach_id == self.config.APPROACH_TOP_SURFACE):
00045 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, 0, 0.05, 1, 0, 0, 0))
00046 elif (approach_id == self.config.APPROACH_SIDE_DEEP):
00047 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0.03, 0, 0, 0, 0.7071, 0, 0.7071))
00048 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, 0.03, 0, -0.5, 0.5, 0.5, 0.5))
00049 self.config.approach_config.grasp_modifiers.append(build_transform_msg(-0.03, 0, 0, -0.7071, 0, 0.7071,0))
00050 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, -0.03, 0, 0.5, 0.5, -0.5, 0.5))
00051 elif (approach_id == self.config.APPROACH_SIDE_SURFACE):
00052 self.config.approach_config.grasp_modifiers.append(build_transform_msg(-0.05, 0, 0, 0, 0.7071, 0, 0.7071))
00053 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, -0.05, 0, -0.5, 0.5, 0.5, 0.5))
00054 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0.05, 0, 0, 0, -0.7071, 0, 0.7071))
00055 self.config.approach_config.grasp_modifiers.append(build_transform_msg(0, 0.05, 0, 0.5, 0.5, -0.5, 0.5))
00056 else:
00057 rospy.logfatal("Magic number approach is out of range")
00058
00059 if (grasp_id == 0):
00060 pass
00061 elif (grasp_id == 1):
00062 self.config.fingers_grasp_configs.append("GM 7000")
00063 self.config.fingers_grasp_configs.append("GTC")
00064 elif (grasp_id == 2):
00065 self.config.fingers_grasp_configs.append("GM 10000")
00066 self.config.fingers_grasp_configs.append("GTC")
00067 elif (grasp_id == 3):
00068 self.config.fingers_grasp_configs.append("SM 500")
00069 self.config.fingers_grasp_configs.append("GTC")
00070 elif (grasp_id == 4):
00071 self.config.fingers_grasp_configs.append("SM 500")
00072 self.config.fingers_grasp_configs.append("GM 7000")
00073 self.config.fingers_grasp_configs.append("GTC")
00074 elif (grasp_id == 5):
00075 self.config.fingers_grasp_configs.append("STC")
00076 self.config.fingers_grasp_configs.append("GTC")
00077 elif (grasp_id == 6):
00078 self.config.fingers_grasp_configs.append("SM 1500")
00079 self.config.fingers_grasp_configs.append("3TC")
00080 self.config.fingers_grasp_configs.append("GTC")
00081
00082 else:
00083 rospy.logfatal("Magic number grasp is out of range")
00084
00085
00086
00087 return self.config
00088
00089 def get_config_from_pomdp_action(pomdp_action):
00090 """
00091 Translate a pomdp_action number into a PomdpConfig object
00092 """
00093
00094 if (pomdp_action > 21):
00095 rospy.logfatal("Pomdp action id out of range: " + str(pomdp_action))
00096
00097 server = PomdpConfigFactory()
00098
00099 if (pomdp_action == 20):
00100 magic_number = 114
00101 elif (pomdp_action == 21):
00102 magic_number = 114
00103 elif (pomdp_action % 10 == 0):
00104 magic_number = 1
00105 elif (pomdp_action % 10 == 1):
00106 magic_number = 3
00107 elif (pomdp_action % 10 == 2):
00108 magic_number = 5
00109 elif (pomdp_action % 10 == 3):
00110 magic_number = 11
00111 elif (pomdp_action % 10 == 4):
00112 magic_number = 14
00113 elif (pomdp_action % 10 == 5):
00114 magic_number = 101
00115 elif (pomdp_action % 10 == 6):
00116 magic_number = 103
00117 elif (pomdp_action % 10 == 7):
00118 magic_number = 105
00119 elif (pomdp_action % 10 == 8):
00120 magic_number = 111
00121 elif (pomdp_action % 10 == 9):
00122 magic_number = 114
00123
00124
00125 config = server.get_instance(magic_number)
00126
00127 config.actiontype = config.GRAB
00128
00129 if (pomdp_action == 20):
00130 config.grabbing_zone = config.RIGHT_ZONE
00131 config.actiontype = config.DROP
00132 elif (pomdp_action == 21):
00133 config.grabbing_zone = config.LEFT_ZONE
00134 config.actiontype = config.DROP
00135 elif (pomdp_action > 9):
00136 config.grabbing_zone = config.LEFT_ZONE
00137 else:
00138 config.grabbing_zone = config.RIGHT_ZONE
00139
00140
00141
00142
00143 if (pomdp_action == 20) or (pomdp_action == 21):
00144 config.place_point = None
00145
00146 return config
00147
00148
00149 class TranslatePomdp(smach.State):
00150 def __init__(self):
00151 pass