def __init__(self, test_flying, mambo_addr, use_wifi=True, use_vision=True): """ Constructor for the Drone Superclass. When writing your code, you may redefine __init__() to have additional attributes for use in processing elsewhere. If you do this, be sure to call super().__init__() with relevant args in order properly initialize all mambo-related things. test_flying: bool : run flight code if True mambo_addr: str : BLE address of drone use_wifi: bool : connect with WiFi instead of BLE if True use_vision: bool : turn on DroneVisionGUI module if True """ self.test_flying = test_flying self.use_wifi = use_wifi self.use_vision = use_vision self.mamboAddr = mambo_addr self.mambo = Mambo(self.mamboAddr, use_wifi=self.use_wifi) self.mambo.set_user_sensor_callback(self.sensor_cb, args=None) if self.use_vision: self.mamboVision = DroneVisionGUI( self.mambo, is_bebop=False, buffer_size=200, user_code_to_run=self.flight_func, user_args=None) self.mamboVision.set_user_callback_function( self.vision_cb, user_callback_args=None)
def execute(self): super().takeoff() mamboVision = DroneVisionGUI(self.mambo, is_bebop=False, buffer_size=200, user_code_to_run=DemoSquare.pint, user_args=(self.mambo, )) mamboVision.open_video() print('opened video') super().land()
def __init__(self, testFlying, mamboAddr, use_wifi): self.bb = [0, 0, 0, 0] self.bb_threshold = 4000 self.bb_trigger = False self.testFlying = testFlying self.mamboAddr = mamboAddr self.use_wifi = use_wifi self.mambo = Mambo(self.mamboAddr, self.use_wifi) self.mamboVision = DroneVisionGUI( self.mambo, is_bebop=False, buffer_size=200, user_code_to_run=self.mambo_fly_function, user_args=None)
bebop.pan_tilt_camera_velocity(pan_velocity=0, tilt_velocity=-2, duration=4) # land bebop.safe_land(5) print("Finishing demo and stopping vision") bebopVision.close_video() # disconnect nicely so we don't need a reboot print("disconnecting") bebop.disconnect() if __name__ == "__main__": # make my bebop object bebop = Bebop() # connect to the bebop success = bebop.connect(5) if (success): # start up the video bebopVision = DroneVisionGUI(bebop, is_bebop=True, user_code_to_run=demo_user_code_after_vision_opened, user_args=(bebop,)) userVision = UserVision(bebopVision) bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None) bebopVision.open_video() else: print("Error connecting to bebop. Retry")
# remember to set True/False for the wifi depending on if you are using the wifi or the BLE to connect # the address can be empty if you are using wifi mambo = Bebop() print("trying to connect to mambo now") success = mambo.connect(num_retries=3) print("connected: %s" % success) if (success): # get the state information print("sleeping") mambo.smart_sleep(1) mambo.ask_for_state_update() mambo.smart_sleep(1) # setup the extra window to draw the markers in cv2.namedWindow("ExampleWindow") cv2.namedWindow("dst") print("Preparing to open vision") mambo.pan_tilt_camera_velocity(-90, 0, 1) mamboVision = DroneVisionGUI( mambo, is_bebop=True, buffer_size=200, user_code_to_run=demo_mambo_user_vision_function, user_args=(mambo, )) mamboVision.set_user_callback_function( draw_second_pictures, user_callback_args=(mamboVision, )) mamboVision.open_video()
print("disconnecting") mambo.disconnect() if __name__ == "__main__": # make my mambo object # remember to set True/False for the wifi depending on if you are using the wifi or the BLE to connect # the address can be empty if you are using wifi mambo = Mambo(address="", use_wifi=True) print("trying to connect to mambo now") success = mambo.connect(num_retries=3) print("connected: %s" % success) if (success): # get the state information print("sleeping") mambo.smart_sleep(1) mambo.ask_for_state_update() mambo.smart_sleep(1) # setup the extra window to draw the markers in cv2.namedWindow("ExampleWindow") print("Preparing to open vision") mamboVision = DroneVisionGUI(mambo, Model.MAMBO, buffer_size=200, user_code_to_run=demo_mambo_user_vision_function, user_args=(mambo, )) mamboVision.set_user_callback_function(draw_second_pictures, user_callback_args=(mamboVision, )) mamboVision.open_video()
while bebop_vision.vision_running: img = bebop_vision.get_latest_valid_picture() if img is not None: instruction = qr_manager.read_qr_code(img) if instruction is not None: if instruction == "take_off": bebop.safe_takeoff(5) elif instruction == "land": bebop.safe_land(5) bebop_vision.close_video() elif instruction in instructions: values = instructions[instruction] bebop.move_relative(values[0], values[1], values[2], values[3]) bebop.disconnect() if __name__ == "__main__": BEBOP = Bebop(drone_type="Bebop") SUCCESS = BEBOP.connect(20) INSTRUCTIONS = file_manager.get_navigation_instructions() if SUCCESS: BEBOP_VISION = DroneVisionGUI( BEBOP, is_bebop=True, user_code_to_run=demo_user_code_after_vision_opened, user_args=(BEBOP, INSTRUCTIONS)) BEBOP_VISION.open_video() else: print("Error connecting to bebop. Retry")
drone = Bebop() success = drone.connect(5) drone.set_picture_format('jpeg') # 영상 포맷 변경 is_bebop = True height = 480 width = 856 elif drone_type == 'm': mamboAddr = "58:FB:84:3B:12:62" drone = Mambo(mamboAddr, use_wifi=True) success = drone.connect(num_retries=3) is_bebop = False height = 360 width = 640 # drone.set_max_tilt() if (success): # get the state information print("sleeping") drone.smart_sleep(1) drone.ask_for_state_update() drone.smart_sleep(1) print("Preparing to open vision") status = input("Input 't' if you want to TAKE-OFF or not : ") droneVision = DroneVisionGUI(drone, is_bebop=is_bebop, buffer_size=200, user_code_to_run=control_and_collect, user_args=(drone, status, height, width, num_classes)) userVision = UserVision(droneVision) # droneVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None) droneVision.open_video()
bebopVision.close_video() # disconnect nicely so we don't need a reboot print("disconnecting") bebop.disconnect() if __name__ == "__main__": # make my bebop object bebop = Bebop() # connect to the bebop success = bebop.connect(5) if (success): # start up the video bebopVision = DroneVisionGUI( bebop, Model.BEBOP, user_code_to_run=demo_user_code_after_vision_opened, user_args=(bebop, ), user_draw_window_fn=draw_current_photo) userVision = UserVision(bebopVision) bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None) bebopVision.open_video() else: print("Error connecting to bebop. Retry")
print("Disconnecting Anafi") anafi.disconnect() if __name__ == "__main__": anafi = Anafi() print("Connecting to Anafi...") if anafi.connect(num_retries=3): print("Connected to Anafi") # Update state info anafi.smart_sleep(1) anafi.ask_for_state_update() anafi.smart_sleep(1) print("Preparing to open video stream") anafi_vision = DroneVisionGUI( anafi, Model.ANAFI, buffer_size=200, user_code_to_run=demo_anafi_user_vision, user_args=(anafi, ), ) user_vision = UserVision(anafi_vision) anafi_vision.set_user_callback_function(user_vision.save_pictures, user_callback_args=None) print("Opening video stream") anafi_vision.open_video()
vision = threading.Thread(target=qr_tracking, args=(bebopVision, bebop), daemon=True) vision.start() vision.join() print("Stopping!") bebopVision.close_exit() # disconnect nicely so we don't need a reboot print("disconnecting") bebop.disconnect() if __name__ == "__main__": # make my bebop object bebop = Bebop() print("Battery level:"+str(bebop.sensors.battery)) # connect to the bebop success = bebop.connect(5) if success: # start up the video bebopVision = DroneVisionGUI(bebop, is_bebop=True, user_code_to_run=user_code, user_args=(bebop, )) userVision = UserVision(bebopVision) bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None) bebopVision.open_video() else: print("Error connecting to bebop. Retry")
bebop.smart_sleep(1) with concurrent.futures.ThreadPoolExecutor() as executor: #ne sort pas du contexte manager tant que tout les programmes n' ont pas fini. thread_1 = executor.submit(controles) thread_2 = executor.submit(depth_display) position = thread_1.result() bebop.smart_sleep(3) if bebop.safe_land(5): #n' enleve le controle à l'utilisateur que si le drone a bien atteri. pygame.quit() vc.release() bebop.disconnect() ############# MAIN if __name__ == "__main__": global bebop bebop = Bebop() success = bebop.connect(5) if (success): bebop.set_video_framerate("24_FPS") bebop.set_video_resolutions("rec720_stream720") bebop.set_video_stream_mode("high_reliability_low_framerate") bebopVision = DroneVisionGUI(bebop, is_bebop=True, user_code_to_run = vol_final, user_args=(bebop, ), user_draw_window_fn=draw_current_photo) userVision = UserVision(bebopVision) bebopVision.open_video() else: print("Error connecting to bebop. Retry")
drone = Bebop() success = drone.connect(5) drone.set_picture_format('jpeg') # 영상 포맷 변경 is_bebop = True elif drone_type == 'm': mamboAddr = "64:E5:99:F7:22:4A" drone = Mambo(mamboAddr, use_wifi=True) success = drone.connect(num_retries=3) is_bebop = False if (success): # get the state information print("sleeping") drone.smart_sleep(1) drone.ask_for_state_update() drone.smart_sleep(1) print("Preparing to open vision") status = input("Input 't' if you want to TAKE OFF or not : ") droneVision = DroneVisionGUI(drone, is_bebop=is_bebop, buffer_size=200, user_code_to_run=tracking_target, user_args=(drone, status, q)) yolnir = Yolnir(droneVision) droneVision.set_user_callback_function(yolnir.detect_target, user_callback_args=None) droneVision.open_video()
bebop.safe_land(10) ########################################################## bebop.safe_land(10) print("disconnecting") bebop.disconnect() if __name__ == "__main__": # make my bebop object bebop = Bebop() # connect to the bebop success = bebop.connect(5) if (success): # start up the video bebopVision = DroneVisionGUI( bebop, is_bebop=True, user_code_to_run=demo_user_code_after_vision_opened, user_args=(bebop, ), user_draw_window_fn=None) userVision = UserVision(bebopVision) bebopVision.set_user_callback_function(userVision.save_pictures, user_callback_args=None) bebopVision.open_video() else: print("Error connecting to bebop. Retry")