diff --git a/src/Tello/KeyPress.py b/src/Tello/KeyPress.py index 66e9f94..4a4499d 100644 --- a/src/Tello/KeyPress.py +++ b/src/Tello/KeyPress.py @@ -1,19 +1,18 @@ -# @Time : 2022/5/9 20:49 -# @Author : 2890199310@qq.com -# @File : KeyPress.py -# @Software: PyCharm -# @Function: +import pygame -def main(): - keyPress() - -def keyPress(key): - if(key == 1): - return "e" - -def result(): - return keyPress() +def init(): + pygame.init() + win = pygame.display.set_mode((400, 400)) +def getKey(keyName): + ans = False + for eve in pygame.event.get(): pass + keyInput = pygame.key.get_pressed() + myKey = getattr(pygame,'K_{}'.format(keyName)) + if keyInput[myKey]: + ans = True + pygame.display.update() + return ans if __name__ == '__main__': - main() \ No newline at end of file + init() \ No newline at end of file diff --git a/src/Tello/KeyPressModule.py b/src/Tello/KeyPressModule.py index bd7182a..4a4499d 100644 --- a/src/Tello/KeyPressModule.py +++ b/src/Tello/KeyPressModule.py @@ -1,31 +1,18 @@ -# @Time : 2022/4/20 12:27 -# @Author : 2890199310@qq.com -# @File : KeyPressModule.py.py -# @Software: PyCharm -# @Function: -import os -import sys -sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../PaddleClas-release-2.3") - -# import pygame -import Tello.KeyPress as k +import pygame def init(): - return + pygame.init() + win = pygame.display.set_mode((400, 400)) def getKey(keyName): - # ans = False - # for eve in pygame.event.get(): pass - # keyInput = pygame.key.get_pressed() - # myKey = getattr(pygame,'K_{}'.format(keyName)) - # if keyInput[myKey]: - if keyName == k.result(): + ans = False + for eve in pygame.event.get(): pass + keyInput = pygame.key.get_pressed() + myKey = getattr(pygame,'K_{}'.format(keyName)) + if keyInput[myKey]: ans = True - # pygame.display.update() + pygame.display.update() return ans -def key(a): - return a - if __name__ == '__main__': init() \ No newline at end of file diff --git a/src/Tello/KeyboardControl.py b/src/Tello/KeyboardControl.py index 6997c9f..5831e92 100644 --- a/src/Tello/KeyboardControl.py +++ b/src/Tello/KeyboardControl.py @@ -1,8 +1,8 @@ -# @Time : 2022/4/20 12:27 -# @Author : 2890199310@qq.com -# @File : KeyboardControl.py.py -# @Software: PyCharm -# @Function: +# # @Time : 2022/4/20 12:27 +# # @Author : 2890199310@qq.com +# # @File : KeyboardControl.py.py +# # @Software: PyCharm +# # @Function: import os import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../PaddleClas-release-2.3") @@ -13,16 +13,45 @@ from djitellopy import tello # import Tello.KeyPressModule as kp # 用于获取键盘按键 from time import sleep -# Tello初始化设置 -Drone = tello.Tello() # 创建飞行器对象 -Drone.connect() # 连接到飞行器 -Drone.streamon() # 开启视频传输 -Drone.LOGGER.setLevel(logging.ERROR) # 只显示错误信息 -sleep(5) # 等待视频初始化 -# kp.init() # 初始化按键处理模块 + +Camera_Width = 720 +Camera_Height = 480 +DetectRange = [6000, 11000] # DetectRange[0] 是保持静止的检测人脸面积阈值下限,DetectRange[0] 是保持静止的检测人脸面积阈值上限 +PID_Parameter = [0.5, 0.0004, 0.4] +pErrorRotate, pErrorUp = 0, 0 + +# 字体设置 +font = cv2.FONT_HERSHEY_SIMPLEX +fontScale = 0.5 +fontColor = (255, 0, 0) +lineThickness = 1 + +def connect(): + # Tello初始化设置 + # 创建飞行器对象 + # kp.init() # 初始化按键处理模块 + global Drone + Drone = tello.Tello() + Drone.connect() # 连接到飞行器 + Drone.streamon() # 开启视频传输 + Drone.LOGGER.setLevel(logging.ERROR) # 只显示错误信息 + sleep(5) # 等待视频初始化 + flag = True + while flag: + global OriginalImage + OriginalImage = Drone.get_frame_read().frame + global image + image = cv2.resize(OriginalImage, (Camera_Width, Camera_Height)) + # getKeyboardInput(drone=Drone, speed=70, image=Image) # 按键控制 + cv2.imshow("Drone Control Centre", image) + cv2.waitKey(1) + if cv2.waitKey(1) == ord('q'): + flag = False + cv2.destroyAllWindows() + def getKeyboardInput(key): - image = cv2.resize(OriginalImage, (Camera_Width, Camera_Height)) + # image = cv2.resize(OriginalImage, (Camera_Width, Camera_Height)) speed = 70 drone = Drone lr, fb, ud, yv = 0, 0, 0, 0 @@ -36,7 +65,6 @@ def getKeyboardInput(key): # elif kp.getKey("DOWN"):#下降 if key == "DOWN": Drone.land() - # if kp.getKey("j"):# 向左飞行 if key == "j": key_pressed = 1 @@ -45,11 +73,14 @@ def getKeyboardInput(key): if key == "l": key_pressed = 1 lr = speed - # if kp.getKey("i"): #向前飞行 if key == "i": key_pressed = 1 fb = speed + # stop + if key == "s": + key_pressed = 1 + fb = 0 # elif kp.getKey("k"):# 向后飞行 if key == "k": key_pressed = 1 @@ -80,26 +111,92 @@ def getKeyboardInput(key): drone.send_rc_control(lr, fb, ud, yv) -# 主程序 -# 摄像头设置 -Camera_Width = 720 -Camera_Height = 480 -DetectRange = [6000, 11000] # DetectRange[0] 是保持静止的检测人脸面积阈值下限,DetectRange[0] 是保持静止的检测人脸面积阈值上限 -PID_Parameter = [0.5, 0.0004, 0.4] -pErrorRotate, pErrorUp = 0, 0 -# 字体设置 -font = cv2.FONT_HERSHEY_SIMPLEX -fontScale = 0.5 -fontColor = (255, 0, 0) -lineThickness = 1 - - - - -while True: - OriginalImage = Drone.get_frame_read().frame - Image = cv2.resize(OriginalImage, (Camera_Width, Camera_Height)) - # getKeyboardInput(drone=Drone, speed=70, image=Image) # 按键控制 - cv2.imshow("Drone Control Centre", Image) - cv2.waitKey(1) \ No newline at end of file +# connect() +# # 主程序 +# # 摄像头设置 +# +# +# +# +# import logging +# import time +# import cv2 +# from djitellopy import tello +# import KeyPressModule as kp # 用于获取键盘按键 +# from time import sleep +# +# def getKeyboardInput(drone, speed, image): +# lr, fb, ud, yv = 0, 0, 0, 0 +# key_pressed = 0 +# if kp.getKey("e"): +# cv2.imwrite('D:/snap-{}.jpg'.format(time.strftime("%H%M%S", time.localtime())), image) +# if kp.getKey("UP"): +# Drone.takeoff() +# elif kp.getKey("DOWN"): +# Drone.land() +# +# if kp.getKey("j"): +# key_pressed = 1 +# lr = -speed +# elif kp.getKey("l"): +# key_pressed = 1 +# lr = speed +# +# if kp.getKey("i"): +# key_pressed = 1 +# fb = speed +# elif kp.getKey("k"): +# key_pressed = 1 +# fb = -speed +# +# if kp.getKey("w"): +# key_pressed = 1 +# ud = speed +# elif kp.getKey("s"): +# key_pressed = 1 +# ud = -speed +# +# if kp.getKey("a"): +# key_pressed = 1 +# yv = -speed +# elif kp.getKey("d"): +# key_pressed = 1 +# yv = speed +# InfoText = "battery : {0}% height: {1}cm time: {2}".format(drone.get_battery(), drone.get_height(), time.strftime("%H:%M:%S",time.localtime())) +# cv2.putText(image, InfoText, (10, 20), font, fontScale, (0, 0, 255), lineThickness) +# if key_pressed == 1: +# InfoText = "Command : lr:{0}% fb:{1} ud:{2} yv:{3}".format(lr, fb, ud, yv) +# cv2.putText(image, InfoText, (10, 40), font, fontScale, (0, 0, 255), lineThickness) +# +# drone.send_rc_control(lr, fb, ud, yv) +# +# # 主程序 +# # 摄像头设置 +# Camera_Width = 720 +# Camera_Height = 480 +# DetectRange = [6000, 11000] # DetectRange[0] 是保持静止的检测人脸面积阈值下限,DetectRange[0] 是保持静止的检测人脸面积阈值上限 +# PID_Parameter = [0.5, 0.0004, 0.4] +# pErrorRotate, pErrorUp = 0, 0 +# +# # 字体设置 +# font = cv2.FONT_HERSHEY_SIMPLEX +# fontScale = 0.5 +# fontColor = (255, 0, 0) +# lineThickness = 1 +# +# # Tello初始化设置 +# Drone = tello.Tello() # 创建飞行器对象 +# Drone.connect() # 连接到飞行器 +# Drone.streamon() # 开启视频传输 +# Drone.LOGGER.setLevel(logging.ERROR) # 只显示错误信息 +# sleep(5) # 等待视频初始化 +# kp.init() # 初始化按键处理模块 +# +# +# while True: +# OriginalImage = Drone.get_frame_read().frame +# Image = cv2.resize(OriginalImage, (Camera_Width, Camera_Height)) +# getKeyboardInput(drone=Drone, speed=70, image=Image) # 按键控制 +# cv2.imshow("Drone Control Centre", Image) +# cv2.waitKey(1) \ No newline at end of file diff --git a/src/Tello/__init__.py b/src/Tello/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/Tello/__pycache__/KeyPress.cpython-39.pyc b/src/Tello/__pycache__/KeyPress.cpython-39.pyc index 3608c27..b43d6db 100644 Binary files a/src/Tello/__pycache__/KeyPress.cpython-39.pyc and b/src/Tello/__pycache__/KeyPress.cpython-39.pyc differ diff --git a/src/Tello/__pycache__/KeyPressModule.cpython-39.pyc b/src/Tello/__pycache__/KeyPressModule.cpython-39.pyc index 1114802..be68495 100644 Binary files a/src/Tello/__pycache__/KeyPressModule.cpython-39.pyc and b/src/Tello/__pycache__/KeyPressModule.cpython-39.pyc differ diff --git a/src/Tello/__pycache__/KeyboardControl.cpython-39.pyc b/src/Tello/__pycache__/KeyboardControl.cpython-39.pyc index aad69a2..adc0fbc 100644 Binary files a/src/Tello/__pycache__/KeyboardControl.cpython-39.pyc and b/src/Tello/__pycache__/KeyboardControl.cpython-39.pyc differ diff --git a/src/qt/Mainwindow.py b/src/qt/Mainwindow.py index f560ca1..5e99b9d 100644 --- a/src/qt/Mainwindow.py +++ b/src/qt/Mainwindow.py @@ -14,6 +14,9 @@ from findpath_UI import * from Screenshot.Screenshot_Gui import * import qdarkstyle +sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../PaddleClas-release-2.3") +import Tello.KeyboardControl as KeyControl + class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") @@ -203,6 +206,13 @@ class Ui_MainWindow(object): self.toolBar.addAction(self.actionicon_3) self.actionicon_2.triggered.connect(lambda: self.path()) self.actionicon_3.triggered.connect(lambda: self.video()) + self.pushButton_7.clicked.connect(lambda: self.connect()) + self.pushButton_3.clicked.connect(lambda: self.up()) + self.pushButton_6.clicked.connect(lambda: self.down()) + self.pushButton.clicked.connect(lambda: self.forward()) + self.pushButton_4.clicked.connect(lambda: self.right()) + self.pushButton_2.clicked.connect(lambda: self.left()) + self.pushButton_5.clicked.connect(lambda: self.Return()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) @@ -216,6 +226,29 @@ class Ui_MainWindow(object): self.ui = Ui_MainWindow2() self.ui.show() + def connect(self): + KeyControl.connect() + + def up(self): + KeyControl.getKeyboardInput("UP") + + def down(self): + KeyControl.getKeyboardInput("DOWN") + + def forward(self): + KeyControl.getKeyboardInput("i") + + def right(self): + KeyControl.getKeyboardInput("l") + + def left(self): + KeyControl.getKeyboardInput("j") + + def Return(self): + KeyControl.getKeyboardInput("a") + KeyControl.getKeyboardInput("dffsfdsa") + + def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "无人机路径生成系统")) diff --git a/src/qt/Screenshot/__pycache__/Audio_record.cpython-39.pyc b/src/qt/Screenshot/__pycache__/Audio_record.cpython-39.pyc index 037c86a..a40e9dc 100644 Binary files a/src/qt/Screenshot/__pycache__/Audio_record.cpython-39.pyc and b/src/qt/Screenshot/__pycache__/Audio_record.cpython-39.pyc differ diff --git a/src/qt/Screenshot/__pycache__/Screenshot_Gui.cpython-39.pyc b/src/qt/Screenshot/__pycache__/Screenshot_Gui.cpython-39.pyc index ee5472f..3d094f4 100644 Binary files a/src/qt/Screenshot/__pycache__/Screenshot_Gui.cpython-39.pyc and b/src/qt/Screenshot/__pycache__/Screenshot_Gui.cpython-39.pyc differ diff --git a/src/qt/Screenshot/__pycache__/Screenshot_record.cpython-39.pyc b/src/qt/Screenshot/__pycache__/Screenshot_record.cpython-39.pyc index 64d31c2..8ec9235 100644 Binary files a/src/qt/Screenshot/__pycache__/Screenshot_record.cpython-39.pyc and b/src/qt/Screenshot/__pycache__/Screenshot_record.cpython-39.pyc differ diff --git a/src/qt/__pycache__/findpath_UI.cpython-39.pyc b/src/qt/__pycache__/findpath_UI.cpython-39.pyc index 54f0718..46c924e 100644 Binary files a/src/qt/__pycache__/findpath_UI.cpython-39.pyc and b/src/qt/__pycache__/findpath_UI.cpython-39.pyc differ