# show the frame and the binary image cv2.imshow("Drone", frame) cv2.waitKey(10) cv2.imshow("Binary", blue) def video_start(): print("Starting video...") cv2.namedWindow("Drone") cv2.namedWindow("Binary") def video_end(): print("Ending video...") cv2.destroyWindow("Drone") cv2.destroyWindow("Binary") # Have to send waitKey several times on Unix to make window disappear for i in range(1, 5): cv2.waitKey(1) print("Connecting to drone..") drone = Bebop() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() print("Connected.") for i in xrange(10000): drone.update() print("Battery:", drone.battery)
def video2stdout(): drone = Bebop( metalog=None, onlyIFrames=False ) drone.videoCbk = videoCallback drone.videoEnable() while True: drone.update()
pan = clip(pan + panDelta, panMin, panMax) # Reset camera on B if joystick.get_button(1) == 1: tilt = 0 pan = 0 if joystick.get_button(5) == 1: print("Flying to altitude: 1.5") drone.flyToAltitude(1.25) drone.moveCamera(tilt, pan) # All movement updated here if userMovement: drone.update(cmd=movePCMDCmd(True, roll, pitch, yaw, gaz)) elif drone.findSphero: roll = (drone.objectCenterX - (drone.frameWidth >> 1)) * drone.moveScaler pitch = ((drone.frameHeight >> 1) - drone.objectCenterY) * drone.moveScaler roll = clip(roll, -50, 50) pitch = clip(pitch, -50, 50) # print("Finding Sphero") # print(roll) # print(pitch) spheroMoveCounter += 1 # if (drone.sinceLastSphero % 3) == 0 and drone.altitude >= 1:
# check to see if any contours were found if len(cnts) > 0: # sort the contours and find the largest one -- we # will assume this contour correspondes to the area # of my phone cnt = sorted(cnts, key=cv2.contourArea, reverse=True)[0] # compute the (rotated) bounding box around then # contour and then draw it rect = np.int32(cv2.boxPoints(cv2.minAreaRect(cnt))) print(rect); cv2.drawContours(frame, [rect], -1, (0, 255, 0), 2) # show the frame and the binary image cv2.imshow("Tracking", frame) cv2.waitKey(10) cv2.imshow("Binary", blue) print("Connecting to drone..") drone = Bebop( metalog=None, onlyIFrames=False, jpegStream=True ) drone.videoCbk = videoCallback drone.videoEnable() print("Connected.") for i in xrange(10000): drone.update( ); print("Battery:", drone.battery)
if joystick.get_button(0) == 1 and hat_x == -1: print("Executing Left Flip") drone.leftFlip() if joystick.get_button(1) == 1: print("Battery: " + str(drone.battery)) # --- Flying --- # Power values roll = scale(joystick.get_axis(0), MAX_SPEED) pitch = -scale(joystick.get_axis(1), MAX_SPEED) yaw = scale(joystick.get_axis(3), MAX_SPEED) gaz = -scale(joystick.get_axis(4), MAX_SPEED) drone.update(cmd=movePCMDCmd(True, roll, pitch, yaw, gaz)) # --- Move camera --- # Triggers to tilt if not(joystick.get_button(0) == 1) and joystick.get_axis(2) > 0.05: tiltDelta = scale(joystick.get_axis(2), -10) if not(joystick.get_button(0) == 1) and joystick.get_axis(5) > 0.05: tiltDelta = scale(joystick.get_axis(5), 10) # A and triggers to pan if joystick.get_button(0) == 1 and joystick.get_axis(2) > 0.05: panDelta = scale(joystick.get_axis(2), -10) if joystick.get_button(0) == 1 and joystick.get_axis(5) > 0.05:
while not done: # EVENT PROCESSING STEP for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop executing_command = False if joystick.get_button(0) == 1: executing_command = True print("Landing...") if drone.flyingState is None or drone.flyingState == 1: # if taking off then do emegency landing drone.emergency() drone.land() if joystick.get_button(3) == 1: executing_command = True print("Taking off..") drone.takeoff() if joystick.get_button(7) == 1: executing_command = True drone.update(cmd=movePCMDCmd(True, 0, MAX_SPEED, 0, 0)) # start going forward slowly drone.update(cmd=None) # Close the window and quit. pygame.quit()
import pygame import sys from commands import * from bebop import Bebop import logging logging.basicConfig(level=logging.DEBUG) print("Connecting to drone...") drone = Bebop() drone.trim() print("Connected.") drone.takeoff() drone.wait(.2) drone.update(cmd=movePCMDCmd(True, 0, 40, 0, 0)) drone.wait(2.3) drone.update(cmd=movePCMDCmd(True, 0, 0, 0, 0)) drone.wait(.2) drone.land()
for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop executing_command = False if joystick.get_button(0) == 1: executing_command = True print("Landing...") if drone.flyingState is None or drone.flyingState == 1: # if taking off then do emegency landing drone.emergency() drone.land() if joystick.get_button(1) == 1: executing_command = True drone.update(cmd=movePCMDCmd(True, 0, 0, MAX_SPEED, 0)) print("Drone spinning clockwise.") if joystick.get_button(2) == 1: executing_command = True drone.update(cmd=movePCMDCmd(True, 0, 0, -1 * MAX_SPEED, 0)) print("Drone spinning counterclockwise.") if joystick.get_button(3) == 1: executing_command = True print("Taking off..") drone.takeoff() if joystick.get_button(4) == 1: executing_command = True print("Descending...")
import pygame import sys from commands import * from bebop import Bebop print("Connecting to drone...") drone = Bebop( metalog=None, onlyIFrames=True ) drone.trim() print("Connected.") drone.takeoff() drone.wait(5) drone.update(cmd=movePCMDCmd(True, 0, 0, -50, 0)) drone.wait(3) drone.land()
# pitch*= .4 # # drone.update(cmd=movePCMDCmd(True, roll, pitch, 0, 0)) # # else: # drone.hover() # clock.tick(20) # if userMovement: # drone.update(cmd=movePCMDCmd(True, roll, pitch, yaw, gaz)) drone.takeoff() drone.flyToAltitude(1.5) drone.hover() drone.wait(.2) drone.update(cmd=movePCMDCmd(True, 0, MAX_SPEED, 0, 0)) drone.wait(3) drone.hover() drone.wait(.2) startFindingIdol = True if idolInCenter: drone.update(cmd=movePCMDCmd(True, 0, MAX_SPEED, 0, 0)) drone.wait(8) drone.hover() drone.land() if startFindingIdol: timer += timer if idolFound: roll = (drone.objectCenterX - (drone.frameWidth >> 1)) * drone.moveScaler
def video2stdout(): drone = Bebop(metalog=None, onlyIFrames=False) drone.videoCbk = videoCallback drone.videoEnable() while True: drone.update()
#leftPower = 0 #rightPower = 0 video = True if event.type == pygame.QUIT: # print "hi" sys.exit() if event.type == pygame.JOYBUTTONDOWN: if event.button == 3: drone.takeoff(); print("Drone taking off.") if event.button == 0: drone.land(); print("Drone landing.") if event.button == 7: drone.update(cmd=movePCMDCmd(True, 0, 0, 50, 0)) print("Drone spinning clockwise.") if event.button == 6: drone.update(cmd=movePCMDCmd(True, 0, 0, -50, 0)) print("Drone spinning counterclockwise.") if event.button == 2: print("Drone ascending.") drone.update(cmd=movePCMDCmd(True, 0, 0, 0, 50)) drone.wait(0.050) if event.button == 1: print("Drone descending.") drone.update(cmd=movePCMDCmd(True, 0, 0, 0, -50)) drone.wait(0.050) # if event.button == 4: # print("Taking picture...") # drone.update(cmd=takePictureCmd())
for i in range(1, 5): cv2.waitKey(1) matcher = Matcher([("fau-logo", "../opencv/templates/fau-logo.png"), ("first-logo", "../opencv/templates/first-logo.jpg"), ("nextera-logo", "../opencv/templates/nextera-energy-logo.jpg"), ("techgarage-logo", "../opencv/templates/techgarage-logo.png") ], min_keypoints_pct_match=10) print("Connecting to drone..") drone = Bebop() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() print("Connected.") for i in xrange(10000): if command is None: drone.update( ); elif command == "TAKEOFF": print("Taking offf.........................") drone.takeoff() command = None elif command == "LAND": print("Landing ...........................") drone.land() command = None print("Battery:", drone.battery)
joystick.get_numhats())) # -------- Main Program Loop ----------- MAX_SPEED = 70 while not done: try: # EVENT PROCESSING STEP for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop executing_command = False userMovement = False drone.update(cmd=moveCameraCmd(0, 0)) if joystick.get_button(0) == 1: executing_command = True # print("Button 0 pressed") drone.update(cmd=moveCameraCmd(-100, 0)) if joystick.get_button(1) == 1: executing_command = True drone.update(cmd=moveCameraCmd(0, 100)) if joystick.get_button(2) == 1: executing_command = True drone.update(cmd=moveCameraCmd(0, -100)) if joystick.get_button(3) == 1:
import cv2 from bebop import Bebop cnt = 0 f = open( "./images/video.h264", "wb" ) def videoCallback( frame, drone, debug=False ): global cnt if isinstance(frame, tuple): print("h.264 frame - (frame# = %s, iframe = %s, size = %s)" % (frame[0], frame[1], len(frame[2]))) f.write(frame[-1]) f.flush() else: cnt = cnt + 1 cv2.imshow("image", frame) cv2.waitKey(10) print("Connecting to drone..") drone = Bebop( metalog=None, onlyIFrames=False, jpegStream=True ) drone.videoCbk = videoCallback drone.videoEnable() print("Connected.") for i in xrange(10000): drone.update()