def __init__(self): super().__init__() # Dronen skal være en tråd, så de ikke hænger i beregninger til reporter self.bebop = Bebop() self.yaw_altitude_damper = 0.30 self._movement_vector = Vector() self.voice = Voice() self.flight = Flight(self.bebop) self.threads = [ self.voice, self.flight ] try: self.device = Devices().get_device() except ControllerNotFound: self.voice.force_pronounce('Unable to connect to controller.') exit(0) self.device.method_listener(self.take_off_landing, 'START') self.device.method_listener(self.pitch, 'LEFT_STICK') self.device.method_listener(self.roll, 'LEFT_STICK') self.device.method_listener(self.yaw, 'RIGHT_STICK') self.device.method_listener(self.altitude, 'RIGHT_STICK') self.device.method_listener(self.left_bumper, 'LEFT_BUMPER') self.device.method_listener(self.right_bumper, 'RIGHT_BUMPER') self.device.method_listener(self.change_profile, 'SELECT', self.device.Handler.single) self.device.method_listener(self.do_flat_trim, 'A', self.device.Handler.single) self.device.method_listener(self.change_geofence, 'Y', self.device.Handler.single) self.device.abort_function(self.abort) self.default_profile = 'Default' self.profiles = [] self.profile_idx = 0 self.load_profiles() self.profile_idx = self.get_default_profile() self.running = True self.debug = False self.debug_count = 0 self.debug_button = False self.block_print()
def video2stdout(): drone = Bebop( metalog=None, onlyIFrames=False ) drone.videoCbk = videoCallback drone.videoEnable() while True: drone.update()
def clip(value, low, high): if value < low: return low if value > high: return high return value # Video variables f = open("./images/video.h264", "wb") cnt = 0 frames = 0 lastFrames = 0 print("Connecting to drone...") drone = Bebop() drone.trim() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() drone.minEdgeVal = 30 drone.maxEdgeVal = 50 print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False
def video_start(): print("Starting video...") cv2.namedWindow("Drone") def video_end(): print("Ending video...") cv2.destroyWindow("Drone") # 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() drone.moveCamera(-90, 0) print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
color = (0, 0, 255) text = "Go Right" elif center_x - width * 0.5 < 50: color = (255, 0, 0) text = "Go Left" cv2.line(frame, barcode.location[0], barcode.location[1], color=color, thickness=2) cv2.line(frame, barcode.location[1], barcode.location[2], color=color, thickness=2) cv2.line(frame, barcode.location[2], barcode.location[3], color=color, thickness=2) cv2.line(frame, barcode.location[0], barcode.location[3], color=color, thickness=2) cv2.circle(frame, (center_x, center_y), 3, color=color, thickness=2) cv2.putText(frame, org=(width - 100, height - 100), text=text, color=color, fontFace=cv2.FONT_HERSHEY_PLAIN, fontScale=1,) break cv2.imshow("Drone feed", frame) cv2.waitKey(10) print("Connecting to drone..") drone = Bebop( metalog=None, onlyIFrames=False, jpegStream=True, fps = 0) drone.videoCbk = videoCallback drone.videoEnable() drone.moveCamera(-90, 0) print("Connected.") for i in xrange(10000): drone.update( ); print("Battery:", drone.battery)
g_queueOut = Queue() g_processor = Process(target=processMain, args=(g_queueOut, )) g_processor.daemon = True g_processor.start() g_queueOut.put_nowait(frame) # H264 compressed video frame def testCVideo(drone): drone.videoCbk = videoCallback drone.videoEnable() for i in xrange(400): drone.update() if g_queueOut is not None: g_queueOut.put_nowait(None) g_processor.join() if __name__ == "__main__": if len(sys.argv) < 2: print __doc__ sys.exit(2) metalog = None if len(sys.argv) > 2: metalog = MetaLog(filename=sys.argv[2]) if len(sys.argv) > 3 and sys.argv[3] == 'F': disableAsserts() drone = Bebop(metalog=metalog, onlyIFrames=False) testCVideo(drone) # vim: expandtab sw=4 ts=4
from bebop import Bebop import logging logging.basicConfig() print("Connecting to drone...") drone = Bebop(loggingLevel=logging.DEBUG) print("Connected.") drone.wait(5)
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()
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(5) drone.land()
import cv2 import time import sys import signal from bebop import Bebop drone = Bebop() def main(): signal.signal(signal.SIGINT, signal_handler) try: drone.moveCamera(tilt=-50, pan=0) drone.videoEnable() cap = cv2.VideoCapture('./bebop.sdp') while (True): ret, img = cap.read() if ret: cv2.imshow('img', img) cv2.namedWindow('img', cv2.WINDOW_NORMAL) cv2.waitKey(1) drone.update() sys.exit(0) except (TypeError) as e: pass
def scale(value, scaler): if abs(value) < 0.05: return 0 return value * scaler from bebop import Bebop from commands import * import pygame import cv2 cnt = 0 f = open( "./images/video.h264", "wb" ) print("Connecting to drone...") drone = Bebop( metalog=None, onlyIFrames=True) drone.trim() drone.videoCbk = videoCallback drone.videoEnable() print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
def clip(value, low, high): if value < low: return low if value > high: return high return value # Video variables f = open( "./images/video.h264", "wb" ) cnt = 0 frames = 0 lastFrames = 0 print("Connecting to drone...") drone = Bebop( metalog=None, onlyIFrames=True, jpegStream=True) drone.trim() drone.videoCbk = videoCallback drone.videoEnable() drone.minEdgeVal = 50 drone.maxEdgeVal = 70 print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False
import pygame import sys from commands import * from bebop import Bebop drive_speed = 50 turn_speed = 50 print ("Connecting to drone..."); metalog=None drone = Bebop( metalog=metalog, onlyIFrames=True ) drone.trim() print ("Connected."); drive_speed = 50 turn_speed = 50 pygame.init() pygame.display.set_mode((100, 100)) pygame.key.set_repeat(50) pygame.joystick.init() my_joystick = pygame.joystick.Joystick(0) my_joystick.init() while True: for event in pygame.event.get(): #leftPower = 0 #rightPower = 0
cv2.line(frame, barcode.location[0], barcode.location[3], color=color, thickness=2) cv2.circle(frame, (center_x, center_y), 3, color=color, thickness=2) cv2.putText(frame, org=(width - 100, height - 100), text=text, color=color, fontFace=cv2.FONT_HERSHEY_PLAIN, fontScale=1, ) if barcode.value == "TechGarage": drone.update(cmd=movePCMDCmd(True, 0, 0, 0, 0)) drone.land() break cv2.imshow("Drone feed", frame) cv2.waitKey(10) print("Connecting to drone..") drone = Bebop( metalog=None, onlyIFrames=False, jpegStream=True, fps = 30 ) drone.videoCbk = videoCallback drone.videoEnable() drone.moveCamera(-90, 0) print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
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()
def video_start(): print("Starting video...") cv2.namedWindow("Drone") def video_end(): print("Ending video...") cv2.destroyWindow("Drone") # 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.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
def video2stdout(): drone = Bebop(metalog=None, onlyIFrames=False) drone.videoCbk = videoCallback drone.videoEnable() while True: drone.update()
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.land()
class DroneBinding(Logging): def __init__(self): super().__init__() # Dronen skal være en tråd, så de ikke hænger i beregninger til reporter self.bebop = Bebop() self.yaw_altitude_damper = 0.30 self._movement_vector = Vector() self.voice = Voice() self.flight = Flight(self.bebop) self.threads = [ self.voice, self.flight ] try: self.device = Devices().get_device() except ControllerNotFound: self.voice.force_pronounce('Unable to connect to controller.') exit(0) self.device.method_listener(self.take_off_landing, 'START') self.device.method_listener(self.pitch, 'LEFT_STICK') self.device.method_listener(self.roll, 'LEFT_STICK') self.device.method_listener(self.yaw, 'RIGHT_STICK') self.device.method_listener(self.altitude, 'RIGHT_STICK') self.device.method_listener(self.left_bumper, 'LEFT_BUMPER') self.device.method_listener(self.right_bumper, 'RIGHT_BUMPER') self.device.method_listener(self.change_profile, 'SELECT', self.device.Handler.single) self.device.method_listener(self.do_flat_trim, 'A', self.device.Handler.single) self.device.method_listener(self.change_geofence, 'Y', self.device.Handler.single) self.device.abort_function(self.abort) self.default_profile = 'Default' self.profiles = [] self.profile_idx = 0 self.load_profiles() self.profile_idx = self.get_default_profile() self.running = True self.debug = False self.debug_count = 0 self.debug_button = False self.block_print() @staticmethod def block_print(): system.stdout = open(os.devnull, 'w') def load_profiles(self): files = glob.glob('./profiles/*.json') for file in files: with open(file, 'r') as f: self.profiles.append( json.loads(f.read()) ) def get_default_profile(self): for idx, p in enumerate(self.profiles): if p.get('name') == self.default_profile: return idx return 0 def load_profile(self, idx): profile = self.profiles[idx] self.log.info(f"Loading profile: {profile.get('name')}") for k, v in profile.items(): if k[0:3] == 'max': self.bebop.set_setting(k, v) return profile.get('name') def start(self): try: if self.bebop.connect(5): self.bebop.ask_for_state_update() self.voice.force_pronounce("Successfully connected to the drone") self.device.start() for thread in self.threads: thread.start() getLogger('XboxController').setLevel(logging.INFO) getLogger('XboxEliteController').setLevel(logging.INFO) else: self.voice.force_pronounce("Could not connect to drone") self.log.error("Could not connect to drone") exit(1) except ConnectionRefusedError: self.voice.force_pronounce("The drone did actively refuse the connection") self.log.error("The drone did actively refuse the connection") exit(1) def take_off_landing(self, args): if args and self.bebop.is_landed(): self.voice.pronounce('Take off sequence has been initiated.') self.flight.fly(self.bebop, self._movement_vector) self.bebop.safe_takeoff(5) elif args and self.bebop.is_flying(): self.voice.pronounce('Landing sequence has been initiated.') self._movement_vector.reset() self.flight.join() self.bebop.safe_land(5) # self.bebop.force_state_update(self.bebop.states.landed) def pitch(self, args): self._movement_vector.set_pitch(args[1]) def roll(self, args): self._movement_vector.set_roll(args[0]) @property def yaw_altitude_damper_converter(self): return 1 + (1 - self.yaw_altitude_damper) def altitude(self, args): yaw = abs(args[0]) altitude = abs(args[1]) if yaw > altitude * self.yaw_altitude_damper_converter: self._movement_vector.set_vertical_movement(0) else: self._movement_vector.set_vertical_movement(args[1]) def yaw(self, args): yaw = abs(args[0]) altitude = abs(args[1]) if altitude > yaw * self.yaw_altitude_damper_converter: self._movement_vector.set_yaw(0) else: self._movement_vector.set_yaw(args[0]) def do_flat_trim(self, args): if args and self.bebop.is_landed(): self.voice.pronounce('Executing flat trim.') self.bebop.flat_trim(2) def change_profile(self, args): if args and self.bebop.is_landed(): self.voice.pronounce(f'Loading new profile') self.profile_idx = (self.profile_idx + 1) % len(self.profiles) profile = self.load_profile(self.profile_idx) self.voice.pronounce(f'Changeing to profile {profile}') def change_geofence(self, args): if args: fence = self.bebop.toggle_fence() status = 'on' if fence else 'off' self.voice.pronounce(f'Drone geofenceing has now been turned {status}') def abort(self): self.voice.pronounce('The emergency protocol has been initiated.') self._movement_vector.reset() self.bebop.emergency_land() self.bebop.disconnect() for thread in self.threads: thread.join() def left_bumper(self, args): if args: self._movement_vector.set_yaw(-1) else: self._movement_vector.set_yaw(0) def right_bumper(self, args): if args: self._movement_vector.set_yaw(1) else: self._movement_vector.set_yaw(0)
ret, image = cap.read() index += 1 else: key = cv2.waitKey(0) if __name__ == "__main__": if len(sys.argv) < 2: print __doc__ sys.exit(2) if sys.argv[1] == "--test": filename = sys.argv[2] stopAt = None if len(sys.argv) > 3: stopAt = int(sys.argv[3]) replayVideoStream(filename=filename, stopAt=stopAt) sys.exit(0) metalog = None if len(sys.argv) > 2: metalog = MetaLog(filename=sys.argv[2]) if len(sys.argv) > 3 and sys.argv[3] == 'F': disableAsserts() drone = Bebop(metalog=metalog, onlyIFrames=True) # testCamera( drone ) testAutomaticLanding(drone) print "Battery:", drone.battery, "(%.2f, %.2f, %.2f)" % drone.position # vim: expandtab sw=4 ts=4
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.land()
def video_end(): print("Ending video...") cv2.destroyWindow("Drone") # Have to send waitKey several times on Unix to make window disappear for i in range(1, 5): cv2.waitKey(1) def scale(value, scaler): if abs(value) < 0.03: return 0 return value * scaler print("Connecting to drone..") drone = Bebop() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
def scale(value, scaler): if abs(value) < 0.03: return 0 return value * scaler def clip(value, low, high): if value < low: return low if value > high: return high return value print("Connecting to drone..") drone = Bebop() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() print("Connected.") print("Battery:", drone.battery) pygame.init() size = [100, 100] pygame.display.set_caption("Drone Teleop") # -------- Main Program Loop ----------- # drone.flyToAltitude(2.25) MAX_SPEED = 40 # drone.moveScaler = .25
else: return value cnt = 0 frames = 0 lastFrames = 0 # Video variables f = open( "./images/video.h264", "wb" ) decoder = Decoder() face_cascade = cv2.CascadeClassifier('cascades/haarcascade_frontalface_default.xml') current_milli_time = lambda: int(round(time.time() * 1000)) print("Connecting to drone...") drone = Bebop( metalog=None, onlyIFrames=True, jpegStream=True) drone.trim() drone.videoCbk = videoCallback drone.videoEnable() print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock()
import pygame import cv2 from commands import * from bebop import Bebop def videoCallback( frame, drone, debug=False ): 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.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() if pygame.joystick.get_count() == 0: print("No joysticks found") done = True else: joystick = pygame.joystick.Joystick(0)
drone.trim() drone.takeoff() # drone.flyToAltitude( 1.5 ) # for i in xrange(1000): # print i, # drone.update( cmd=None ) drone.land() except ManualControlException, e: print print "ManualControlException" if drone.flyingState is None or drone.flyingState == 1: # taking off drone.emergency() drone.land() if __name__ == "__main__": if len(sys.argv) < 2: print __doc__ sys.exit(2) metalog = None if len(sys.argv) > 2: metalog = MetaLog(filename=sys.argv[2]) if len(sys.argv) > 3 and sys.argv[3] == 'F': disableAsserts() drone = Bebop(metalog=metalog) demo(drone) print "Battery:", drone.battery # vim: expandtab sw=4 ts=4
elif template_that_matches == "first-logo": command = "LAND" cv2.waitKey(10) 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( metalog=None, onlyIFrames=False, jpegStream=True ) drone.videoCbk = videoCallback 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
# 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)
import pygame import sys from commands import * from bebop import Bebop print("Connecting to drone...") drone = Bebop() drone.trim() print("Connected.") drone.takeoff() drone.wait(5) drone.update(cmd=movePCMDCmd(True, 0, 0, -50, 0)) drone.wait(3) drone.land()
def video_end(): print("Ending video...") cv2.destroyWindow("Drone") # Have to send waitKey several times on Unix to make window disappear 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
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()
#!/usr/bin/env python from bebop import Bebop if __name__ == '__main__': drone = Bebop(debug=False) while True: drone.takeoff() while not drone.done: drone.move() drone.land() raw_input("Press enter to race again")
import datetime from bebop import Bebop from commands import movePCMDCmd from capdet import detectTwoColors, loadColors # this will be in new separate repository as common library fo robotika Python-powered robots from apyros.metalog import MetaLog, disableAsserts from apyros.manual import myKbhit, ManualControlException if __name__ == "__main__": dPsi = math.pi # 0 rad # print "drone.trim()" # print "drone.takeoff()" # print "drone.flyToAltitude( 1.5 )" drone = Bebop() drone.trim() # drone.videoDisable() drone.takeoff() time.sleep(3) print "Take Off Successfull" # drone.hover() # print("Flying To Altitude Of " + str(2)) # drone.flyToAltitude(2, timeout=20, speed=100) # time.sleep(5) # # print "Battery:", drone.battery drone.takePicture() print "Picture Taken." print "Rotating by " + str(dPsi)