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 import roslib; roslib.load_manifest('ui_responder')
00038 import rospy
00039
00040 from std_msgs.msg import Empty
00041
00042 from PyQt4 import QtGui, QtCore
00043
00044 import sys
00045
00046 class UIResponder(QtGui.QMessageBox):
00047 preempted = QtCore.pyqtSignal()
00048 def __init__(self):
00049 QtGui.QMessageBox.__init__(self)
00050 self.timeout_seconds = rospy.get_param('~timeout', 60)
00051 self.name = rospy.get_param('~name', 'task')
00052 self.details = rospy.get_param('~details', 'Make sure it is safe to let the robot do something else.')
00053
00054 self.pub = rospy.Publisher(rospy.remap_name('action_ns') + '/preempt_response', Empty)
00055 self.sub = rospy.Subscriber(rospy.remap_name('action_ns') + '/preempt_request', Empty, self.req_cb)
00056 self.preempted.connect(self.handle_preempt)
00057 self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
00058 self.end_now_button = self.addButton("Safe to end " + self.name, QtGui.QMessageBox.YesRole)
00059 self.defer_button = self.addButton("Remind me later", QtGui.QMessageBox.NoRole)
00060 self.setWindowTitle("Robot Task Preempt Request")
00061 self.setText("Another application or user needs to take control of the robot.")
00062 self.setInformativeText(self.details)
00063 self.setDefaultButton(self.defer_button)
00064 self.setIcon(self.Critical)
00065 self.defer_timer = QtCore.QTimer()
00066 self.defer_timer.timeout.connect(self.recenter)
00067 self.defer_timer.start( 1000 * self.timeout_seconds )
00068
00069 def recenter(self):
00070 self.adjustSize()
00071 self.move(QtGui.QApplication.desktop().screen().rect().center() - self.rect().center())
00072
00073 def handle_preempt(self):
00074 try:
00075 rospy.loginfo("Displaying ui_responder popup")
00076 self.exec_()
00077 while self.clickedButton() == self.defer_button:
00078 print "defer!"
00079 self.defer_timer.start( 1000 * self.timeout_seconds )
00080 self.move(0,0)
00081 self.exec_()
00082
00083 except:
00084 pass
00085
00086 rospy.loginfo("Exiting ui_responder")
00087
00088 rospy.signal_shutdown('quit')
00089 QtGui.qApp.quit()
00090 sys.exit()
00091
00092 def req_cb(self, msg):
00093 self.preempted.emit()
00094
00095 def main():
00096 rospy.init_node('ui_responder', None, False, 2, False, False, True)
00097 app = QtGui.QApplication(rospy.myargv(sys.argv))
00098 ui_r = UIResponder()
00099
00100
00101
00102
00103 while True:
00104 app.exec_()
00105
00106 if __name__ == '__main__':
00107 main()