Go to the documentation of this file.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
00059
00060 import time
00061
00062 import roslib
00063 roslib.load_manifest('cob_3d_mapping_demonstrator')
00064 import rospy
00065 import actionlib
00066
00067 from cob_script_server.msg import *
00068 from simple_script_server import *
00069 from cob_srvs.srv import *
00070 from cob_3d_mapping_msgs.msg import *
00071
00072 sss = simple_script_server()
00073
00074
00075
00076
00077
00078 class execute_button_commands():
00079
00080
00081 def __init__(self):
00082 self.ns_global_prefix = "/cob_3d_mapping_demonstrator"
00083 self.script_action_server = actionlib.SimpleActionServer("cob_3d_mapping_demonstrator", ScriptAction, self.execute_cb, False)
00084 self.script_action_server.register_preempt_callback(self.execute_stop)
00085 self.script_action_server.start()
00086 self.trigger_client = actionlib.SimpleActionClient('trigger_mapping', TriggerAction)
00087 self.step = 0.1
00088
00089
00090
00091
00092
00093
00094 def execute_cb(self, server_goal):
00095 print "execute_cb"
00096 server_result = ScriptActionResult().result
00097 if server_goal.function_name == "start":
00098 print "start"
00099 ret=self.execute_start()
00100
00101
00102 elif server_goal.function_name == "reset":
00103 ret=self.execute_reset()
00104 elif server_goal.function_name == "clear":
00105 ret=self.execute_clear()
00106 elif server_goal.function_name == "step":
00107 ret=self.execute_step()
00108 elif server_goal.function_name == "recover":
00109 ret=self.execute_recover()
00110 else:
00111 rospy.logerr("function <<%s>> not supported", server_goal.function_name)
00112 self.script_action_server.set_aborted(server_result)
00113 return
00114
00115
00116
00117
00118 if self.script_action_server.is_active():
00119 self.script_action_server.set_succeeded(server_result)
00120
00121
00122
00123
00124
00125
00126 def execute_start(self):
00127 print "start"
00128
00129
00130
00131
00132
00133
00134 print self.script_action_server.is_preempt_requested()
00135 while not self.script_action_server.is_preempt_requested():
00136 print "move"
00137 sss.move("cob_3d_mapping_demonstrator",[[0.5,0],[-0.5,0],[-0.5,-0.5],[0.5,-0.5],[0.5,0],[0,0]])
00138 sss.sleep(1.0)
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 def execute_start_map(self):
00168 print "start"
00169 goal = TriggerGoal()
00170 if not self.trigger_client.wait_for_server(rospy.Duration.from_sec(2.0)):
00171 print "switched to /segmentation/trigger"
00172 self.trigger_client = actionlib.SimpleActionClient('/segmentation/trigger', TriggerAction)
00173
00174 if not self.trigger_client.wait_for_server(rospy.Duration.from_sec(2.0)):
00175 rospy.logerr('server not available')
00176
00177 else:
00178 goal.start = True
00179 self.trigger_client.send_goal(goal)
00180 if not self.trigger_client.wait_for_result(rospy.Duration.from_sec(2.0)):
00181 print "no result"
00182
00183 sss.move("cob_3d_mapping_demonstrator",[[-0.5,0]])
00184 if self.script_action_server.is_preempt_requested():
00185 self.script_action_server.set_preempted()
00186 return False
00187 sss.move("cob_3d_mapping_demonstrator","home")
00188 if self.script_action_server.is_preempt_requested():
00189 self.script_action_server.set_preempted()
00190 sss.stop("cob_3d_mapping_demonstrator")
00191 return False
00192 sss.move("cob_3d_mapping_demonstrator",[[0.5,0]])
00193 sss.sleep(0.5)
00194 if self.script_action_server.is_preempt_requested():
00195 self.script_action_server.set_preempted()
00196 sss.stop("cob_3d_mapping_demonstrator")
00197 return False
00198 sss.move("cob_3d_mapping_demonstrator",[[0.5,-0.5]])
00199 if self.script_action_server.is_preempt_requested():
00200 self.script_action_server.set_preempted()
00201 sss.stop("cob_3d_mapping_demonstrator")
00202 return False
00203 sss.move("cob_3d_mapping_demonstrator",[[0,-0.5]])
00204 if self.script_action_server.is_preempt_requested():
00205 self.script_action_server.set_preempted()
00206 sss.stop("cob_3d_mapping_demonstrator")
00207 return False
00208 sss.move("cob_3d_mapping_demonstrator",[[-0.5,-0.5]])
00209 if self.script_action_server.is_preempt_requested():
00210 self.script_action_server.set_preempted()
00211 sss.stop("cob_3d_mapping_demonstrator")
00212 return False
00213 sss.move("cob_3d_mapping_demonstrator","home")
00214 goal.start = False
00215 self.trigger_client.send_goal(goal)
00216 if not self.trigger_client.wait_for_result(rospy.Duration.from_sec(2.0)):
00217 return False
00218 return True
00219
00220
00221 def execute_stop(self):
00222 print "stop"
00223 self.script_action_server.set_preempted()
00224 sss.stop("cob_3d_mapping_demonstrator")
00225 return True
00226
00227 def execute_reset(self):
00228 print "reset"
00229 self.execute_stop()
00230 goal = TriggerGoal()
00231 goal.start = False
00232 self.trigger_client.send_goal(goal)
00233 if not self.trigger_client.wait_for_result(rospy.Duration.from_sec(2.0)):
00234 print "mapping not running"
00235 return False
00236
00237
00238
00239 return True
00240
00241
00242
00243 def execute_clear(self):
00244 print "clear"
00245 try:
00246
00247 clear = rospy.ServiceProxy('point_map/clear_map', Trigger)
00248 resp = clear()
00249 except rospy.ServiceException, e:
00250 print "Service call failed: %s"%e
00251 try:
00252
00253 clear = rospy.ServiceProxy('geometry_map/clear_map', Trigger)
00254 resp = clear()
00255 except rospy.ServiceException, e:
00256 print "Service call failed: %s"%e
00257 try:
00258
00259 clear = rospy.ServiceProxy('registration/reset', Trigger)
00260 resp = clear()
00261 except rospy.ServiceException, e:
00262 print "Service call failed: %s"%e
00263 return True
00264
00265 def execute_recover(self):
00266 goal = TriggerGoal()
00267 if not self.trigger_client.wait_for_server(rospy.Duration.from_sec(2.0)):
00268 print "switched to /segmentation/trigger"
00269 self.trigger_client = actionlib.SimpleActionClient('/segmentation/trigger', TriggerAction)
00270
00271 if not self.trigger_client.wait_for_server(rospy.Duration.from_sec(2.0)):
00272 rospy.logerr('server not available')
00273
00274 else:
00275 goal.start = True
00276 self.trigger_client.send_goal(goal)
00277 if not self.trigger_client.wait_for_result(rospy.Duration.from_sec(2.0)):
00278 print "no result"
00279
00280
00281 return True
00282
00283 def execute_step(self):
00284 sss.move("cob_3d_mapping_demonstrator",[[0, -0.5]])
00285 """if self.step==0.1:
00286 self.execute_clear()
00287 print "step"
00288 goal = TriggerGoal()
00289 if not self.trigger_client.wait_for_server(rospy.Duration.from_sec(2.0)):
00290 rospy.logerr('server not available')
00291 #return False
00292 else:
00293 goal.start = True
00294 self.trigger_client.send_goal(goal)
00295 if not self.trigger_client.wait_for_result(rospy.Duration.from_sec(2.0)):
00296 print "no result"
00297 sss.move("cob_3d_mapping_demonstrator",[[self.step,-0.3]])
00298 self.step += 0.1"""
00299
00300
00301
00302 if __name__ == '__main__':
00303 rospy.init_node('execute_button_commands')
00304 execute_button_commands()
00305 rospy.loginfo("execute button commands is running")
00306 rospy.spin()