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('cob_3d_mapping_pipeline')
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 simple_script_server import *
00070 sss = simple_script_server()
00071
00072
00073
00074
00075 class UpdateEnvMap(smach.State):
00076
00077
00078 def __init__(self):
00079
00080 smach.State.__init__(
00081 self,
00082 outcomes=['succeeded', 'failed'],
00083 input_keys=['angle_range'])
00084 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00085
00086 def execute(self, userdata):
00087
00088
00089
00090
00091
00092 rospy.wait_for_service('point_map/clear_map',10)
00093 try:
00094 clear_point_map = rospy.ServiceProxy('point_map/clear_map', Trigger)
00095 resp1 = clear_point_map()
00096 except rospy.ServiceException, e:
00097 print "Service call failed: %s"%e
00098 rospy.wait_for_service('geometry_map/clear_map',10)
00099 try:
00100 clear_geom_map = rospy.ServiceProxy('geometry_map/clear_map', Trigger)
00101 resp1 = clear_geom_map()
00102 except rospy.ServiceException, e:
00103 print "Service call failed: %s"%e
00104 goal = TriggerGoal()
00105 goal.start = True
00106 if not self.client.wait_for_server():
00107 rospy.logerr('server not available')
00108 return 'failed'
00109 self.client.send_goal(goal)
00110 if not self.client.wait_for_result():
00111 return 'failed'
00112 angle_start = -userdata.angle_range/2
00113 angle_stop = userdata.angle_range/2
00114 sss.move("torso",[[-0.2,angle_start,-0.1]])
00115 sss.move("torso",[[-0.2,angle_stop,-0.1]])
00116 sss.move("torso",[[0,angle_stop,0]])
00117 sss.move("torso",[[0,angle_start,0]])
00118 goal.start = False
00119 self.client.send_goal(goal)
00120 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00121 sss.move("torso","home")
00122
00123
00124
00125 return 'succeeded'
00126
00127 """experimental state, should be replaces by generic state for approach pose"""
00128 class ApproachScanPose(smach.State):
00129
00130 def __init__(self):
00131
00132 smach.State.__init__(
00133 self,
00134 outcomes=['succeeded', 'failed'],
00135 input_keys=['scan_pose'])
00136
00137 def execute(self, userdata):
00138 scan_pose = userdata.scan_pose
00139 sss.move("torso","home")
00140 sss.move("head","front")
00141
00142 sss.move("base",scan_pose)
00143
00144 return 'succeeded'
00145
00146 class Map360(smach.State):
00147
00148 def __init__(self):
00149
00150 smach.State.__init__(
00151 self,
00152 outcomes=['succeeded', 'failed'],
00153 input_keys=['angle_range'])
00154 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00155
00156 def execute(self, userdata):
00157 scan_pose = [0, -0.5, 0]
00158 sss.move("base",scan_pose)
00159 sss.move("torso","home")
00160 sss.move("head","front")
00161 sss.move("tray","down")
00162
00163 goal = TriggerGoal()
00164 goal.start = True
00165 if not self.client.wait_for_server():
00166 rospy.logerr('server not available')
00167 return 'failed'
00168 self.client.send_goal(goal)
00169 if not self.client.wait_for_result():
00170 return 'failed'
00171 i = 0.8
00172 ctr = 0
00173 while i <= 8:
00174 scan_pose[2]=i
00175 sss.move("base",scan_pose)
00176
00177 i = i+0.8
00178 ctr = ctr+1
00179 sss.move("torso",[[-0.2,0.0,-0.2]])
00180 while i > 0:
00181 i = i-0.8
00182 scan_pose[2]=i
00183 sss.move("base",scan_pose)
00184 goal.start = False
00185 self.client.send_goal(goal)
00186 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00187
00188
00189
00190
00191 return 'succeeded'
00192
00193
00194 class Map180(smach.State):
00195
00196 def __init__(self):
00197
00198 smach.State.__init__(
00199 self,
00200 outcomes=['succeeded', 'failed'],
00201 input_keys=['angle_range'])
00202 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00203
00204 def execute(self, userdata):
00205 scan_pose = [0, -1, 0]
00206 sss.move("tray","down")
00207 sss.move("torso","home")
00208 sss.move("head","front")
00209 sss.move("base",scan_pose)
00210
00211 raw_input("Press any key")
00212 goal = TriggerGoal()
00213 goal.start = True
00214 if not self.client.wait_for_server():
00215 rospy.logerr('server not available')
00216 return 'failed'
00217 self.client.send_goal(goal)
00218 if not self.client.wait_for_result():
00219 return 'failed'
00220 i = 0.2
00221 ctr = 0
00222 while i <= 4:
00223 scan_pose[2]=i
00224 sss.move("base",scan_pose)
00225
00226
00227
00228
00229
00230 i = i+0.8
00231
00232 sss.move("torso",[[-0.2,0.0,-0.2]])
00233 while i > 0:
00234 i = i-0.8
00235 scan_pose[2]=i
00236 sss.move("base",scan_pose)
00237 goal.start = False
00238 self.client.send_goal(goal)
00239 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00240
00241
00242
00243
00244 return 'succeeded'
00245
00246 class Map90(smach.State):
00247
00248 def __init__(self):
00249
00250 smach.State.__init__(
00251 self,
00252 outcomes=['succeeded', 'failed'],
00253 input_keys=['angle_range'])
00254 self.client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00255
00256 def execute(self, userdata):
00257 scan_pose = [0.515, -1, 1.583]
00258 sss.move("tray","down")
00259 sss.move("torso","home")
00260 sss.move("head","front")
00261 sss.move("base",scan_pose)
00262
00263 goal = TriggerGoal()
00264 goal.start = True
00265 if not self.client.wait_for_server():
00266 rospy.logerr('server not available')
00267 return 'failed'
00268 self.client.send_goal(goal)
00269 if not self.client.wait_for_result():
00270 return 'failed'
00271 i = 1.8
00272 ctr = 0
00273 while ctr <= 2:
00274 scan_pose[2]=i
00275 sss.move("base",scan_pose)
00276
00277
00278
00279
00280
00281 i = i+0.8
00282 ctr = ctr+1
00283 sss.move("torso",[[-0.2,0.0,-0.2]])
00284 while ctr > 0:
00285 i = i-0.9
00286 ctr = ctr-1
00287 scan_pose[2]=i
00288 sss.move("base",scan_pose)
00289 goal.start = False
00290 self.client.send_goal(goal)
00291 self.client.wait_for_result(rospy.Duration.from_sec(5.0))
00292
00293
00294
00295
00296 return 'succeeded'
00297
00298
00299