def challenge5(): me = tello.Tello() me.connect() print(me.get_battery()) me.takeoff() sleep(1) me.flip_back() sleep(1) me.flip_forward() sleep(1) me.flip_left() sleep(1) me.flip_right() sleep(1) me.land()
def __init__(self): pygame.init() # init pygame window win = pygame.display.set_mode( (400, 400)) # set pygame window dimensions self.drone = tello.Tello() # Call tello bib self.drone.connect() # Connect to drone time.sleep(2) self.drone.streamon() # Get camera feed from drone battery = self.drone.get_battery() # Get battery status from.drone print("Battery is at {}%".format(battery)) df = { "Key": [ "SPACE", "Q", "R", "UP", "DOWN", "LEFT", "RIGHT", "W", "A", "S", "D" ], "Function": [ "Take off", "Land drone", "Take a screenshot", "Go Up", "Go Down", "Rotate Left", "Rotate Right", "Go forward", "Go left", "Go backward", "Go right" ] } df = pd.DataFrame(df) print(tabulate(df, headers="keys", tablefmt="psql", showindex=False)) # Show controls in a nice table self.start = time.time() # Get current time
def main(): drone = tello.Tello() initializedrone(drone) arucoparameters, aruco_dict = loadarucoparam() objdicts = loadarucoimages("Objects") w, h = 540, 360 abrange = [75, 80] pid_yap = [0.4, 0.9, 0.45, 0.9, 0.7, 0.8, 0, 0, 0] p_error, i_t = [0, 0, 0], [0, 0, 0] # pTime, cTime = 0, 0 while True: frame = drone.get_frame_read().frame frame = cv2.resize(frame, (w, h), interpolation=cv2.INTER_AREA) alista, alistc, info = [], [], [[0, 0], 0] arucofound = findarucofeatures(frame, arucoparameters, aruco_dict) if len(arucofound[0]) != 0: for corners, ids in zip(arucofound[0], arucofound[1]): if int(ids) in objdicts.keys(): frame, info[0], info[1] = findaruco(corners, frame, alistc, alista) p_error, i_t = arucotrack(drone, info, w, h, i_t, pid_yap, p_error, abrange) # cTime = time.time() # fps = 1 / (cTime - pTime) # pTime = cTime # cv2.putText(frame, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3) cv2.imshow('Display', frame) if cv2.waitKey(1) & 0xff == 27: drone.land() break
def main(trackface=False, trackaruco=False): drone = tello.Tello() initializeDrone(drone) arucoparameters, aruco_dict=loadarucoparam() objdicts = loadarucoimages("Objects") w, h = 360, 240 fbRange = [6200, 6800] abRange = [60, 65] pid = [0.5, 0.9, 0, 0.7, 0.8, 0, 0.8, 0.8, 0] pError = [0, 0, 0] while True: frame = drone.get_frame_read().frame frame = cv2.resize(frame, (w, h), interpolation=cv2.INTER_AREA) if trackface: frame, info = FindFace(frame) pError = FaceTrack(drone, info, w,h, pid, pError, fbRange) if trackaruco: AListA, AListC, info = [], [], [[0, 0], 0] arucofound = findarucofeatures(frame, arucoparameters, aruco_dict) if len(arucofound[0]) != 0: for corners, id in zip(arucofound[0], arucofound[1]): if int(id) in objdicts.keys(): frame, info[0], info[1] = findaruco(corners, id, frame, objdicts[int(id)], AListC, AListA) pError = FaceTrack(drone, info, w,h, pid, pError, abRange) cv2.imshow('Display', frame) print("Center", info[0], "Area", info[1]) if cv2.waitKey(1) & 0xff == 27: drone.land() break
def __init__(self) -> None: self.CONST = Constants() self.drone = tello.Tello() self.up_down_velocity = 0 self.right_left_velocity = 0 self.forward_backward_velocity = 0 self.turn_velocity = 0
def initializeTello(): myDrone = tello.Tello() myDrone.connect() myDrone.for_back_velocity = 0 myDrone.left_right_velocity = 0 myDrone.up_down_velocity = 0 myDrone.yaw_velocity = 0 myDrone.speed = 0 print(myDrone.get_battery()) myDrone.streamoff() myDrone.streamon() return myDrone
def initializedrone(): drone = tello.Tello() drone.connect() drone.land() time.sleep(2) print(drone.get_battery()) drone.streamon() drone.takeoff() time.sleep(2) drone.send_rc_control(0, 0, 20, 0) time.sleep(2.2) return drone
def challenge3(): me = tello.Tello() me.connect() print(me.get_battery()) me.takeoff() sleep(2) me.flip() sleep(2) me.land()
def challenge2(): me = tello.Tello() me.connect() print(me.get_battery()) me.takeoff() sleep(2) me.send_rc_control(0, 0, 0, 50) sleep(2) me.land()
def __init__(self): # Init necessary variables self.w, self.h = 360, 240 self.fbRange = [5200, 6500] self.area_O = 6000 self.pid = [0.4, 0.4, 0] self.p_error = 0 self.p_error2 = 0 self.p_error3 = 0 pygame.init() # init pygame window win = pygame.display.set_mode( (400, 400)) # set pygame window dimensions self.drone = tello.Tello() # Call tello bib self.drone.connect() # Connect to drone time.sleep(2) self.drone.streamon() # Get camera feed from drone battery = self.drone.get_battery() # Get battery status from drone print("Battery is at {}%".format(battery))
def colorpicker(): frameWidth = 480 frameHeight = 360 me = tello.Tello() me.connect() print(me.get_battery()) me.streamon() cv2.namedWindow("HSV") cv2.resizeWindow("HSV", 640, 240) cv2.createTrackbar("HUE Min", "HSV", 0, 179, empty) cv2.createTrackbar("HUE Max", "HSV", 179, 179, empty) cv2.createTrackbar("SAT Min", "HSV", 0, 255, empty) cv2.createTrackbar("SAT Max", "HSV", 255, 255, empty) cv2.createTrackbar("VALUE Min", "HSV", 0, 255, empty) cv2.createTrackbar("VALUE Max", "HSV", 255, 255, empty) #cap = cv2.VideoCapture(1) frameCounter = 0 while True: img = me.get_frame_read().frame #_, img = cap.read() img = cv2.resize(img, (frameWidth, frameHeight)) imgHsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) h_min = cv2.getTrackbarPos("HUE Min", "HSV") h_max = cv2.getTrackbarPos("HUE Max", "HSV") s_min = cv2.getTrackbarPos("SAT Min", "HSV") s_max = cv2.getTrackbarPos("SAT Max", "HSV") v_min = cv2.getTrackbarPos("VALUE Min", "HSV") v_max = cv2.getTrackbarPos("VALUE Max", "HSV") lower = np.array([h_min, s_min, v_min]) upper = np.array([h_max, s_max, v_max]) mask = cv2.inRange(imgHsv, lower, upper) result = cv2.bitwise_and(img, img, mask=mask) print(f'[{h_min},{s_min},{v_min},{h_max},{s_max},{v_max}]') mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) hStack = np.hstack([img, mask, result]) cv2.imshow('Horizontal Stacking', hStack) if cv2.waitKey(1) and 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
def __init__( self, log_level=None ): self.toggle_action_interval = 2 # buffer in seconds for toggle actions self.pose = None self.log_level = log_level self.is_flying = False self.drone_sdk = drone.Tello() self.axis_speed = {"rotation": 0, "right-left": 0, "forward-back": 0, "up-down": 0} self.cmd_axis_speed = {"rotation": 0, "right-left": 0, "forward-back": 0, "up-down": 0} self.prev_axis_speed = self.axis_speed.copy() self.def_speed = {"rotation": 50, "right-left": 35, "forward-back": 35, "up-down": 80} self.rotation = 0 self.toggle_tracking_timestamp = time.time() - 3 self.tracking_after_takeoff = False self.tracking = False self.keep_distance = None self.palm_landing = False self.palm_landing_approach = False self.rotation_to_consume = 0 self.timestamp_keep_distance = time.time() self.timestamp_take_picture = None self.throw_ongoing = False self.scheduled_takeoff = None self.timestamp_no_body = time.time() self.rotation_to_consume = 0 self.set_logging(log_level) self.init_drone() self.init_sounds() self.start_time = time.time() self.use_gesture_control = False self.is_pressed = False self.battery = self.drone_sdk.get_battery() self.op = PoseDetectorWrapper() self.morse = CameraMorse(display=False) self.morse.define_command("-", self.delayed_takeoff) self.tracker = PersonTracker(log) self.pygame_screen = PyGameScreen(self) self.pygame_screen.add_listeners() self.path_manager = PathManager(self.pygame_screen) self.path_manager.watch(self)
def main(): drone = tello.Tello() drone.connect() print(drone.get_battery()) drone.streamon() drone.takeoff() #cap = cv2.VideoCapture(1) while True: #_, img = cap.read() img = drone.get_frame_read().frame img = cv2.resize(img, (width, height)) img = cv2.flip(img, 0) imgThres = thresholding(img) cx = getContours(imgThres, img) ## For Translation senOut = getSensorOutput(imgThres, sensors, img) ## Rotation sendCommands(senOut, cx, drone) cv2.imshow("Output", img) cv2.imshow("Path", imgThres) cv2.waitKey(1)
def challenge4(): me = tello.Tello() me.connect() print(me.get_battery()) me.takeoff() me.send_rc_control(0, 50, 0, 0) """forward 25""" sleep(3) me.send_rc_control(50, 0, 0, 0) sleep(1) me.send_rc_control(0, -40, 0, 0) sleep(3) me.send_rc_control(-40, 0, 0, 0) sleep(1) me.land()
from djitellopy import tello import keyboard import time import cv2 # Connect to Tello tello = tello.Tello() tello.connect() print(tello.get_battery()) global airborne airborne = False def get_keyboard_input(): lr, fb, ud, yv = 0, 0, 0, 0 speed = 100 # Left - Right if keyboard.is_pressed('a'): lr = -speed elif keyboard.is_pressed('d'): lr = speed # Front - Back if keyboard.is_pressed('s'): fb = -speed elif keyboard.is_pressed('w'): fb = speed # Up - Down
from djitellopy import tello from threading import Thread from time import sleep, time import pygame import cv2 import os drone = tello.Tello() pygame.init() HEIGHT, WIDTH = 400, 400 WIN = pygame.display.set_mode((HEIGHT,WIDTH)) pygame.display.set_caption('Tello Keyboard') fps = 60 def init(): drone.connect() # print('connection unsuccessful') drone.streamon() print (drone.get_battery()) def get_image(): img = drone.get_frame_read().frame img = cv2.resize(img, (360,240)) cv2.imshow("Image", img) cv2.waitKey(1) def getKey(keyName, keyInput): ans = False myKey = getattr(pygame, 'K_{}'.format(keyName)) if keyInput[myKey]: ans = True
from time import sleep from djitellopy import tello import keyboard as kp kp.init() me = tello.Tello() me.connect() print(me.get_battery()) def getKeyboardInput(): lr, fb, ud, yaw = 0, 0, 0, 0 speed = 50 if kp.getKey("LEFT"): lr = -speed elif kp.getKey("RIGHT"): lr = speed if kp.getKey("UP"): fb = speed elif kp.getKey("DOWN"): fb = -speed if kp.getKey("w"): ud = speed elif kp.getKey("s"): ud = -speed if kp.getKey("a"): yaw = -speed elif kp.getKey("d"): yaw = +speed if kp.getKey("q"): me.land() if kp.getKey("e"): me.takeoff() return [lr, fb, ud, yaw]
import KeyPressModule as kp from djitellopy import tello import cv2 import time from time import sleep kp.init() #pygame pencerimiz aktif olarak çalışacak me=tello.Tello() #tello objemizi yarattık me.connect() #tello drone bağlantımızı sağladık print(me.get_battery()) #pil durumunu kontrol ediyoruz global img me.streamon() def getKeyboardInput(): lr,fb,up,yv=0,0,0,0 #sol-sağ,ileri-geri,yukarı-aşağı,rotasyon değerleri speed=30 #klavye üzerinde her sol ok tuşuna bastığınız zaman drone 50 -speed ile sol yöne gidecektir. # + ise sağ yön anlamına gelir if kp.getKey("LEFT"): lr= -speed elif kp.getKey("RIGHT"): lr = speed #ileri geri gitmek içinde aynı mantık vardır + speed ileri - speed geri gitmek için kullanılır if kp.getKey("UP"): fb = speed elif kp.getKey("DOWN"): fb = -speed #alçalmak ve yükselmek için de aynı mantığı kullanıyoruz if kp.getKey("w"): up = speed elif kp.getKey("s"): up = -speed #drone saat yönünde ve ters yönde çevirmek için: