def main(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) drone.takeoff() sleep(1) drone.take_picture() #drone.clockwise(rad) #drone.land() i = 1 while i <= n: drone.left(X) drone.forward(Y) sleep(3) drone.clockwise(rad) sleep(1) #drone.take_picture() #pic = drone.take_picture() #pic = #pic.show() #pic.save('/Users/user/Desktop/lenna_square_pillow.jpg', quality=95) i = i + 1 drone.land() sleep(1) drone.land() sleep(1) drone.land() sleep(5) except Exception as ex: print(ex) finally: drone.quit()
def main(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) drone.takeoff() #sleep(10) container = av.open(drone.get_video_stream()) start_time = time.time() videoCamera(start_time, container, drone, 5) drone.clockwise(10) sleep(5) start_time = time.time() videoCamera(start_time, container, drone, 5) drone.land() sleep(5) drone.quit() cv2.destroyAllWindows() except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone.quit() cv2.destroyAllWindows()
def __init__(self): self.prev_flight_data = None self.record = False self.tracking = False self.keydown = False self.date_fmt = '%Y-%m-%d_%H%M%S' self.speed = 50 self.drone = tellopy.Tello() self.init_drone() self.init_controls() # container for processing the packets into frames self.container = av.open(self.drone.get_video_stream()) self.vid_stream = self.container.streams.video[0] self.out_file = None self.out_stream = None self.out_name = None self.start_time = time.time() # tracking a color green_lower = (30, 50, 50) green_upper = (80, 255, 255) #red_lower = (0, 50, 50) # red_upper = (20, 255, 255) # blue_lower = (110, 50, 50) # upper_blue = (130, 255, 255) self.track_cmd = "" self.tracker = Tracker(self.vid_stream.height, self.vid_stream.width, green_lower, green_upper)
def test(): drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.connect() drone.wait_for_connection(60.0) drone.takeoff() sleep(5) drone.up(10) sleep(2) drone.up(0) sleep(1) drone.forward(20) sleep(5) drone.forward(0) sleep(1) drone.backward(20) sleep(5) drone.backward(0) sleep(1) drone.land() sleep(5) except Exception as ex: drone.land() #エラーが起きたらその場で緊急着陸 print(ex) finally: drone.quit()
def main(): global container, drone drone = tellopy.Tello() drone.video_encoder_rate = 1 drone.connect() drone.wait_for_connection(60.0) container = av.open(drone.get_video_stream()) drone.subscribe(drone.EVENT_FLIGHT_DATA, flight_data_handler) listener = Listener(on_press=on_press, on_release=on_release) listener.start() try: while True: # loop with pygame.event.get() is too much tight w/o some sleep video_handler() time.sleep(0.01) except KeyboardInterrupt as e: print(e) except Exception as e: print(e) cv2.destroyAllWindows() drone.quit() exit(1)
def main(): drone = None try: drone = tellopy.Tello() print("Battery:", drone.battery()) except Exception as err: print(err) # Commands go here: # Make sure to avoid the obstacles # drone.takeoff() time.sleep(3) #drone.forward(20) #time.sleep(3) #drone.flip('f') #time.sleep(3) drone.cw(90) time.sleep(3) drone.land() time.sleep(3) print("Battery is at:", drone.battery()) print("You have flied for ", drone.flight_time())
def main(): global buttons pygame.init() pygame.joystick.init() try: js = pygame.joystick.Joystick(0) js.init() js_name = js.get_name() buttons = JoystickPS4 except pygame.error: pass drone = tellopy.Tello() drone.connect() try: while 1: # loop with pygame.event.get() is too much tight w/o some sleep time.sleep(0.01) for e in pygame.event.get(): handle_input_event(drone, e) except KeyboardInterrupt as e: print(e) except Exception as e: print(e) drone.quit() exit(1)
def drone_camera(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) retry = 3 container = None while container is None and 0 < retry: retry = retry - 1 try: container = av.open(drone.get_video_stream()) except av.AVError as ave: print(ave) print('retry ...') while True: for frame in container.decode(video=0): image = cv2.cvtColor(np.array(frame.to_image()), cv2.COLOR_RGB2BGR) cv2.imshow('Image', image) cv2.waitKey(1) except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone.quit() cv2.destroyAllWindows()
def Drone(): print('Muse') drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) # unused var unused_addr = 0 args = 0 drone.connect() drone.wait_for_connection(60.0) drone.takeoff() time.sleep(5) drone.forward(40) time.sleep(5) if is_jaw_clench: drone.forward(1) elif LookLeft(): drone.land() elif LookRight(): drone.right(1) except Exception as ex: print(ex) finally: drone.quit()
def flyAndCapture(): drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) # Connect to drone drone.connect() drone.wait_for_connection(60.0) # Start camera feed t1 = threading.Thread(target=cameraCapture, args=(drone, )) t1.start() sleep(15) # Take-off drone.takeoff() print( "motion thr: Inside motion thread, started another thread for camera stuff" ) sleep(5) drone.down(50) print("motion thr: ok") sleep(5) drone.land() print("motion thr: ok") sleep(5) print("motion thr: done") except Exception as ex: print(ex) finally: drone.quit()
def __init__(self): #开始连接飞机 self.drone = tellopy.Tello() try: self.drone.connect() self.drone.set_video_encoder_rate(2) self.drone.start_video() #订阅飞行数据信息 #self.drone.subscribe(self.drone.EVENT_FLIGHT_DATA,self.flight_data_handler) #self.drone.wait_for_connection(60.0) retry = 3 self.container = None #container用于存放帧 while self.container is None and 0 < retry: retry -= 1 try: self.container = av.open(self.drone.get_video_stream()) except av.AVError as ave: print(ave) print('retry...') except: print('ooooooooooooooo') self.frame_skip = 300
def __init__(self): rospy.init_node('tello_action_node', anonymous=False) self.rate = rospy.Rate(1) # Connect to the drone self._drone = tellopy.Tello() self._drone.connect() self._drone.wait_for_connection(60.0) rospy.loginfo('connected to drone') self._drone.takeoff() rospy.on_shutdown(self.shutdown) self._drone.clockwise(360) sleep(5) self._drone.clockwise(0) while not rospy.is_shutdown(): # self._drone.clockwise(360) sleep(5) # self._drone.counter_clockwise(20) # self._drone.up(0) # self._drone.down(0) # self._drone.forward(0) # self._drone.backward(0) # self._drone.left(0) # self._drone.right(0) self.rate.sleep()
def connectDrone2(): global videoPortText global connectionRequestPortText global portText global wifiInterfaceText videoPort = int(videoPortText.get("1.0", END).strip()) port = int(portText.get("1.0", END).strip()) wifiInterface = wifiInterfaceText.get("1.0", END).strip() connectionRequest = int(connectionRequestPortText.get("1.0", END).strip()) print(videoPort) print(port) print(wifiInterface) print(connectionRequest) drone2 = tellopy.Tello(wifiInterface, port, videoPort, connectionRequest) try: drone2.connect() drone2.wait_for_connection(60.0) container2 = av.open(drone2.get_video_stream()) while True: for frame in container2.decode(video=0): image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR) cv2.imshow('Drone', image) cv2.waitKey(1) except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone2.quit() cv2.destroyAllWindows()
def main(): pygame.init() pygame.display.init() pygame.display.set_mode((1280, 720)) pygame.font.init() global font font = pygame.font.SysFont("dejavusansmono", 32) global wid if 'window' in pygame.display.get_wm_info(): wid = pygame.display.get_wm_info()['window'] print("Tello video WID:", wid) drone = tellopy.Tello() drone.connect() drone.wait_for_connection(60.0) drone.start_video() drone.subscribe(drone.EVENT_FLIGHT_DATA, flightDataHandler) drone.subscribe(drone.EVENT_VIDEO_FRAME, videoFrameHandler) drone.subscribe(drone.EVENT_FILE_RECEIVED, handleFileReceived) speed = 30 try: while 1: time.sleep( 0.01 ) # loop with pygame.event.get() is too mush tight w/o some sleep for e in pygame.event.get(): # WASD for movement if e.type == pygame.locals.KEYDOWN: print('+' + pygame.key.name(e.key)) keyname = pygame.key.name(e.key) if keyname == 'escape': drone.quit() exit(0) if keyname in controls: key_handler = controls[keyname] if type(key_handler) == str: getattr(drone, key_handler)(speed) else: key_handler(drone, speed) elif e.type == pygame.locals.KEYUP: print('-' + pygame.key.name(e.key)) keyname = pygame.key.name(e.key) if keyname in controls: key_handler = controls[keyname] if type(key_handler) == str: getattr(drone, key_handler)(0) else: key_handler(drone, 0) except e: print(str(e)) finally: print('Shutting down connection to drone...') if video_recorder: toggle_recording(drone, 1) drone.quit() exit(1)
def rotate_cw(n_rote): drone = tellopy.Tello() secs_per_rotate = 16 flight_time = n_rote * secs_per_rotate try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.connect() drone.wait_for_connection(60.0) drone.takeoff() sleep(5) # drone.up(20) # sleep(2) # drone.up(0) # 定常円旋回は、前進とその場旋回のベクトル和で実現 drone.forward(20) # 前進飛行速度=20cm/s drone.clockwise(36) # 旋回方向と角速度を設定(時計回り, 36deg/s) sleep(flight_time) drone.forward(0) drone.clockwise(0) sleep(1) drone.land() sleep(5) except Exception as ex: drone.land() #エラーが起きたらその場で緊急着陸 print(ex) finally: drone.quit()
def test(): drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) #드론에 연결 drone.connect() drone.wait_for_connection(60.0) #드론이륙 drone.takeoff() #명령을 수행하는데 시간이 걸리기 때문에 딜레이를 추가해줍니다. 3~5초가 적절합니다. sleep(5) #drone_command.txt를 참조하여 적절한 명령을 추가합니다. drone.clockwise(30) sleep(5) drone.flip_left() sleep(5) drone.land() sleep(5) #에러가 발생했을경우 처리하는 에러문구를 출력합니다. except Exception as ex: print(ex) finally: drone.quit()
def test(): drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.connect() drone.wait_for_connection(60.0) drone.takeoff() sleep(4) drone.flip_back() sleep(4) drone.flip_forward() sleep(4) drone.flip_forwardleft() sleep(2) drone.down(50) sleep(3) drone.land() sleep(3) except Exception as ex: print(ex) finally: drone.quit()
def main(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) container = av.open(drone.get_video_stream()) frame_count = 0 while True: for frame in container.decode(video=0): frame_count = frame_count + 1 # skip first 300 frames if frame_count < 300: continue image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR) cv2.imshow('Original', image) cv2.imshow('Canny', cv2.Canny(image, 100, 200)) cv2.waitKey(1) except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone.quit() cv2.destroyAllWindows()
def main(): videostream = io.BytesIO() videostream.seek(0) drone = tellopy.Tello() drone.log.set_level(2) drone.connect() drone.start_video() drone.subscribe(drone.EVENT_VIDEO_FRAME, videoFrameHandler) # in_container = av.open(drone.get_video_stream()) out_container = av.open('tmp.mp4', mode='w') # in tello.py it is set to 0x20 out_stream = out_container.add_stream('mpeg4', rate=32) while True: for packet in in_container.demux((in_container.streams.video[0], )): for frame in packet.decode(): image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR) print("image", type(image)) cv2.imshow('frame', image) if cv2.waitKey(20) & 0xFF == ord('q'): break print(len(videostream))
def setup(self, *args, **kwargs): self.drone = tellopy.Tello() self.drone.connect() self.drone.wait_for_connection(60.0) self.stream = av.open(self.drone.get_video_stream()).decode(video=0) for i in range(300): _ = next(self.stream)
def __init__(self): rospy.init_node('tello_driver_node', anonymous=False) # ROS publishers self._flight_data_pub = rospy.Publisher('tello/flight_data', FlightData, queue_size=10) self._image_pub = rospy.Publisher('tello/image_raw', Image, queue_size=10) self._cv_bridge = CvBridge() # Connect to the drone self._drone = tellopy.Tello() self._drone.connect() self._drone.wait_for_connection(60.0) rospy.loginfo('connected to drone') # Listen to flight data messages self._drone.subscribe(self._drone.EVENT_FLIGHT_DATA, self.flight_data_callback) # Start video thread self._stop_request = threading.Event() video_thread = threading.Thread(target=self.video_worker) video_thread.start() rospy.spin() rospy.on_shutdown(self.shutdown)
def main(): global buttons pygame.init() pygame.joystick.init() try: js = pygame.joystick.Joystick(0) js.init() js_name = js.get_name() print('Joystick name: ' + js_name) buttons = JoystickPS4 except pygame.error: pass drone = tellopy.Tello() drone.connect() drone.start_video() drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.subscribe(drone.EVENT_VIDEO_FRAME, handler) try: while 1: # loop with pygame.event.get() is too much tight w/o some sleep time.sleep(0.01) for e in pygame.event.get(): handle_input_event(drone, e) except KeyboardInterrupt as e: print(e) except Exception as e: print(e) drone.quit() exit(1)
def __init__(self): print("Connecting to Airsim Client: ") self.client = airsim.CarClient() self.client.confirmConnection() print("Connection confirmed, Enabling Car controls ") self.client.enableApiControl(True) self.car_controls= airsim.CarControls() print("Car Controls enabled, Please enter Command parameters ") self.car_state=self.client.getCarState() self.mode = bool(input("Input car Mode: True (distance commands) " or "False")) if(self.mode): print("Going to Distance mode! ") pass else: self.repeat= int(input("How many repeats? " or "3")) self.record= bool(input("Record Images? " or "False")) self.fold= os.getcwd()+'/pictures3/' self.projectionMatrix = np.array([[1, 0.000000000, 0.000000000, -127.5000000000], [0.000000000, 1, 0.000000000, -71.5000000000], [0.000000000, 0.000000000, 1.00000000, 127.5 ], [0.000000000, 0.000000000, -1/20.0000000, 0.000000000]]) color = (0,255,0) self.rgb = "%d %d %d" % color ## Control Tello self.drone = tellopy.Tello() try: self.drone.subscribe(drone.EVENT_FLIGHT_DATA,handler) self.drone.connect() drone.wait_for_connection(60.0)
def __init__(self): self.prev_flight_data = None self.record = False self.tracking = False self.keydown = False self.date_fmt = '%Y-%m-%d_%H%M%S' self.speed = 50 self.prev_tracking="tr_off" self.drone = tellopy.Tello() self.init_drone() self.init_controls() self.prev_tracking=0 # container for processing the packets into frames self.container = av.open(self.drone.get_video_stream()) self.vid_stream = self.container.streams.video[0] self.out_stream_writer=None self.out_file = None self.out_stream = None self.out_name = None self.start_time = time.time() self.use_openpose=False self.op = OP(number_people_max=5, min_size=10, debug=None) self.fps = FPS()
def main(): drone = tellopy.Tello() try: drone.connect() drone.wait_for_connection(60.0) container = av.open(drone.get_video_stream()) # skip first 300 frames frame_skip = 300 while True: for frame in container.decode(video=0): if 0 < frame_skip: frame_skip = frame_skip - 1 continue start_time = time.time() image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR) cv2.imshow('Original', image) cv2.imshow('Canny', cv2.Canny(image, 100, 200)) cv2.waitKey(1) if frame.time_base < 1.0 / 60: time_base = 1.0 / 60 else: time_base = frame.time_base frame_skip = int((time.time() - start_time) / time_base) except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) print(ex) finally: drone.quit() cv2.destroyAllWindows()
def test(): drone = tellopy.Tello() try: # drone.set_loglevel(d.LOG_ALL) drone.subscribe(drone.CONNECTED_EVENT, handler) # drone.subscribe(drone.WIFI_EVENT, handler) # drone.subscribe(drone.LIGHT_EVENT, handler) drone.subscribe(drone.FLIGHT_EVENT, handler) # drone.subscribe(drone.LOG_EVENT, handler) drone.subscribe(drone.TIME_EVENT, handler) drone.subscribe(drone.VIDEO_FRAME_EVENT, handler) drone.connect() # drone.takeoff() # time.sleep(5) drone.down(50) sleep(3) drone.up(50) sleep(3) drone.down(0) sleep(2) drone.land() sleep(5) except Exception, ex: print ex show_exception(ex)
def test(): drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.subscribe(drone.EVENT_LOG_DATA, handler) drone.record_log_data() drone.connect() drone.wait_for_connection(60.0) drone.takeoff() sleep(5) drone.clockwise(100) sleep(5) drone.clockwise(0) drone.down(50) sleep(2) drone.up(50) sleep(2) drone.up(0) drone.land() sleep(5) except Exception as ex: print(ex) finally: drone.quit()
def __init__(self, commands): self.tello = tellopy.Tello() self.commands = commands self.activity = { 'takeoff': self.tello.takeoff, 'land': self.tello.land }
def test(): input = ser.readline()[0] drone = tellopy.Tello() try: drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) drone.connect() drone.wait_for_connection(60.0) # drone.takeoff() drone.land() # sleep(30) print("BYE") #drone.down(50) #sleep(5) #drone.land() #sleep(5) except Exception as ex: print(ex) drone.quit finally: #drone.quit() if input == 48: # right drone.right(50) elif input == 49: #up drone.left(50) elif input == 51: #down drone.down(50) elif input == 54: #left drone.left(50) elif input == 57: #select drone.land()
def test(): drone = tellopy.Tello() try: # drone.set_loglevel(d.LOG_ALL) drone.subscribe(drone.EVENT_CONNECTED, handler) # drone.subscribe(drone.EVENT_WIFI, handler) # drone.subscribe(drone.EVENT_LIGHT, handler) drone.subscribe(drone.EVENT_FLIGHT_DATA, handler) # drone.subscribe(drone.EVENT_LOG, handler) drone.subscribe(drone.EVENT_TIME, handler) drone.subscribe(drone.EVENT_VIDEO_FRAME, handler) drone.connect() # drone.takeoff() # time.sleep(5) drone.down(50) sleep(3) drone.up(50) sleep(3) drone.down(0) sleep(2) drone.land() sleep(5) except Exception as ex: print(ex) show_exception(ex) finally: drone.quit() print('end.')