00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 import roslib
00059 roslib.load_manifest('srs_states')
00060 import rospy
00061 import smach
00062 import smach_ros
00063 import actionlib
00064 import operator
00065
00066 from cob_3d_mapping_msgs.msg import *
00067 from cob_srvs.srv import Trigger
00068
00069 from shared_state_information import *
00070
00071 from simple_script_server import *
00072 sss = simple_script_server()
00073
00074
00075
00076
00077 class UpdateEnvMap(smach.State):
00078
00079 def __init__(self):
00080
00081 smach.State.__init__(
00082 self,
00083 outcomes=['succeeded', 'failed', 'preempted'],
00084 input_keys=['angle_range'])
00085 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerMappingAction)
00086
00087 def execute(self, userdata):
00088
00089
00090
00091
00092
00093 rospy.wait_for_service('registration/reset',10)
00094 try:
00095 reset_registration = rospy.ServiceProxy('registration/reset', Trigger)
00096 resp1 = reset_registration()
00097 except rospy.ServiceException, e:
00098 print "Service call failed: %s"%e
00099 rospy.wait_for_service('point_map/clear_map',10)
00100 try:
00101 clear_point_map = rospy.ServiceProxy('point_map/clear_map', Trigger)
00102 resp1 = clear_point_map()
00103 except rospy.ServiceException, e:
00104 print "Service call failed: %s"%e
00105 rospy.wait_for_service('geometry_map/clear_map',10)
00106 try:
00107 clear_geom_map = rospy.ServiceProxy('geometry_map/clear_map', Trigger)
00108 resp1 = clear_geom_map()
00109 except rospy.ServiceException, e:
00110 print "Service call failed: %s"%e
00111 goal = TriggerMappingGoal()
00112 goal.start = True
00113 if not self.client.wait_for_server():
00114 rospy.logerr('server not available')
00115 return 'failed'
00116 self.client.send_goal(goal)
00117 if not self.client.wait_for_result():
00118 return 'failed'
00119 sss.sleep(5.0)
00120 angle_start = -userdata.angle_range/2
00121 angle_stop = userdata.angle_range/2
00122 sss.move("torso",[[-0.2,angle_start,-0.1]])
00123 sss.move("torso",[[-0.2,angle_stop,-0.1]])
00124 sss.move("torso",[[0,angle_stop,0]])
00125 sss.move("torso",[[0,angle_start,0]])
00126 goal.start = False
00127 self.client.send_goal(goal)
00128 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00129 sss.move("torso","home")
00130
00131
00132
00133 return 'succeeded'
00134
00135 """experimental state, should be replaces by generic state for approach pose"""
00136 class ApproachScanPose(smach.State):
00137
00138 def __init__(self):
00139
00140 smach.State.__init__(
00141 self,
00142 outcomes=['succeeded', 'failed'],
00143 input_keys=['scan_pose'])
00144
00145 def execute(self, userdata):
00146 scan_pose = userdata.scan_pose
00147 sss.move("torso","home")
00148 sss.move("head","front")
00149
00150
00151
00152 return 'succeeded'
00153
00154 class Map360(smach.State):
00155
00156 def __init__(self):
00157
00158 smach.State.__init__(
00159 self,
00160 outcomes=['succeeded', 'failed'],
00161 input_keys=['angle_range'])
00162 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerMappingAction)
00163
00164 def execute(self, userdata):
00165 scan_pose = [0, 0, 0]
00166 sss.move("base",scan_pose)
00167 sss.move("torso","home")
00168 sss.move("head","front")
00169 sss.move("tray","down")
00170
00171 goal = TriggerMappingGoal()
00172 goal.start = True
00173 if not self.client.wait_for_server():
00174 rospy.logerr('server not available')
00175 return 'failed'
00176 self.client.send_goal(goal)
00177 if not self.client.wait_for_result():
00178 return 'failed'
00179 i = 0.2
00180 ctr = 0
00181 while i <= 6.2:
00182 scan_pose[2]=i
00183 sss.move("base",scan_pose)
00184 if operator.mod(ctr,2) == 0:
00185 sss.move("torso",[[-0.2,0.0,-0.2]])
00186 else:
00187 sss.move("torso","home")
00188
00189 i = i+0.2
00190 ctr = ctr+1
00191 goal.start = False
00192 self.client.send_goal(goal)
00193 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00194
00195
00196
00197
00198 return 'succeeded'