Merge branch 'hexuesong' of https://bdgit.educoder.net/pbyhqr72x/exercise_2 into hexuesong
commit
c1158a039b
@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
@ -1,6 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tello)" project-jdk-type="Python SDK" />
|
|
||||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/tello.iml" filepath="$PROJECT_DIR$/.idea/tello.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@ -1,18 +0,0 @@
|
|||||||
import pygame
|
|
||||||
|
|
||||||
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__':
|
|
||||||
init()
|
|
Binary file not shown.
@ -1,81 +0,0 @@
|
|||||||
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]
|
|
||||||
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)
|
|
Loading…
Reference in new issue