def __init__(self, type, connection_type=ConnectionType.WIFI_DIRECT): #self.connection = robot_connection.RobotConnection() self.connection = type self.connection_type = connection_type self.video_decoder = libh264decoder.H264Decoder() libh264decoder.disable_logging() self.audio_decoder = opus_decoder.opus_decoder() self.video_decoder_thread = threading.Thread( target=self._video_decoder_task) self.video_decoder_msg_queue = queue.Queue(64) self.video_display_thread = threading.Thread( target=self._video_display_task) self.video_read_thread = threading.Thread(target=self._video_read_task) self.video_track_thread = threading.Thread( target=self._video_track_task) self.audio_decoder_thread = threading.Thread( target=self._audio_decoder_task) self.audio_decoder_msg_queue = queue.Queue(32) self.audio_display_thread = threading.Thread( target=self._audio_display_task) self.command_ack_list = [] self.is_shutdown = False #默认连接上去了 self.image = np.zeros((1280, 680, 3), np.uint8)
def __init__(self, connection_type): self.connection = robot_connection.RobotConnection() self.connection_type = connection_type self.video_decoder = libh264decoder.H264Decoder() libh264decoder.disable_logging() self.video_decoder_thread = threading.Thread(target=self._video_decoder_task) self.video_decoder_msg_queue = queue.Queue(64) self.video_display_thread = threading.Thread(target=self._video_display_task) self.command_ack_list = [] self.is_shutdown = True self.state = 0 self.angles = ['20', '-20'] self._threat_json = [ { 'msg': 'threat detected!', 'position': [0, 0] }, { 'msg': 'No threat!', 'position': [0, 0] } ] self.api_json = self._threat_json[self.state]
def __init__(self, ip='0.0.0.0', port=11111): # socket settings for the video stream self.socket_video = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket_video.bind(('0.0.0.0', 11111)) libh264decoder.disable_logging() self.decoder = libh264decoder.H264Decoder() self.frame = None # current video frame stored as a numpy array of RGB self.capturing = True self.thread_video = threading.Thread(target=self.recv_video) self.thread_video.daemon = True self.thread_video.start()
def __init__(self, connection_type): self.connection = robot_connection.RobotConnection() self.connection_type = connection_type self.video_decoder = libh264decoder.H264Decoder() libh264decoder.disable_logging() self.audio_decoder = opus_decoder.opus_decoder() self.video_decoder_thread = threading.Thread(target=self._video_decoder_task) self.video_decoder_msg_queue = queue.Queue(64) self.video_display_thread = threading.Thread(target=self._video_display_task) self.audio_decoder_thread = threading.Thread(target=self._audio_decoder_task) self.audio_decoder_msg_queue = queue.Queue(32) self.audio_display_thread = threading.Thread(target=self._audio_display_task) self.command_ack_list = [] self.is_shutdown = True
def __init__(self,tello_ip,command_port=8889,video_port=11111,telem_port=8890,interface=None): self.tello_ip = tello_ip self.command_port = command_port self.video_port = video_port self.telem_port = telem_port self.interface = interface self.command_sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) self.video_sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) self.telem_sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) if self.interface: self.command_sock.setsockopt(socket.SOL_SOCKET, 25,self.interface.encode()) self.video_sock.setsockopt(socket.SOL_SOCKET, 25,self.interface.encode()) self.telem_sock.setsockopt(socket.SOL_SOCKET, 25,self.interface.encode()) self.command_sock.bind(('0.0.0.0', self.command_port)) self.command_sock.setblocking(False) self.command_sock.settimeout(10) self.sock_process_thread = threading.Thread(target=self._process_socks) self.sock_process_thread.daemon = True self.telem_sock.bind(('0.0.0.0', int(self.telem_port))) self.telem_sock.setblocking(False) self.telem_sock.settimeout(10) self.video_sock.bind(('0.0.0.0', self.video_port)) self.video_sock.setblocking(False) self.decoder_queue = queue.Queue(128) self.decoder = libh264decoder.H264Decoder() libh264decoder.disable_logging() self.videothread = threading.Thread(target=self._receive_video_data) self.videothread.daemon = True self.r_socks =[] self.w_socks =[] self.a_socks =[] #state variable self.in_command_mode = False self.in_action_mode = False self.in_flight = False self.error_and_stop_flight = False self.last_cmd = '' self.start_cmd_time = -1 self.timeout = 9.0 self.wait_time = 8.0 #wait duration for a response to an action, after which wait ends and next command is sent. TODO: to change wait_time based on command and past data self.socket_closed = False self.connecting = False self.connect_attempt = 0 self.max_connect_attempt = 3 #number of attempts to connect self.prevent_tello_inactivity_and_land_duration = 8 #duration after which hover command is sent to prevent auto land of tello due to inactivity self.last_frame = None self.frame = None self.is_freeze = False self._cmdseq = 0 self.response ='' self.data_queue = { self.command_sock : queue.Queue(32), #for buffering data from drone self.video_sock : queue.Queue(32), #for buffering video data from drone self.telem_sock : queue.Queue(32), #for buffering telemetry data from drone } self.cmd_queue = queue.Queue() #for buffering instructions from users self.data_timeout = 3 self.batterylevel = -1 self.tof = -1