from djitellopy import Tello
import keyboard
from time import sleep as sp
import cv2 

drone = Tello()
drone.connect()
drone.streamon()
 
def StatusOutput():
    if keyboard.is_pressed('b'):
        print("Battery:", drone.get_battery())
    elif keyboard.is_pressed('t'):
        print("Temperature:", drone.get_highest_temperature)

def LaunchInput():
    if keyboard.is_pressed('q'):
        drone.takeoff()
        drone.send_rc_control(0, 0, 0, 0)
    elif keyboard.is_pressed('e'):
        drone.send_rc_control(0, 0, 0, 0)
        drone.land()
    elif keyboard.is_pressed('f'):
        drone.flip('left')
    elif keyboard.is_pressed('o'):
        drone.emergency()
    elif keyboard.is_pressed('h'):
        drone.send_rc_control(0, 0, 0, 0)
    elif keyboard.is_pressed('x'):
        drone.disconnect()
    
def ControlsInput():
    lr, fb, ud, yv = 0, 0, 0, 0

    speed = 100

    if keyboard.is_pressed('left'):
        lr = -speed
    elif keyboard.is_pressed('right'):
        lr = speed

    if keyboard.is_pressed('up'):
        fb = speed
    elif keyboard.is_pressed('down'):
        fb = -speed

    if keyboard.is_pressed('w'):
        ud = speed
    elif keyboard.is_pressed('s'):
        ud = -speed

    if keyboard.is_pressed('a'):
        yv = speed
    elif keyboard.is_pressed('d'):
        yv = -speed

    return [lr, fb, ud, yv]


while True:
     
    img = drone.get_frame_read().frame
    img = cv2.resize(img, (800, 400))
    cv2.imshow("Drone", img)
    cv2.waitKey(1)

    StatusOutput()

    LaunchInput()

    value = ControlsInput()
    drone.send_rc_control(value[0], value[1], value[2], value[3])
    

Latest Update: July 21, 2024, 8:21 p.m.
TAGS