servoing_interface.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import sys
00004 from PyQt4 import QtCore, QtGui, uic
00005 
00006 import roslib
00007 roslib.load_manifest("std_msgs")
00008 roslib.load_manifest("rospy")
00009 roslib.load_manifest("smach_ros")
00010 
00011 import rospy
00012 from std_msgs.msg import Bool
00013 from smach_msgs.msg import SmachContainerStatus
00014 
00015 from servoing_ui import Ui_Frame as QTServoingFrame
00016 
00017 disabled_button_ss = """QPushButton { font: 75 18pt;
00018                                       background-color: rgb(190, 190, 190);}"""
00019 
00020 STATUS_DICT = { "UI_FIND_TAG_WAIT" : "Navigate the robot so it can see\nthe AR tag.",
00021                 "FIND_AR_TAG" : "Locating tag...",
00022                 "UI_SERVO_WAIT" : "Confirm the robot has found the\ntag in rviz.",
00023                 "SERVOING" : "Servoing to tag..."}
00024 
00025 class ServoingFrame(QtGui.QFrame):
00026     def __init__(self):
00027         super(ServoingFrame, self).__init__()
00028         self.init_ui()
00029 
00030         rospy.Subscriber("/pr2_servo/smach/container_status", SmachContainerStatus, 
00031                          self.smach_status_cb)
00032         self.cur_smach_state = None
00033 
00034         self.find_tag_pub = rospy.Publisher("/pr2_ar_servo/find_tag", Bool)
00035         self.tag_confirm_pub = rospy.Publisher("/pr2_ar_servo/tag_confirm", Bool)
00036         self.preempt_pub = rospy.Publisher("/pr2_ar_servo/preempt", Bool)
00037 
00038     def smach_status_cb(self, msg):
00039         for state in msg.active_states:
00040             if state == self.cur_smach_state:
00041                 continue
00042             if state in STATUS_DICT:
00043                 self.ui.state_information.setText(STATUS_DICT[state])
00044                 self.cur_smach_state = state
00045             if state == "UI_FIND_TAG_WAIT" or state == "FIND_AR_TAG":
00046                 self.enable_button(self.ui.find_ar_tag, self.find_ar_tag_ss)
00047                 self.disable_button(self.ui.begin_servoing)
00048             if state == "UI_SERVO_WAIT":
00049                 self.enable_button(self.ui.begin_servoing, self.begin_servoing_ss)
00050                 self.disable_button(self.ui.find_ar_tag)
00051             if state == "SERVOING":
00052                 self.disable_button(self.ui.find_ar_tag)
00053                 self.disable_button(self.ui.begin_servoing)
00054                 
00055     def enable_button(self, button, ss):
00056         button.setStyleSheet(ss)
00057         button.setEnabled(True)
00058                 
00059     def disable_button(self, button):
00060         button.setStyleSheet(disabled_button_ss)
00061         button.setDisabled(True)
00062 
00063     def init_ui(self):
00064         self.ui = QTServoingFrame()
00065         self.ui.setupUi(self)
00066         self.ui.stop_moving.clicked.connect(self.stop_moving_clk)
00067         self.ui.find_ar_tag.clicked.connect(self.find_ar_tag_clk)
00068         self.ui.begin_servoing.clicked.connect(self.begin_servoing_clk)
00069         self.ui.state_information.setText("State Information")
00070         self.stop_moving_ss = self.ui.stop_moving.styleSheet()
00071         self.find_ar_tag_ss = self.ui.find_ar_tag.styleSheet()
00072         self.begin_servoing_ss = self.ui.begin_servoing.styleSheet()
00073 
00074     def stop_moving_clk(self):
00075         self.preempt_pub.publish(Bool(True))
00076 
00077     def find_ar_tag_clk(self):
00078         self.find_tag_pub.publish(Bool(True))
00079 
00080     def begin_servoing_clk(self):
00081         self.tag_confirm_pub.publish(Bool(True))
00082 
00083 def main():
00084     rospy.init_node("servoing_interface")
00085     app = QtGui.QApplication(sys.argv)
00086     sframe = ServoingFrame()
00087     sframe.show()
00088     sys.exit(app.exec_())
00089 
00090 if __name__ == "__main__":
00091     main()


kelsey_sandbox
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:52:04