control_mode.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 
00019 import rospy
00020 import os
00021 import sys
00022 from roslib.packages import get_pkg_dir
00023 
00024 from python_qt_binding.QtGui import *
00025 from python_qt_binding.QtCore import *
00026 from python_qt_binding import loadUi
00027 
00028 from airbus_pyqt_extend.QtAgiGui import QAgiSilderButton
00029 from airbus_cobot_gui.alarm import Alarm
00030 from airbus_cobot_gui.emergency import EmergencyStopState
00031 from airbus_cobot_gui.res import R
00032 ## @class ControlMode
00033 ## @brief Class for difine different control mode.
00034 class ControlMode:
00035     
00036     AUTOMATIC = 1
00037     MANUAL    = 2
00038     
00039     TOSTR = {AUTOMATIC : 'Automatic',
00040              MANUAL    : 'Manual'}
00041     
00042     TOLEVEL = {'Automatic' : AUTOMATIC,
00043                'auto'      : AUTOMATIC,
00044                'Manual'    : MANUAL,
00045                'manu'      : MANUAL}
00046 
00047 class ControlModeWidget(QWidget):
00048     
00049     def __init__(self, context):
00050         """! The constructor."""
00051         QWidget.__init__(self)
00052         
00053         self._context = context
00054         self._context.addLanguageEventListner(self.onTranslate)
00055         self._context.addAlarmEventListner(self.onAlarm)
00056         self._context.addEmergencyStopEventListner(self.onEmergencyStop)
00057         self._context.addCloseEventListner(self.onDestroy)
00058         
00059         self.setFixedSize(QSize(140,40))
00060         
00061         lng = self._context.getLanguage()
00062         
00063         self._slider_button = QAgiSilderButton(self,
00064                                             initial_state=True,
00065                                             on_label=R.values.strings.manu(lng),
00066                                             off_label=R.values.strings.auto(lng))
00067         self._slider_button.setFixedSize(QSize(140,40))
00068         self.connect(self._slider_button,
00069                      SIGNAL("statusChanged"),
00070                      self._switch_mode)
00071     
00072     def setDefaultMode(self, mode):
00073         
00074         if mode is ControlMode.AUTOMATIC:
00075             self._slider_button.setState(False)
00076         else:
00077             self._slider_button.setState(True)
00078             
00079         self._context.requestNewControlMode(mode)
00080         
00081     setControlMode = setDefaultMode
00082     
00083     def _switch_mode(self, status):
00084         
00085         if status == False:
00086             self._context.requestNewControlMode(self._context.AUTOMATIC)
00087         else:
00088             self._context.requestNewControlMode(ControlMode.MANUAL)
00089             
00090     def onTranslate(self, lng):
00091         self._slider_button.setOnText(R.values.strings.manu(lng))
00092         self._slider_button.setOffText(R.values.strings.auto(lng))
00093         
00094     def onAlarm(self, alarm):
00095         
00096         if alarm.level() >= Alarm.CRITICAL:
00097             if self._context.getControlMode() != ControlMode.MANUAL:
00098                 self.setControlMode(ControlMode.MANUAL)
00099                 self._context.sendAlarm(Alarm.WARNING,
00100                                         "Control mode switching automatic to manual mode !")
00101         
00102     def onEmergencyStop(self, emer):
00103         
00104         if emer == EmergencyStopState.LOCKED:
00105             if self._context.getControlMode() != ControlMode.MANUAL:
00106                 self.setControlMode(ControlMode.MANUAL)
00107         
00108     def onDestroy(self):
00109         pass
00110         
00111 if __name__ == "__main__":
00112     
00113     from airbus_cobot_gui.context import Context
00114     
00115     rospy.init_node('unittest_countrol_mode_ui')
00116     
00117     a = QApplication(sys.argv)
00118     
00119     utt_appli = QMainWindow()
00120     
00121     utt_appli.setCentralWidget(ControlModeWidget(Context(utt_appli)))
00122     
00123     utt_appli.show()
00124     a.exec_()
00125     
00126 #End of file


airbus_cobot_gui
Author(s): Martin Matignon
autogenerated on Thu Jun 6 2019 17:59:19