from torchvision import transforms import torch.nn as nn import numpy as np from skimage import io import torchvision.transforms.functional as F import torch.nn.functional as f from PIL import Image import ardrone import time import pygame from Pipeline.option import args from Architecture.model import model # from Data.data import trans drone = ardrone.ARDrone() drone.speed = 0.1 pygame.init() W, H = 299, 299 screen = pygame.display.set_mode((W, H)) imsize = 299 threshold = 0.6 trans = transforms.Compose([ transforms.Resize(imsize), transforms.CenterCrop(imsize), transforms.ToTensor() ])
def main(win): drone = ardrone.ARDrone() pygame.init() if drone == None: print("not connect to drone") return -1 datasource = dataSource.DataSource() model = load_model() drone.speed = 0.7 v = Video(screen=win, drone=drone) running = True eeg = False while running: #print(eeg) temp = datasource.readData() pre = np.argmax(model.predict(temp)) if eeg == True: print(pre) if pre == 1: drone.move_forward() elif pre == 2: drone.turn_left() elif pre == 3: drone.turn_right() v.video() for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYUP: drone.hover() elif event.type == pygame.KEYDOWN: k = pygame.key.get_pressed() if k[pygame.K_t]: if eeg == True: eeg = False else: eeg = True elif k[pygame.K_DELETE]: running = False elif k[pygame.K_ESCAPE]: drone.reset() running = False # takeoff / land elif k[pygame.K_q]: drone.takeoff() elif k[pygame.K_SPACE]: drone.land() elif k[pygame.K_BACKSPACE]: drone.reset() # forward / backward elif k[pygame.K_w]: drone.move_forward() elif k[pygame.K_s]: drone.move_backward() # left / right elif k[pygame.K_a]: drone.move_left() elif k[pygame.K_d]: drone.move_right() # up / down elif k[pygame.K_UP]: drone.move_up() elif k[pygame.K_DOWN]: drone.move_down() # turn left / turn right elif k[pygame.K_LEFT]: drone.turn_left() elif k[pygame.K_RIGHT]: drone.turn_right() print("Shutting down...") drone.halt() print("Ok.")
if len(sys.argv) != 1 and len(sys.argv) != 2: print('usage: ' + sys.argv[0] + ' [host]') sys.exit(1) fd = sys.stdin.fileno() oldterm = termios.tcgetattr(fd) newattr = termios.tcgetattr(fd) newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO termios.tcsetattr(fd, termios.TCSANOW, newattr) oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) if len(sys.argv) >= 2: drone = ardrone.ARDrone(sys.argv[1]) else: drone = ardrone.ARDrone() try: while 1: try: c = sys.stdin.read(1).lower() if c == 'q': break elif c == 'a': drone.move_left() elif c == 'd': drone.move_right() elif c == 'w':
import inspect import ardrone import sys import time import os import re import rosgraph __topics__ = [topic for topic in rosgraph.Master('/rostopic').getSystemState()] __topics__ = [topic[0] for item in __topics__ for topic in item] __topics__ = filter(lambda u: re.match('/.*/navdata', u) is not None, __topics__) __dronenames__ = map(lambda u: os.path.dirname(u)[1:], __topics__) __drones__ = {name: ardrone.ARDrone(name) for name in __dronenames__} if len(__drones__) == 0: print("I don't see any drones created") quit() __firstdrone__ = list(__drones__.values())[0] __thismodule = sys.modules[__name__] def exit(): """Exit the prompt.""" raise EOFError def quit():