payload_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 from python_qt_binding.QtCore import Signal, Slot, pyqtSlot
14 try: # indigo
15  from python_qt_binding.QtGui import QFrame, QVBoxLayout
16 except ImportError: # kinetic+ (pyqt5)
17  from python_qt_binding.QtWidgets import QFrame, QVBoxLayout
18 import math
19 
20 import rospy
21 from qt_gui_py_common.worker_thread import WorkerThread
22 from kobuki_testsuite import Square
23 
24 # Local resource imports
25 import detail.common_rc
26 import detail.text_rc
27 from detail.payload_frame_ui import Ui_payload_frame
28 
29 ##############################################################################
30 # Classes
31 ##############################################################################
32 
33 class PayloadFrame(QFrame):
34  def __init__(self, parent=None):
35  super(PayloadFrame, self).__init__(parent)
36  self._gyro_topic_name = '/mobile_base/sensors/imu_data'
37  self._ui = Ui_payload_frame()
38  self._motion = None
39  self._motion_thread = None
40 
41  def setupUi(self):
42  self._ui.setupUi(self)
43  self._ui.start_button.setEnabled(True)
44  self._ui.stop_button.setEnabled(False)
45 
46  def shutdown(self):
47  '''
48  Used to terminate the plugin
49  '''
50  rospy.loginfo("Kobuki TestSuite: payload frame shutdown")
51  self._stop()
52 
53  ##########################################################################
54  # Widget Management
55  ##########################################################################
56 
57  def hibernate(self):
58  '''
59  This gets called when the frame goes out of focus (tab switch).
60  Disable everything to avoid running N tabs in parallel when in
61  reality we are only running one.
62  '''
63  self._stop()
64 
65  def restore(self):
66  '''
67  Restore the frame after a hibernate.
68  '''
69  pass
70 
71  ##########################################################################
72  # Motion Callbacks
73  ##########################################################################
74 
75  def _run_finished(self):
76  self._motion_thread = None
77  self._motion = None
78  self._ui.start_button.setEnabled(True)
79  self._ui.stop_button.setEnabled(False)
80 
81  ##########################################################################
82  # Qt Callbacks
83  ##########################################################################
84  @Slot()
86  self._ui.start_button.setEnabled(False)
87  self._ui.stop_button.setEnabled(True)
88  self._motion = Square('/mobile_base/commands/velocity', '/odom', self._gyro_topic_name)
89  self._motion.init(self._ui.speed_spinbox.value(), self._ui.distance_spinbox.value())
90  self._motion_thread = WorkerThread(self._motion.execute, self._run_finished)
91  self._motion_thread.start()
92 
93  @Slot()
95  self._stop()
96 
97  def _stop(self):
98  if self._motion:
99  self._motion.stop()
100  if self._motion_thread:
101  self._motion_thread.wait()
102  self._motion_thread = None
103  if self._motion:
104  self._motion = None
105  self._ui.start_button.setEnabled(True)
106  self._ui.stop_button.setEnabled(False)
107 
108  @pyqtSlot(float)
110  if self._motion:
111  self._motion.init(self._ui.speed_spinbox.value(), self._ui.distance_spinbox.value())
112 
113  @pyqtSlot(float)
115  if self._motion:
116  self._motion.init(self._ui.speed_spinbox.value(), self._ui.distance_spinbox.value())
117 
118  ##########################################################################
119  # Ros Callbacks
120  ##########################################################################
121 
122  #def robot_state_callback(self, data):
123  # if data.state == RobotStateEvent.OFFLINE:
124  # self.stop()
125 
126 #
def _run_finished(self)
Motion Callbacks.
def hibernate(self)
Widget Management.
def on_start_button_clicked(self)
Qt Callbacks.


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