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 import os, sys
00056
00057 import roslib
00058 roslib.load_manifest('srs_states')
00059 import rospy
00060 import smach
00061 import threading
00062 import tf
00063 from std_msgs.msg import String, Bool, Int32
00064 from geometry_msgs.msg import *
00065
00066
00067 """
00068 current_task_info is a global shared memory for exchanging task information among statuses
00069
00070 smach is slow on passing large amount of userdata. Hence they are stored under goal_structure as global variable
00071
00072 srs_dm_action perform one task at a time and maintain a unique session id.
00073 """
00074
00075 listener = tf.TransformListener()
00076
00077 class goal_structure():
00078
00079 def __init__(self):
00080
00081
00082 self.task_name =""
00083
00084
00085 self.task_parameter=""
00086
00087
00088
00089
00090 self.task_feedback=""
00091
00092
00093
00094
00095
00096 self.json_parameters = ''
00097
00098
00099 self.last_step_info = list()
00100
00101
00102 self.preemptied = False
00103
00104
00105 self._srs_as=""
00106
00107
00108
00109 self.pub_fb = rospy.Publisher('fb_executing_solution', Bool)
00110
00111 self.pub_fb2 = rospy.Publisher('fb_executing_state', String)
00112
00113
00114 self.object_in_hand = False
00115
00116 self.object_identified = False
00117
00118
00119 self.post_grasp_adjusted = False
00120
00121
00122
00123 self.object_on_tray = False
00124
00125 self.arm_folded_ready_for_transfer = False
00126
00127 self.lock = threading.Lock()
00128
00129 self.customised_preempt_required = False
00130
00131 self.customised_preempt_acknowledged = False
00132
00133 self.pause_required = False
00134
00135 self.stop_required = False
00136
00137 self.stop_acknowledged = False
00138
00139 self.language_set = ''
00140
00141 try:
00142 self.language_set = rospy.get_param("/srs/language")
00143 except Exception, e:
00144 self.language_set = 'English'
00145
00146
00147
00148 self.speaking_language = dict()
00149 self.feedback_messages = dict()
00150
00151 if self.language_set.lower() == 'italian':
00152 self.speaking_language['Grasp']= "Ora sto afferrare il "
00153 self.speaking_language['Search']= "Ora sto cercando il "
00154 self.speaking_language['Navigation']= "Ora mi sto muovendo"
00155 self.speaking_language['Stop']= "Ora sto fermare l attività corrente "
00156 self.speaking_language['Pause']= "Ora sto pausa l attività corrente"
00157 self.speaking_language['Resume']= "Ora sto riprendendo l'attività corrente"
00158 self.speaking_language['Preempted']= "Ora vengo fermato da un altro task con priorità maggiore"
00159
00160 self.feedback_messages['sm_srs_grasp']= "Greifen Sie das Objekt"
00161 self.feedback_messages['sm_put_object_on_tray']= "Legen Sie das Objekt auf dem Tablett"
00162 self.feedback_messages['sm_enviroment_update']= "Umgebung zu aktualisieren"
00163 self.feedback_messages['sm_srs_detection']= "Auf der Suche nach Objekt"
00164 self.feedback_messages['sm_srs_navigation']= "Umzug nach Ziel"
00165 self.feedback_messages['initialise']='Initialisierung Roboter'
00166
00167 elif self.language_set.lower()== 'german':
00168 self.speaking_language['Grasp']= "Jetzt bin ich Ergreifen der "
00169 self.speaking_language['Search']= "Jetzt suche ich die "
00170 self.speaking_language['Navigation']= "Jetzt bin ich bewegt "
00171 self.speaking_language['Stop']= "Jetzt bin ich Anhalten der aktuellen Aufgabe "
00172 self.speaking_language['Pause']= "Jetzt bin ich Anhalten der aktuellen Aufgabe"
00173 self.speaking_language['Resume']= "Jetzt bin ich die Wiederaufnahme der aktuellen Aufgabe"
00174 self.speaking_language['Preempted']= "Jetzt bin ich von einer anderen Task mit höherer Priorität unterbrochen"
00175
00176 self.feedback_messages['sm_srs_grasp']= "Cogliere l'oggetto"
00177 self.feedback_messages['sm_put_object_on_tray']= "Mettere l'oggetto sul vassoio"
00178 self.feedback_messages['sm_enviroment_update']= "Ambiente aggiornamento"
00179 self.feedback_messages['sm_srs_detection']= "Ricerca di oggetti"
00180 self.feedback_messages['sm_srs_navigation']= "Spostamento di destinazione"
00181 self.feedback_messages['initialise']='inizializzazione robot'
00182
00183 else:
00184
00185 self.speaking_language['Grasp']= "Now I am grasping the "
00186 self.speaking_language['Search']= "Now I am searching the "
00187 self.speaking_language['Navigation']= "Now I am moving "
00188 self.speaking_language['Stop']= "Now I am stopping the current task "
00189 self.speaking_language['Pause']= "Now I am pausing the current task "
00190 self.speaking_language['Resume']= "Now I am resuming the current task "
00191 self.speaking_language['Preempt']= "Now I am stopped by another task with higher priority"
00192
00193 self.feedback_messages['sm_srs_grasp']= "Grasping the object"
00194 self.feedback_messages['sm_put_object_on_tray']= "Put the object on the tray"
00195 self.feedback_messages['sm_enviroment_update']= "Environment update"
00196 self.feedback_messages['sm_srs_detection']= "Searching for object"
00197 self.feedback_messages['sm_srs_navigation']= "Moving to target"
00198 self.feedback_messages['initialise']='initialising robot'
00199
00200
00201
00202 def get_post_grasp_adjustment_state(self):
00203 self.lock.acquire()
00204
00205 value = self.post_grasp_adjusted
00206 self.lock.release()
00207 return value
00208
00209 def set_post_grasp_adjustment_state(self, value):
00210 self.lock.acquire()
00211
00212 self.post_grasp_adjusted = value
00213 self.lock.release()
00214
00215 def get_object_identification_state(self):
00216 self.lock.acquire()
00217 value = self.object_identified
00218 self.lock.release()
00219 return value
00220
00221 def set_object_identification_state(self, value):
00222 self.lock.acquire()
00223 self.object_identified = value
00224 self.lock.release()
00225
00226
00227 def get_pause_required(self):
00228 self.lock.acquire()
00229 value = self.pause_required
00230 self.lock.release()
00231 return value
00232
00233 def get_customised_preempt_required(self):
00234 self.lock.acquire()
00235 value = self.customised_preempt_required
00236 self.lock.release()
00237 return value
00238
00239 def get_customised_preempt_acknowledged(self):
00240 self.lock.acquire()
00241 value = self.customised_preempt_acknowledged
00242 self.lock.release()
00243 return value
00244
00245 def get_stop_required(self):
00246 self.lock.acquire()
00247 value = self.stop_required
00248 self.lock.release()
00249 return value
00250
00251 def get_stop_acknowledged(self):
00252 self.lock.acquire()
00253 value = self.stop_acknowledged
00254 self.lock.release()
00255 return value
00256
00257 def set_pause_required(self,value):
00258 self.lock.acquire()
00259 self.pause_required = value
00260 self.lock.release()
00261
00262 def set_customised_preempt_required(self,value):
00263 self.lock.acquire()
00264 self.customised_preempt_required = value
00265 self.lock.release()
00266
00267
00268 def set_customised_preempt_acknowledged(self, value):
00269 self.lock.acquire()
00270 self.customised_preempt_acknowledged = value
00271 self.lock.release()
00272
00273
00274 def set_stop_required(self, value):
00275 self.lock.acquire()
00276 self.stop_required = value
00277 self.lock.release()
00278
00279 def set_stop_acknowledged(self, value):
00280 self.lock.acquire()
00281 self.acknowledged = value
00282 self.lock.release()
00283
00284
00285
00286 def stopable(self):
00287
00288 self.lock.acquire()
00289
00290
00291 if self.object_in_hand and not self.arm_folded_ready_for_transfer:
00292 outcome = False
00293 else:
00294 outcome = True
00295 self.lock.release()
00296
00297 return outcome
00298
00299
00300 def reset(self):
00301
00302 self.__init__()
00303 gc.collect()
00304
00305 def get_robot_pos(self):
00306 try:
00307
00308 (trans,rot) = listener.lookupTransform("/map", "/base_link", rospy.Time(0))
00309 except rospy.ROSException, e:
00310 print "Transformation not possible: %s"%e
00311 return None
00312
00313 rb_pose = Pose2D()
00314 rb_pose.x = trans[0]
00315 rb_pose.y = trans[1]
00316 rb_pose_rpy = tf.transformations.euler_from_quaternion(rot)
00317 rb_pose.theta = rb_pose_rpy[2]
00318
00319 return rb_pose
00320
00321
00322
00323 current_task_info = goal_structure()