Skip to content

Commit

Permalink
Server: Add flip and emergency buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Neroboot committed Jun 10, 2019
1 parent 2de50d3 commit 2516906
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 19 deletions.
64 changes: 64 additions & 0 deletions Server/emergency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
import glob

from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItemModel, QStandardItem
from PyQt5.QtCore import Qt, pyqtSlot
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5 import QtCore, QtGui, QtWidgets
from server import *
from server_qt import *

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(632, 214)
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(470, 110, 121, 61))
self.pushButton_2.setSizeIncrement(QtCore.QSize(16, 16))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(40, 100, 121, 61))
self.pushButton_3.setSizeIncrement(QtCore.QSize(16, 16))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_2.clicked.connect(self.btn_2)
self.pushButton_3.clicked.connect(self.btn_3)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(40, 40, 561, 51))
font = QtGui.QFont()
font.setPointSize(16)
self.label.setFont(font)
self.label.setObjectName("label")

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton_2.setText(_translate("Dialog", "PushButton"))
self.pushButton_3.setText(_translate("Dialog", "PushButton"))
self.label.setText(_translate("Dialog", "\n"
"Select a group in which the drone does not work correctly"))
def btn_2(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("green")
def btn_3(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("red")

if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())

76 changes: 76 additions & 0 deletions Server/emergency.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>632</width>
<height>214</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>470</x>
<y>110</y>
<width>121</width>
<height>61</height>
</rect>
</property>
<property name="sizeIncrement">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>121</width>
<height>61</height>
</rect>
</property>
<property name="sizeIncrement">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>561</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>
Select a group in which the drone does not work correctly</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
20 changes: 12 additions & 8 deletions Server/server_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1239, 741)
MainWindow.resize(1284, 740)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setEnabled(True)
self.centralwidget.setObjectName("centralwidget")
Expand Down Expand Up @@ -54,9 +54,9 @@ def setupUi(self, MainWindow):
self.stop_button = QtWidgets.QPushButton(self.centralwidget)
self.stop_button.setObjectName("stop_button")
self.formLayout.setWidget(5, QtWidgets.QFormLayout.SpanningRole, self.stop_button)
self.test_Button = QtWidgets.QPushButton(self.centralwidget)
self.test_Button.setObjectName("test_Button")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.SpanningRole, self.test_Button)
self.emergency_button = QtWidgets.QPushButton(self.centralwidget)
self.emergency_button.setObjectName("emergency_button")
self.formLayout.setWidget(6, QtWidgets.QFormLayout.SpanningRole, self.emergency_button)
self.verticalLayout.addLayout(self.formLayout)
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
Expand All @@ -71,20 +71,23 @@ def setupUi(self, MainWindow):
self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.takeoff_button)
self.land_button = QtWidgets.QPushButton(self.centralwidget)
self.land_button.setObjectName("land_button")
self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.land_button)
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.land_button)
self.disarm_button = QtWidgets.QPushButton(self.centralwidget)
self.disarm_button.setObjectName("disarm_button")
self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.SpanningRole, self.disarm_button)
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.disarm_button)
self.leds_button = QtWidgets.QPushButton(self.centralwidget)
self.leds_button.setObjectName("leds_button")
self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.leds_button)
self.flip_button = QtWidgets.QPushButton(self.centralwidget)
self.flip_button.setObjectName("flip_button")
self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.SpanningRole, self.flip_button)
self.verticalLayout.addLayout(self.formLayout_2)
self.horizontalLayout.addLayout(self.verticalLayout)
self.horizontalLayout.setStretch(0, 1)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1239, 21))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1284, 21))
self.menubar.setObjectName("menubar")
self.menuOptions = QtWidgets.QMenu(self.menubar)
self.menuOptions.setObjectName("menuOptions")
Expand Down Expand Up @@ -112,11 +115,12 @@ def retranslateUi(self, MainWindow):
self.start_button.setText(_translate("MainWindow", "Start animation"))
self.pause_button.setText(_translate("MainWindow", "Pause"))
self.stop_button.setText(_translate("MainWindow", "Stop"))
self.test_Button.setText(_translate("MainWindow", "Test"))
self.emergency_button.setText(_translate("MainWindow", "Emergency land"))
self.takeoff_button.setText(_translate("MainWindow", "Takeoff"))
self.land_button.setText(_translate("MainWindow", "Land"))
self.disarm_button.setText(_translate("MainWindow", "Disarm"))
self.leds_button.setText(_translate("MainWindow", "Test leds"))
self.flip_button.setText(_translate("MainWindow", "Flip"))
self.menuOptions.setTitle(_translate("MainWindow", "Actions"))
self.action_send_animations.setText(_translate("MainWindow", "Send Animations"))
self.action_send_configurations.setText(_translate("MainWindow", "Send Configurations"))
Expand Down
21 changes: 14 additions & 7 deletions Server/server_gui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1239</width>
<height>741</height>
<width>1284</width>
<height>740</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -92,9 +92,9 @@
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QPushButton" name="test_Button">
<widget class="QPushButton" name="emergency_button">
<property name="text">
<string>Test</string>
<string>Emergency land</string>
</property>
</widget>
</item>
Expand All @@ -119,14 +119,14 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="land_button">
<property name="text">
<string>Land</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="disarm_button">
<property name="text">
<string>Disarm</string>
Expand All @@ -140,6 +140,13 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="flip_button">
<property name="text">
<string>Flip</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand All @@ -153,7 +160,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1239</width>
<width>1284</width>
<height>21</height>
</rect>
</property>
Expand Down
35 changes: 31 additions & 4 deletions Server/server_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from server_gui import Ui_MainWindow

from server import *
from emergency import *


# noinspection PyArgumentList,PyCallByClass
Expand All @@ -28,13 +29,13 @@ def init_ui(self):
self.ui.start_button.clicked.connect(self.send_starttime)
self.ui.pause_button.clicked.connect(self.pause_all)
self.ui.stop_button.clicked.connect(self.stop_all)
self.ui.test_Button.clicked.connect(self.test)
self.ui.emergency_button.clicked.connect(self.emergency)

self.ui.leds_button.clicked.connect(self.test_leds)
self.ui.takeoff_button.clicked.connect(self.takeoff_selected)
self.ui.land_button.clicked.connect(self.land_all)
self.ui.disarm_button.clicked.connect(self.disarm_all)

self.ui.flip_button.clicked.connect(self.flip)
self.ui.action_send_animations.triggered.connect(self.send_animations)
self.ui.action_send_configurations.triggered.connect(self.send_configurations)
self.ui.action_send_Aruco_map.triggered.connect(self.send_aruco)
Expand Down Expand Up @@ -146,6 +147,7 @@ def disarm_all(self):
@pyqtSlot()
def send_animations(self):
path = str(QFileDialog.getExistingDirectory(self, "Select Animation Directory"))

if path:
print("Selected directory:", path)
files = [file for file in glob.glob(path + '/*.csv')]
Expand Down Expand Up @@ -193,13 +195,38 @@ def send_aruco(self):
copter.send_file(path, "/home/pi/catkin_ws/src/clever/aruco_pose/map/animation_map.txt")
copter.send_message("service_restart", {"name": "clever"})
@pyqtSlot()
def test(self):
def emergency(self):
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
copter = Client.get_by_id(item.text())
copter.send_message("test")
copter.send_message("emergency")
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
Dialog.exec_()

@pyqtSlot()
def flip(self):
reply = QMessageBox.question(
self, "Confirm operation",
"You are ready to turn the copter?",
QMessageBox.Yes | QMessageBox.No, QMessageBox.No
)
if reply == QMessageBox.Yes:
print("Accepted")
for row_num in range(model.rowCount()):
item = model.item(row_num, 0)
if item.isCheckable() and item.checkState() == Qt.Checked:
if True: # TODO checks for batt/selfckeck here
copter = Client.get_by_id(item.text())
copter.send_message("flip")
else:
print("Cancelled")
pass



model = QStandardItemModel()
model.setHorizontalHeaderLabels(
Expand Down

0 comments on commit 2516906

Please sign in to comment.