Exemple #1
0
    def run(self):
        if self.is_ar_drone_2:
            video_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            video_socket.connect(
                ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))
            video_socket.setblocking(0)
        else:
            video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            video_socket.setblocking(0)
            video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
            video_socket.sendto("\x01\x00\x00\x00",
                                ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))

        nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        nav_socket.setblocking(0)
        nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
        nav_socket.sendto("\x01\x00\x00\x00",
                          ('192.168.1.1', libardrone.ARDRONE_NAVDATA_PORT))

        stopping = False
        while not stopping:
            inputready, outputready, exceptready = select.select(
                [nav_socket, video_socket, self.com_pipe], [], [])
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    if self.is_ar_drone_2:
                        self.ar2video.write(data)
                        # Sending is taken care of by the decoder
                    else:
                        w, h, image, t = arvideo.read_picture(data)
                        self.video_pipe.send(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata = libardrone.decode_navdata(data)
                    self.nav_pipe.send(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    stopping = True
                    break
        video_socket.close()
        nav_socket.close()
Exemple #2
0
    def run(self):
        if self.is_ar_drone_2:
            video_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            video_socket.connect(('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))
            video_socket.setblocking(0)
        else:
            video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            video_socket.setblocking(0)
            video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
            video_socket.sendto("\x01\x00\x00\x00", ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))

        nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        nav_socket.setblocking(0)
        nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
        nav_socket.sendto("\x01\x00\x00\x00", ('192.168.1.1', libardrone.ARDRONE_NAVDATA_PORT))

        stopping = False
        while not stopping:
            inputready, outputready, exceptready = select.select([nav_socket, video_socket, self.com_pipe], [], [])
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    if self.is_ar_drone_2:
                        self.ar2video.write(data)
                        # Sending is taken care of by the decoder
                    else:
                        w, h, image, t = arvideo.read_picture(data)
                        self.video_pipe.send(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata = libardrone.decode_navdata(data)
                    self.nav_pipe.send(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    stopping = True
                    break
        video_socket.close()
        nav_socket.close()
Exemple #3
0
    def run(self):
        video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        video_socket.setblocking(0)
        video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
        video_socket.sendto("\x01\x00\x00\x00",
                            (self.ip, libardrone.ARDRONE_VIDEO_PORT))

        nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        nav_socket.setblocking(0)
        nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
        nav_socket.sendto("\x01\x00\x00\x00",
                          (self.ip, libardrone.ARDRONE_NAVDATA_PORT))

        stopping = False
        while not stopping:
            inputready, outputready, exceptready = select.select(
                [nav_socket, video_socket, self.com_pipe], [], [])
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    w, h, image, t = arvideo.read_picture(data)
                    self.video_pipe.send(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata = libardrone.decode_navdata(data)
                    # print 'navdata being sent'
                    self.nav_pipe.send(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    stopping = True
                    break
        video_socket.close()
        nav_socket.close()
Exemple #4
0
    def run(self):
        video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        video_socket.setblocking(0)
        video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
        video_socket.sendto("\x01\x00\x00\x00", (self.ip, libardrone.ARDRONE_VIDEO_PORT))

        nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        nav_socket.setblocking(0)
        nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
        nav_socket.sendto("\x01\x00\x00\x00", (self.ip, libardrone.ARDRONE_NAVDATA_PORT))

        stopping = False
        while not stopping:
            inputready, outputready, exceptready = select.select([nav_socket, video_socket, self.com_pipe], [], [])
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    w, h, image, t = arvideo.read_picture(data)
                    self.video_pipe.send(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(65535)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata = libardrone.decode_navdata(data)
                    # print 'navdata being sent'
                    self.nav_pipe.send(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    stopping = True
                    break
        video_socket.close()
        nav_socket.close()
Exemple #5
0
    def run(self):

        def _connect():
            logging.warn('Connection to ardrone')
            if self.is_ar_drone_2:
                video_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                video_socket.connect(('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))
                video_socket.setblocking(0)
            else:
                video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                video_socket.setblocking(0)
                video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
                video_socket.sendto("\x01\x00\x00\x00", ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))

            nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
            nav_socket.setblocking(0)
            nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
            nav_socket.sendto("\x01\x00\x00\x00", ('192.168.1.1', libardrone.ARDRONE_NAVDATA_PORT))

            control_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            control_socket.connect(('192.168.1.1', libardrone.ARDRONE_CONTROL_PORT))
            control_socket.setblocking(0)

            time.sleep(1.0)

            com_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            com_socket.connect(('127.0.0.1', 17482))
            com_socket.setblocking(0)
            logging.warn('Connection established')
            return video_socket, nav_socket, control_socket, com_socket

        def _disconnect(video_socket, nav_socket, control_socket):
            logging.warn('Disconnection to ardrone streams')
            video_socket.close()
            nav_socket.close()
            control_socket.close()

        video_socket, nav_socket, control_socket, com_socket = _connect()

        self.stopping = False
        connection_lost = 1
        reconnection_needed = False
        while not self.stopping:
            if reconnection_needed:
                _disconnect(video_socket, nav_socket, control_socket)
                video_socket, nav_socket, control_socket, com_socket = _connect()
                reconnection_needed = False
            inputready, outputready, exceptready = select.select([nav_socket, video_socket, com_socket, control_socket], [], [], 1.)
            if len(inputready) == 0:
                connection_lost += 1
                reconnection_needed = True
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65536)
                            if self.is_ar_drone_2:
                                self.ar2video.write(data)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                        # Sending is taken care of by the decoder
                    if not self.is_ar_drone_2:
                        w, h, image, t = arvideo.read_picture(data)
                        self._drone.set_image(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(500)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata, has_information = libardrone.decode_navdata(data)
                    if (has_information):
                        self._drone.set_navdata(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    self.stopping = True
                    break
                elif i == com_socket:
                    # print "got die!"
                    self.stopping = True
                    break
                elif i == control_socket:
                    reconnection_needed = False
                    while not reconnection_needed:
                        try:
                            data = control_socket.recv(65536)
                            if len(data) == 0:
                                logging.warning('Received an empty packet on control socket')
                                reconnection_needed = True
                            else:
                                logging.warning("Control Socket says : %s", data)
                        except IOError:
                            break
        _disconnect(video_socket, nav_socket, control_socket)
Exemple #6
0
    def run(self):
        def _connect():
            logging.warn('Connection to ardrone')
            if self.is_ar_drone_2:
                video_socket = socket.socket(socket.AF_INET,
                                             socket.SOCK_STREAM)
                video_socket.connect(
                    ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))
                video_socket.setblocking(0)
            else:
                video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                video_socket.setblocking(0)
                video_socket.bind(('', libardrone.ARDRONE_VIDEO_PORT))
                video_socket.sendto(
                    "\x01\x00\x00\x00",
                    ('192.168.1.1', libardrone.ARDRONE_VIDEO_PORT))

            nav_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                       socket.IPPROTO_UDP)
            nav_socket.setblocking(0)
            nav_socket.bind(('', libardrone.ARDRONE_NAVDATA_PORT))
            nav_socket.sendto("\x01\x00\x00\x00",
                              ('192.168.1.1', libardrone.ARDRONE_NAVDATA_PORT))

            control_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            control_socket.connect(
                ('192.168.1.1', libardrone.ARDRONE_CONTROL_PORT))
            control_socket.setblocking(0)
            logging.warn('Connection established')
            return video_socket, nav_socket, control_socket

        def _disconnect(video_socket, nav_socket, control_socket):
            logging.warn('Disconnection to ardrone streams')
            video_socket.close()
            nav_socket.close()
            control_socket.close()

        video_socket, nav_socket, control_socket = _connect()

        stopping = False
        connection_lost = 1
        reconnection_needed = False
        while (not stopping) and (not self.stopped()):
            if reconnection_needed:
                _disconnect(video_socket, nav_socket, control_socket)
                video_socket, nav_socket, control_socket = _connect()
                reconnection_needed = False
            inputready, outputready, exceptready = select.select(
                [nav_socket, video_socket, self.com_pipe, control_socket], [],
                [], 1.)
            if len(inputready) == 0:
                connection_lost += 1
                reconnection_needed = True
            for i in inputready:
                if i == video_socket:
                    while 1:
                        try:
                            data = video_socket.recv(65536)
                            if self.is_ar_drone_2:
                                self.ar2video.write(data)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                        # Sending is taken care of by the decoder
                    if not self.is_ar_drone_2:
                        w, h, image, t = arvideo.read_picture(data)
                        self._drone.set_image(image)
                elif i == nav_socket:
                    while 1:
                        try:
                            data = nav_socket.recv(500)
                        except IOError:
                            # we consumed every packet from the socket and
                            # continue with the last one
                            break
                    navdata, has_information = libardrone.decode_navdata(data)
                    if (has_information):
                        self._drone.set_navdata(navdata)
                elif i == self.com_pipe:
                    _ = self.com_pipe.recv()
                    stopping = True
                    break
                elif i == control_socket:
                    reconnection_needed = False
                    while not reconnection_needed:
                        try:
                            data = control_socket.recv(65536)
                            if len(data) == 0:
                                logging.warning(
                                    'Received an empty packet on control socket'
                                )
                                reconnection_needed = True
                            else:
                                logging.warning("Control Socket says : %s",
                                                data)
                        except IOError:
                            break
        _disconnect(video_socket, nav_socket, control_socket)