life_frame.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # License: BSD
4 # https://raw.github.com/yujinrobot/kobuki_desktop/master/kobuki_qtestsuite/LICENSE
5 #
6 ##############################################################################
7 # Imports
8 ##############################################################################
9 
10 import os
11 import numpy
12 import operator
13 #import python_qt_binding.QtCore
14 from python_qt_binding.QtCore import QObject, Signal, Slot, pyqtSlot, QTimer
15 try: # indigo
16  from python_qt_binding.QtGui import QFrame, QVBoxLayout
17 except ImportError: # kinetic+ (pyqt5)
18  from python_qt_binding.QtWidgets import QFrame, QVBoxLayout
19 import math
20 
21 import rospy
22 from qt_gui_py_common.worker_thread import WorkerThread
23 from kobuki_testsuite import Rotate
24 
25 # Local resource imports
26 import detail.common_rc
27 import detail.text_rc
28 from detail.life_frame_ui import Ui_life_frame
29 
30 ##############################################################################
31 # Classes
32 ##############################################################################
33 
34 class LifeFrame(QFrame):
35  STATE_STOPPED = "stopped"
36  STATE_RUN = "running"
37  STATE_IDLE = "idle"
38 
39  def __init__(self, parent=None):
40  super(LifeFrame, self).__init__(parent)
41  self._ui = Ui_life_frame()
42  self._motion = Rotate('/mobile_base/commands/velocity')
43  self._motion_thread = None
44  self._timer = QTimer()
45  #self._timer.setInterval(60000) #60s
46  self._timer.setInterval(250) #60s
47  self._timer.timeout.connect(self.update_progress_callback)
48  self._state = LifeFrame.STATE_STOPPED
49  self._is_alive = False # Used to indicate whether the frame is alive or not (see hibernate/restore methods)
50 
51  def setupUi(self):
52  self._ui.setupUi(self)
53  self._ui.start_button.setEnabled(True)
54  self._ui.stop_button.setEnabled(False)
55  self._motion.init(self._ui.angular_speed_spinbox.value())
56 
57  def shutdown(self):
58  '''
59  Used to terminate the plugin
60  '''
61  rospy.loginfo("Kobuki TestSuite: life frame shutdown")
62  self._motion.shutdown()
63 
64  ##########################################################################
65  # Widget Management
66  ##########################################################################
67 
68  def hibernate(self):
69  '''
70  This gets called when the frame goes out of focus (tab switch).
71  Disable everything to avoid running N tabs in parallel when in
72  reality we are only running one.
73  '''
74  pass
75 
76  def restore(self):
77  '''
78  Restore the frame after a hibernate.
79  '''
80  pass
81 
82 
83  ##########################################################################
84  # Motion Callbacks
85  ##########################################################################
86 
87  def start(self):
88  self._state = LifeFrame.STATE_RUN
89  self._ui.run_progress.reset()
90  self._ui.idle_progress.reset()
91  self._motion_thread = WorkerThread(self._motion.execute, None)
92  self._motion_thread.start()
93 
94  def stop(self):
95  self._state = LifeFrame.STATE_STOPPED
96  self._motion.stop()
97  if self._motion_thread:
98  self._motion_thread.wait()
99 
100  ##########################################################################
101  # Qt Callbacks
102  ##########################################################################
103  @Slot()
105  self._ui.start_button.setEnabled(False)
106  self._ui.stop_button.setEnabled(True)
107  self._timer.start()
108  self.start()
109 
110  @Slot()
112  self.stop()
113  self._timer.stop()
114  self._ui.start_button.setEnabled(True)
115  self._ui.stop_button.setEnabled(False)
116 
117  @pyqtSlot(float)
119  self._motion.init(self._ui.angular_speed_spinbox.value())
120 
121  ##########################################################################
122  # Timer Callbacks
123  ##########################################################################
124 
125  @Slot()
127  if self._state == LifeFrame.STATE_RUN:
128  new_value = self._ui.run_progress.value()+1
129  if new_value == self._ui.run_progress.maximum():
130  print(" Switching to idle")
131  self._motion.stop()
132  self._state = LifeFrame.STATE_IDLE
133  else:
134  self._ui.run_progress.setValue(new_value)
135  if self._state == LifeFrame.STATE_IDLE:
136  new_value = self._ui.idle_progress.value()+1
137  if new_value == self._ui.idle_progress.maximum():
138  print(" Switching to run")
139  self.start()
140  else:
141  self._ui.idle_progress.setValue(new_value)
142 
143 
144 #
def hibernate(self)
Widget Management.
Definition: life_frame.py:68
def start(self)
Motion Callbacks.
Definition: life_frame.py:87
def update_progress_callback(self)
Timer Callbacks.
Definition: life_frame.py:126
def __init__(self, parent=None)
Definition: life_frame.py:39
def on_angular_speed_spinbox_valueChanged(self, value)
Definition: life_frame.py:118
def on_start_button_clicked(self)
Qt Callbacks.
Definition: life_frame.py:104


kobuki_qtestsuite
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:53:02