emergency_stop.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ################################################################################
3 #
4 # Copyright Airbus Group SAS 2015
5 # All rigths reserved.
6 #
7 # File Name : emergency_stop.py
8 # Authors : Martin Matignon
9 #
10 # If you find any bug or if you have any question please contact
11 # Adolfo Suarez Roos <adolfo.suarez@airbus.com>
12 # Martin Matignon <martin.matignon.external@airbus.com>
13 #
14 #
15 ################################################################################
16 ## @package: emergency_stop
17 ##
18 ## @version 1.0
19 ## @author Matignon Martin
20 ## @date Last modified 24/09/2014
21 import rospy
22 import os
23 import sys
24 import threading
25 from roslib.packages import get_pkg_dir
26 
27 from python_qt_binding.QtGui import *
28 from python_qt_binding.QtCore import *
29 from python_qt_binding import loadUi
30 
31 from airbus_cobot_gui import resources_dir, trUtf8
32 from airbus_cobot_gui.python_qt_extend import MessageBox_v2
33 
34 from std_msgs.msg import Bool
35 
36 ## @class EmergencyStopState
38  LOCKED = True
39  UNLOCKED = False
40 
41 ## @class EmergencyStopButton
42 class EmergencyStopButton(QPushButton):
43 
44  EMERGENCY_STOP_TOPIC_NAME = '/emergency_stop/state'
45  EVENT_NAME = 'emergencyStopStatusChanged'
46 
47  def __init__(self):
48  """! The constructor."""
49  QPushButton.__init__(self)
50 
51  self.setCheckable(True)
52  self.setFocusPolicy(Qt.NoFocus)
53  self.setStyleSheet("background-color: transparent;")
54 
55  self.ICON_PLAY = QIcon(resources_dir('icons/icon_play.png'))
56  self.ICON_PAUSE = QIcon(resources_dir('icons/icon_pause.png'))
57 
58  self.setIcon(self.ICON_PAUSE)
59 
60  self._button_state = EmergencyStopState.UNLOCKED
61  self._keep_running = True
62 
63  self.connect(self,SIGNAL('clicked(bool)'),self._trigger_button)
64  self._estop_pub = rospy.Publisher(self.EMERGENCY_STOP_TOPIC_NAME,
65  Bool, latch=True, queue_size=1)
66 
67  self._estop_pub_thread = threading.Thread(name='emergency_stop_publisher_loop',
69  self._estop_pub_thread.start()
70 
71  def _trigger_button(self, checked):
72  """Called when user click on ermergency stop button.
73  @param checked: Button status (True/False).
74  @type checked: bool.
75  """
76  self._button_state = checked
77 
78  self.emit(SIGNAL(self.EVENT_NAME),self._button_state)
79 
80  if checked == EmergencyStopState.LOCKED:
81  self.setIcon(self.ICON_PLAY)
82 
83  msg_box = MessageBox_v2(QMessageBox.Warning,
84  trUtf8("System paused",'!'))
85  msg_box.setStandardButtons(QMessageBox.Ok)
86  msg_box.button(QMessageBox.Ok).setMinimumSize(100,40)
87  msg_box.setMinimumSize(800,600)
88  msg_box.exec_()
89  else:
90  self.setIcon(self.ICON_PAUSE)
91 
93  """Loop to publish the emergency stop status."""
94 
95  r = rospy.Rate(10) # 10hz
96 
97  while not rospy.is_shutdown() and self._keep_running:
98 
99  if self._button_state == EmergencyStopState.UNLOCKED:
100  self._estop_pub.publish(Bool(True))
101  else:
102  self._estop_pub.publish(Bool(False))
103 
104  r.sleep()
105 
106  def shutdown(self):
107  """Called when appli closes."""
108  self._keep_running = False
109 
110 
111 ##Unittest
112 if __name__ == "__main__":
113 
114  rospy.init_node('unittest_emergency_stop_2')
115 
116  a = QApplication(sys.argv)
117  utt_appli = QMainWindow()
119  estop.setIconSize(QSize(80,80))
120  utt_appli.setCentralWidget(estop)
121  utt_appli.show()
122  a.exec_()
123  estop.shutdown()
124 
125 
126 #End of file


airbus_cobot_gui
Author(s):
autogenerated on Thu Dec 17 2015 11:42:05