Compare commits

...

5 Commits

@ -0,0 +1,18 @@
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()

@ -0,0 +1,87 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import logging
import time
import cv2
from djitellopy import tello
import KeyPressMoudle 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)

@ -0,0 +1,160 @@
# 四则运算行棋 计算器
"""|||mid_to_aft将中缀表达式转化为后缀表达式l;
aft_to_cal有参数l将后缀表达式进行计算
mid_to_cal直接将中缀表达式进行计算|||"""
class Calculator(object): # 用一个类应用于计算
def __init__(self, equ):
self.s = equ
def mid_to_aft(self):
pref = {'+': 1, '-': 1, '*': 2, '/': 2, '^': 3} # 符号字典
l = ''
A = []
i = 0
while True:
loc = self.s[i]
# 可能是一个两位以上的数字
if loc in list('0123456789'):
while i < len(self.s) - 1 and self.s[i + 1] in list('0123456789'): # 不是最后一个数字且为连续数字
loc += self.s[i + 1]
i += 1 # 刚好到连续的最后一个数字
l = l + loc + ' '
elif loc in list('()+-*/^'):
if A == [] or loc == '(':
A.append(loc)
elif loc == ')':
while A[-1] != '(':
l = l + A.pop() + ' '
A.pop()
elif A[-1] == '(':
A.append(loc)
else:
if pref[loc] > pref[A[-1]]:
A.append(loc)
else:
while A[-1] != '(':
l = l + A.pop() + ' '
if A == []:
break
A.append(loc)
i += 1
if i == len(self.s):
while A != []:
if len(A) == 1:
l += A.pop()
else:
l = l + A.pop() + ' '
break
return l
def aft_to_cal(self, l):
A = []
i = 0
while True:
# print('第{}个元素A = '.format(i+1),A)
loc = l[i]
if loc in list('0123456789'):
while l[i + 1] in list('0123456789'): # 此时肯定是数字
loc += l[i + 1]
i = i + 1
A.append(float(loc))
i += 1
elif loc == ' ':
i += 1
continue
else:
if loc == '+':
A.append(A.pop() + A.pop())
elif loc == '-':
A.append(-A.pop() + A.pop())
elif loc == '*':
A.append(A.pop() * A.pop())
elif loc == '/':
A.append((1 / A.pop()) * A.pop())
else:
last = A.pop()
A.append(pow(A.pop(), last))
i += 1
if i >= len(l) - 1:
break
result = A.pop()
return result
def mid_to_cal(self):
pref = {'+': 1, '-': 1, '*': 2, '/': 2, '^': 3}
l = ''
A = []
i = 0
while True:
loc = self.s[i]
# 可能是一个两位以上的数字
if loc in list('0123456789'):
while i < len(self.s) - 1 and self.s[i + 1] in list('0123456789'): # 不是最后一个数字且为连续数字
loc += self.s[i + 1]
i += 1 # 刚好到连续的最后一个数字
l = l + loc + ' '
elif loc in list('()+-*/^'):
if A == [] or loc == '(':
A.append(loc)
elif loc == ')':
while A[-1] != '(':
l = l + A.pop() + ' '
A.pop()
elif A[-1] == '(':
A.append(loc)
else:
if pref[loc] > pref[A[-1]]:
A.append(loc)
else:
while A[-1] != '(':
l = l + A.pop() + ' '
if A == []:
break
A.append(loc)
i += 1
if i == len(self.s):
while A != []:
if len(A) == 1:
l += A.pop()
else:
l = l + A.pop() + ' '
break
i = 0
while True:
loc = l[i]
if loc in list('0123456789'):
while l[i + 1] in list('0123456789'): # 此时肯定是数字
loc += l[i + 1]
i = i + 1
A.append(float(loc))
i += 1
elif loc == ' ':
i += 1
continue
else:
if loc == '+':
A.append(A.pop() + A.pop())
elif loc == '-':
A.append(-A.pop() + A.pop())
elif loc == '*':
A.append(A.pop() * A.pop())
elif loc == '/':
A.append((1 / A.pop()) * A.pop())
else:
last = A.pop()
A.append(pow(A.pop(), last))
i += 1
if i >= len(l) - 1:
break
result = A.pop()
return result
'''def eval(expression):
c = eval(expression)
return c'''
'''中缀转后缀计算器设计结束'''

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save