def testDroneConnection(self): # read battery status, extract an image drone = libardrone.ARDrone(1, 0) drone.reset() ''' I = drone.image if I != None: frame = I[:, :, ::-1].copy() # You might need to call drone.reset() before taking off if the drone is in # emergency mode # get battery status bat = drone.navdata.get(0, dict()).get('battery', 0) print bat # get an image #while(1): img = drone.image cv2.imwrite('/Users/mangotee/Pictures/imgDroneOut.png',img) # test flying #drone.takeoff() #drone.land() #drone.halt() ''' running = True bat = drone.navdata.get(0, dict()).get('battery', 0) print('Battery: %i%%' % bat) counter = 1 while running: try: # This should be an numpy image array pixelarray = drone.get_image() frame = pixelarray[:, :, ::-1].copy() if pixelarray != None: #print "problem" #frame = drone.image # Display the Image pass if counter == 1: cv2.imwrite('/Users/mangotee/Pictures/imgDroneOut.png', frame) counter = counter + 1 cv2.imshow('Drone', frame) #print "Success" except: pass #print "Failed" ''' if cv2.waitKey(1) & 0xFF == ord('w'): print "Take OFF!!" drone.reset() drone.takeoff() drone.hover() ''' # Listen for Q Key Press if cv2.waitKey(1) & 0xFF == ord('q'): running = False cv2.destroyAllWindows()
def __init__(self): self.drone = libardrone.ARDrone(is_ar_drone_2=True) self.frame = cv2.cvtColor(self.drone.get_image(), cv2.COLOR_BGR2RGB) cv2.namedWindow('camshift') cv2.setMouseCallback('camshift', self.onmouse) self.selection = None self.drag_start = None self.tracking_state = 0 self.show_backproj = False self.ai_control = False self.leap_control = False self.speed_multiplier = 1 # Set up leap motion listener self.listener = LeapToQuadListener() self.controller = Leap.Controller() self.listener.parent = self # So it can send messages back if necessary # Have the listener receive events from the controller self.controller.add_listener(self.listener)
def __init__(self): self.drone = None self.main = Tkinter.Tk() self.picLabel = Tkinter.Label(self.main, text = "Waiting for ARDrone image") self.picLabel.grid(row = 0, column = 0) self.dataLabel = Tkinter.Label(self.main, text = "Waiting for Navdata") self.dataLabel.grid(row=1, column = 0) self.main.bind_all('<Any-KeyPress>', self.respondToKeyPress) #self.main.bind('<KeyPress-n>', self.nextPicture) #self.main.bind('<KeyPress-r>', self.resetDrone) #self.main.bind('<KeyPress-Return>', self.takeoff) #self.main.bind('<KeyPress- >', self.land) #self.main.bind('<KeyPress-Up>', self.moveUp) #self.main.bind('<KeyPress-Down>', self.moveDown) #self.main.bind('<KeyPress-Left>', self.turnLeft) #self.main.bind('<KeyPress-Right>', self.turnRight) #self.main.bind('<KeyPress-w>', self.moveForward) #self.main.bind('<KeyPress-s>', self.moveBackward) #self.main.bind('<KeyPress-a>', self.bankLeft) #self.main.bind('<KeyPress-d>', self.bankRight) self.main.bind_all('<Any-KeyRelease>', self.keyRelease) self.drone = libardrone.ARDrone(True) self.mcs = MultiCamShift(self.drone, self) self.mcs.start()
def run(self): """Launch drone class""" self.drone = libardrone.ARDrone(True) print "running" move_forward = 0 move_backward = 0 move_left = 0 move_right = 0 turn = 0 running = True while running: try: event, params = self.event_queue.get(True, 1) print "got event" event(*params) except Queue.Empty: self.drone.hover() sleep(0.001) print "Shutting down...", drone.reset() drone.halt() print "Ok." quit()
def Takeoff(): pygame.init() W, H = 320, 240 screen = pygame.display.set_mode((W, H)) drone = libardrone.ARDrone() clock = pygame.time.Clock() drone.takeoff()
def main(): #pygame.init() #W, H = 320, 240 #screen = pygame.display.set_mode((W, H)) drone = libardrone.ARDrone() drone.takeoff() drone.hover() print "Make the ardrone dance!" running = True while running: dance = raw_input("type waltz, boogie or quit> ") if dance == "boogie": print "boogying" funk_leftright(drone) elif dance == "waltz": print "waltzing" formal_waltz(drone) elif dance == "quit": print "quitting" running = False sleep(10) print "Shutting down...", drone.halt() print "Ok."
def main(): drone = libardrone.ARDrone() drone.takeoff() pygame.time.delay(3000) drone.hover() pygame.time.delay(2000) for (action, duration) in path: print "next action:", action, "duration:", duration if action == "backward": drone.move_backward() elif action == "hover": drone.hover() elif action == "forward": drone.move_forward() elif action == "left": drone.move_left() elif action == "right": drone.move_right() elif action == "up": drone.move_up() elif action == "down": drone.move_down() elif action == "turn_left": drone.turn_left() elif action == "turn_right": drone.turn_right() pygame.time.delay(duration) drone.hover() pygame.time.delay(3000) drone.land()
def on_init(self, controller): print "Initialized" self.tolerance = 10 self.deriv_tol = 5 self.takedoff = False self.drone = libardrone.ARDrone() self.new_time; self.old_time;
def __init__(self): self.drone = libardrone.ARDrone(True) self.lock = threading.Lock() self.runFlag = True self.scs = SIFTcamshift(self.drone, self) self.scs.start() self.width, self.height = self.scs.getFrameDims() self.cx, self.cy = self.width / 2, self.height / 2 self.targetRelativeArea = 0.38
def __init__(self): self.drone = libardrone.ARDrone(True) self.lock = threading.Lock() self.runFlag = True self.mcs = MultiCamShift(self.drone, self, trackColors = ["pink", "blue"]) self.mcs.start() self.height, self.width, self.depth = self.drone.image_shape #self.mcs.getFrameDims() self.cx, self.cy = self.width / 2, self.height / 2 self.targetRelativeArea = 0.035
def __init__(self): """ Initialize the drone. Moves the drone to the maximal height in its starting point """ self.__current_hit_count = 0 self.__drone = libardrone.ARDrone() self.__drone.takeoff() time.sleep(3)
def __init__(self): threading.Thread.__init__(self) self.drone = libardrone.ARDrone(True) self.lock = threading.Lock() self.runFlag = True self.mcs = MultiCamShift(self.drone, self, trackColors = ["red", "red"]) self.mcs.start() self.width, self.height = self.mcs.getFrameDims() self.cx, self.cy = self.width / 2, self.height / 2 self.targetRelativeArea = 0.035
def __init__(self, log=True): """ Initialize the connection and variables. """ self.log = log if (log): self.out = open('odometry', 'w') print "Connecting..." self.cam = cv2.VideoCapture('tcp://192.168.1.1:5555') self.drone = libardrone.ARDrone() print "Ok." self.last_thata = self.drone.navdata.get(0, dict()).get('psi', 0)
def __init__(self): """Sets up a drone object Binds the keypress and release to callback functions""" self.drone = None self.main = cv2.namedWindow("Drone View") self.drone = libardrone.ARDrone(True) print("Drone initialized") print( "\n q for quit \n spacebar for takeoff/land \n b for battery level check \n AWSD directional control \n " "x and c for up and down \n i for altitude info") self.inAir = False self.quitting = False
def __init__(self): print "starting drone..." self.drone = libardrone.ARDrone() self.K, self.d = parse_calib('calibration.txt') self.marker_frame = np.array( [[0, 0, 0], [MARKER_SIZE, 0, 0], [MARKER_SIZE, MARKER_SIZE, 0], [0, MARKER_SIZE, 0]], dtype=np.float32) self.ALLOW_FLIGHT = False self.record = Queue(1) self.frame_queue = Queue(2) self.frame_worker = Process(target=self.query_frames) self.frame_worker.start()
def __init__(self): """Sets up a drone object, and a Tkinter window to display the picture and other things. Binds the keypress and release to callback functions""" self.drone = None #self.main = cv2.namedWindow("Drone View") #self.displayText = "" #self.dispFont = cv2.FONT_HERSHEY_SIMPLEX self.drone = libardrone.ARDrone(True) print("Drone initialized") self.inAir = False self.quitting = False
def __init__(self): self.drone = libardrone.ARDrone(is_ar_drone_2=True) self.frame = cv2.cvtColor(self.drone.get_image(), cv2.COLOR_BGR2RGB) cv2.namedWindow('camshift') cv2.setMouseCallback('camshift', self.onmouse) self.selection = None self.drag_start = None self.tracking_state = 0 self.show_backproj = False self.ai_control = False self.speed_multiplier = 1
def __init__(self): # Pygame init pygame.init() self.drone = libardrone.ARDrone() print "Connected to drone." # Gamepad connecting self.j = pygame.joystick.Joystick(0) # Gamepad init self.j.init() print "Initialized." self.running = True self.hover = True
def __init__(self, map_center=(51.195323, 4.464865), map_zoom=20, map_scale=1, map_height=640, map_name='staticmap.png', use_gps=True): self.drone = libardrone.ARDrone() self.drone.config('general:navdata_demo', 'TRUE') self.drone.config('general:ardrone_name', 'DronePhil') self.drone.config('control:outdoor', 'TRUE') self.drone.config('control:flight_without_shell', 'TRUE') self.drone.config('control:altitude_max', '25000') self.pid = PID() self.map_center = map_center self.map_zoom = map_zoom self.map_scale = map_scale self.map_height = map_height self.map_name = map_name self.use_gps = use_gps self.flight_data_bg = 'flight_data.png' self.gps_data = [] self.waypoints = [] # gps tracking if (self.use_gps): cv2.namedWindow('Map') cv2.moveWindow('Map', self.map_height, 0) cv2.cv.SetMouseCallback('Map', self.mouse_click) self.gps_thread = threading.Thread(target=self.process_gps) self.gps_thread.start() # flight data cv2.namedWindow('Flight Data') cv2.moveWindow('Flight Data', 0, 405) self.data_thread = threading.Thread(target=self.process_flight_data) self.data_thread.start() # object tracking cv2.namedWindow('Video') cv2.moveWindow('Video', 0, 0) self.process_video() cv2.startWindowThread()
def setup(): global state global drone global running global flying global battery_level LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, 'Greeting!!') LCD1602.write(1, 1, 'Coderdojo:-)') ADC.setup(0x48) # Setup PCF8591 GPIO.setmode(GPIO.BOARD) GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) drone = libardrone.ARDrone() drone.set_speed(0.2)
def main(): pygame.init() drone = libardrone.ARDrone() print(type(drone.image)) image = cv2.cvtColor(drone.image, cv2.COLOR_BGR2GRAY ) # Displaying the image cv2.imshow("test", image) W, H = 320, 240 screen = pygame.display.set_mode((W, H)) print ("init") print ("takeoff start") drone.takeoff() #operation(2) drone.land() print ("land end") pygame.quit()
def __init__(self, port, debug=False): self.drone = libardrone.ARDrone() #ALT = self.drone.navdata['altitude'] #print ALT self.drone.trim() try: super(CommandData, self).__init__(port) self.add_method("/command", 's', self.command_callback) # register a fallback for unhandled messages self.add_method(None, None, self.fallback) self.debug = debug except liblo.ServerError, err: print str(err) sys.exit()
def MoveRight(): drone = libardrone.ARDrone() FrontOfObject = False while not FrontOfObject: # Capture frame-by-frame ret, frame = video_capture.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame', gray) drone.move_right() if FrontOfObject: drone.hover()
def main(): drone = libardrone.ARDrone(True) drone.reset() drone.set_camera_view(1) running = True while (1): try: frame = drone.get_image() frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) cv2.imshow('frame', frame) tecla = cv2.waitKey(15) if (tecla == 1048603): cv2.destroyAllWindows() drone.reset() drone.halt() break except: pass
def __init__(self): if DRONE: self.drone = libardrone.ARDrone(is_ar_drone_2=True) self.frame = cv2.cvtColor(self.drone.get_image(), cv2.COLOR_BGR2RGB) else: self.camera = cv2.VideoCapture(0) rval, self.frame = self.camera.read() cv2.namedWindow('camshift') #cv2.namedWindow('mask') #cv2.namedWindow('prob') cv2.setMouseCallback('camshift', self.onmouse) self.selection = None self.drag_start = None self.tracking_state = 0 self.show_backproj = False self.ai_control = False self.leap_control = False # Set up leap motion listener self.listener = LeapToQuadListener() self.controller = Leap.Controller() self.listener.parent = self # So it can send messages back if necessary # Have the listener receive events from the controller self.controller.add_listener(self.listener) # Controller stuff self.reset_speed() self.I_gain = 0.05 self.I_decay = 0.90 self.tracking_status_changed = False self.z_set_height = 0.4
def main(): pygame.init() W, H = 320, 240 screen = pygame.display.set_mode((W, H)) drone = libardrone.ARDrone() clock = pygame.time.Clock() drone.takeoff() running = True while running: # Capture frame-by-frame ret, frame = video_capture.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Display the resulting frame cv2.imshow('frame', gray) time.sleep(3) drone.move_forward() time.sleep(2) drone.halt()
def run(self): """We call pygame (to use controler)""" #pygame.init() SDL_Init( SDL_INIT_JOYSTICK ) """Launch drone class""" drone = libardrone.ARDrone(True) clock = pygame.time.Clock() running = True """Set up and init joystick""" #j=joystick.Joystick(0) #j.init() gGameController = SDL_JoystickOpen( 0 ) move_forward = 0 move_backward = 0 move_left = 0 move_right = 0 yaw_left = 0 yaw_right = 0 turn = 0 xvalue = 0 yvalue = 0 zvalue = 0 event = SDL_Event() time_1 = time.time() while running: #for event in pygame.event.get(): while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_JOYBUTTONDOWN: # takeoff #if SDL_JoystickGetButton (gGameController, 7) == 1: if event.jbutton.button == 7: print "Take Off !" drone.takeoff() # Land elif event.jbutton.button == 2: print "Land !" drone.land() # Stop and land elif event.jbutton.button == 6: print "Stop and Land !" drone.land() running = False # Altitude UP elif event.jbutton.button == 3: print "Altitude UP" drone.speed = 1 drone.move_up() # Altitude Down elif event.jbutton.button == 0: print "Altitude Down" drone.speed = 1 drone.move_down() # Emmergency elif event.jbutton.button == 1: print "Emergency !" drone.reset() if event.type == SDL_JOYBUTTONUP: # Altitude UP if event.jbutton.button == 3 : print "Altitude UP STOP !" drone.speed = 0 drone.hover() # Altitude Down elif event.jbutton.button == 0: print "Altitude Down STOP !" drone.speed = 0 drone.hover() #if event.type == pygame.JOYAXISMOTION: if event.type == SDL_JOYAXISMOTION: ''' xvalue = SDL_JoystickGetAxis(gGameController, 0) / 32768.0 yvalue = SDL_JoystickGetAxis(gGameController, 1) / 32768.0 zvalue = SDL_JoystickGetAxis(gGameController, 3) / 32768.0 ''' if event.jaxis.axis == 0: xvalue = event.jaxis.value / 32768.0 elif event.jaxis.axis == 1: yvalue = event.jaxis.value / 32768.0 elif event.jaxis.axis == 3: zvalue = event.jaxis.value / 32768.0 ''' if xvalue < -xDeadZone : xDir = -1 elif xv > xDeadZone : xDir = 1 else : xDir = 0 if yv < -yDeadZone : yDir = -1 elif yv > yDeadZone : yDir = 1 else : yDir = 0 if zv < -zDeadZone : zDir = -1 elif zv > zDeadZone : zDir = 1 else : zDir = 0 ''' # Axis 0 / Roll if xvalue < 0: if round(xvalue*-1,1) != move_left: # Axis 0 / Left print "Axis 0 / Left" print "Speed" + " : " + str(round(xvalue*-1,1)) move_left = round(xvalue*-1,1); drone.speed = round(xvalue*-1,1) drone.move_left() elif xvalue > 0: if round(xvalue,1) != move_right: # Axis 0 / Right print "Axis 0 / Right" print "Speed" + " : " + str(round(xvalue,1)) move_right = round(xvalue,1) drone.speed = round(xvalue,1) drone.move_right() # Axe 1 / Pitch if yvalue < 0: if round(yvalue*-1,1) != move_forward: # Axis 1 / Forward print "Axis 1 / Forward" print "Speed" + " : " + str(round(yvalue*-1,1)) move_forward = round(yvalue*-1,1) drone.speed = round(yvalue*-1,1) drone.move_forward() elif yvalue > 0: if round(yvalue,1) != move_backward: # Axis 1 / Backward print "Axis 1 / Backward" print "Speed" + " : " + str(round(yvalue,1)) move_backward = round(yvalue,1) drone.speed = round(yvalue,1) drone.move_backward() #Axis 3 / Yaw if zvalue < 0: if round(zvalue*-1,1) != yaw_left: # Axis 3 / Yaw left print "Axis 3 / Yaw left" print "Speed" + " : " + str(round(zvalue*-1,1)) yaw_left = round(zvalue*-1,1) drone.speed = round(zvalue*-1,1) drone.turn_left() elif zvalue > 0: if round(zvalue,1) != yaw_right: # Axis 3 / Yaw right print "Axis 3 / Yaw right" print "Speed" + " : " + str(round(zvalue,1)) yaw_right = round(zvalue,1) drone.speed = round(zvalue,1) drone.turn_right() ''' # Axis 3 / Yaw if round(zvalue*1,0) > 0: if round(zvalue*1,0) != turn: # Axis 3 / Yaw Right print "Axis 3 / Yaw Right" + " : " + str(round(zvalue*1,0)) turn = round(zvalue*1,0) drone.speed = 1 drone.turn_right() elif round(zvalue*-1,0) > 0: if round(zvalue*-1,0) != turn: # Axe 3 / Yaw left print "Axis 3 / Yaw Left" + " : " + str(round(zvalue*-1,0)) turn = round(zvalue*-1,0) drone.speed = 1 drone.turn_left() elif round(zvalue*1,0) == 0: if round(zvalue*1,0) != turn: # Axe 3 / Stop Yaw print "Axis 3 / Stop Yaw" + " : " + str(round(zvalue*1,0)) turn = round(zvalue*1,0) drone.speed = 0 drone.hover() ''' time_2 = time.time() time_diff = (time_2 - time_1)*1000 print time_diff time_1 = time_2 clock.tick(10000) print "Shutting down...", drone.reset() drone.halt() video.stop() print "Ok." quit()
#!/usr/bin/env python import time, libardrone drone = libardrone.ARDrone() def run(): v = input("Choisissez moi une vitesse de deplacement : ") while 1 == 1: saisie = raw_input("Saisissez une commande : ") if saisie == "up": drone.takeoff() print "Je decolle\n" elif saisie == "down": drone.land() print "J'atteris\n" elif saisie == "moveforward": drone.speed = v drone.move_forward() print "J avance\n" elif saisie == "movebackward": drone.speed = v drone.move_backward() print "Je recule\n"
def main(): pygame.init() W, H = 320, 240 screen = pygame.display.set_mode((W, H)) drone = libardrone.ARDrone() clock = pygame.time.Clock() running = True while running: 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: if event.key == pygame.K_ESCAPE: drone.reset() running = False # takeoff / land elif event.key == pygame.K_RETURN: drone.takeoff() elif event.key == pygame.K_SPACE: drone.land() # emergency elif event.key == pygame.K_BACKSPACE: drone.reset() # forward / backward elif event.key == pygame.K_w: drone.move_forward() elif event.key == pygame.K_s: drone.move_backward() # left / right elif event.key == pygame.K_a: drone.move_left() elif event.key == pygame.K_d: drone.move_right() # up / down elif event.key == pygame.K_UP: drone.move_up() elif event.key == pygame.K_DOWN: drone.move_down() # turn left / turn right elif event.key == pygame.K_LEFT: drone.turn_left() elif event.key == pygame.K_RIGHT: drone.turn_right() # speed elif event.key == pygame.K_1: drone.speed = 0.1 elif event.key == pygame.K_2: drone.speed = 0.2 elif event.key == pygame.K_3: drone.speed = 0.3 elif event.key == pygame.K_4: drone.speed = 0.4 elif event.key == pygame.K_5: drone.speed = 0.5 elif event.key == pygame.K_6: drone.speed = 0.6 elif event.key == pygame.K_7: drone.speed = 0.7 elif event.key == pygame.K_8: drone.speed = 0.8 elif event.key == pygame.K_9: drone.speed = 0.9 elif event.key == pygame.K_0: drone.speed = 1.0 try: surface = pygame.image.fromstring(drone.image, (W, H), 'RGB') # battery status hud_color = (255, 0, 0) if drone.navdata.get( 'drone_state', dict()).get('emergency_mask', 1) else (10, 10, 255) bat = drone.navdata.get(0, dict()).get('battery', 0) f = pygame.font.Font(None, 20) hud = f.render('Battery: %i%%' % bat, True, hud_color) screen.blit(surface, (0, 0)) screen.blit(hud, (10, 10)) except: pass pygame.display.flip() clock.tick(50) pygame.display.set_caption("FPS: %.2f" % clock.get_fps()) print("Shutting down..."), drone.halt() print("Ok.")
def main(): pygame.init() W, H = 640, 320 screen = pygame.display.set_mode((W, H)) drone = libardrone.ARDrone() clock = pygame.time.Clock() running = True cam = cv2.VideoCapture('tcp://192.168.1.1:5555') while running: 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: if event.key == pygame.K_ESCAPE: drone.reset() running = False # takeoff / land elif event.key == pygame.K_RETURN: drone.takeoff() elif event.key == pygame.K_SPACE: drone.land() # emergency elif event.key == pygame.K_BACKSPACE: drone.reset() # forward / backward elif event.key == pygame.K_w: drone.move_forward() elif event.key == pygame.K_s: drone.move_backward() # left / right elif event.key == pygame.K_a: drone.move_left() elif event.key == pygame.K_d: drone.move_right() # up / down elif event.key == pygame.K_UP: drone.move_up() elif event.key == pygame.K_DOWN: drone.move_down() # turn left / turn right elif event.key == pygame.K_LEFT: drone.turn_left() elif event.key == pygame.K_RIGHT: drone.turn_right() # speed elif event.key == pygame.K_1: drone.speed = 0.1 elif event.key == pygame.K_2: drone.speed = 0.2 elif event.key == pygame.K_3: drone.speed = 0.3 elif event.key == pygame.K_4: drone.speed = 0.4 elif event.key == pygame.K_5: drone.speed = 0.5 elif event.key == pygame.K_6: drone.speed = 0.6 elif event.key == pygame.K_7: drone.speed = 0.7 elif event.key == pygame.K_8: drone.speed = 0.8 elif event.key == pygame.K_9: drone.speed = 0.9 elif event.key == pygame.K_0: drone.speed = 1.0 running, cam_image = cam.read() if running: try: cv2_image = cv2.cvtColor(cam_image, cv2.COLOR_BGR2RGB) surface = pygame.surfarray.make_surface(cv2_image) surface = pygame.transform.rotate(surface, -90) surface = pygame.transform.flip(surface, True, False) screen.blit(surface, (0, 0)) except: pass else: # error reading frame print 'error reading video feed' pygame.display.flip() clock.tick(30) print "Shutting down...", drone.halt() print "Ok." cam.release() cv2.destroyAllWindows()