Пример #1
0
    def _parse_address(self, i):
        assert i == 0 or i == 1
        if i == 0:
            server = 'command'
        elif i == 1:
            server = 'receiver'

        # Try to split the command server address string into ip and port.
        address = self.args.address[i].split(':')
        if len(address) != 2:
            raise debug.Error('args', 'the address of the %s server does not have a valid port' % server)
        else:
            # Make sure the ip is valid (this will throw an error if it's not).
            if address[0] == 'localhost':
                address[0] = '127.0.0.1'
            try:
                socket.inet_aton(address[0])
            except socket.error:
                raise debug.Error('args', 'the address of the %s server does not have a valid ip' % server)
            # Make sure the port is valid.
            try:
                port = int(address[1])
                if port not in range(9000, 9501):
                    raise debug.Error('args', 'the address of the %s server has a port %s not in the valid range 9000 to 9500' % (server, port))
            except ValueError:
                raise debug.Error('args', 'the address of the %s server does not have a valid port' % server)
    def __init__(self, debug_queue, error_queue):
        self.debug_queue = debug_queue
        self.error_queue = error_queue

        try:
            self.cmd_soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.cmd_soc.connect(('localhost', 9000))

        except socket.error as e:
            if e[0] == errno.ECONNREFUSED:
                self.error_queue.put(
                    debug.Error('controller',
                                'unable to connect to command server'))
            if e[0] == errno.EPIPE:
                self.error_queue.put(
                    debug.Error('controller', 'bad pipe to command server'))
    def __init__(self, debug_queue, error_queue):
        self.debug_queue = debug_queue
        self.error_queue = error_queue
        self.bufsize = 8192

        query = {'N': True}
        self.query_json = json.dumps(query)

        try:
            self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.soc.connect(('localhost', 9001))
            self.soc.setblocking(1)
        except socket.error as e:
            if e[0] == errno.ECONNREFUSED:
                self.error_queue.put(
                    debug.Error('receiver',
                                'unable to connect to receiver server'))
            if e[0] == errno.EPIPE:
                self.error_queue.put(
                    debug.Error('receiver', 'bad pipe to receiver server'))
 def recv_navdata(self):
     """ Gets the navigation data from the parrot by first sending a 'GET'
         query and then receiving the data.
     """
     navdata = None
     self.soc.send(self.query_json)
     try:
         navdata = self.soc.recv(self.bufsize)
     except socket.error as e:
         if e[0] == errno.ECONNREFUSED:
             self.error_queue.put(
                 debug.Error('receiver',
                             'unable to connect to receiver server'))
     return navdata
    def get_input(self):
        try:
            if self.pygame_okay:
                # Get the keyboard input.
                inputs_remote = self.get_keyboard()

                # Replace the keyboard input with gamepad input if a gamepad
                # is connected.
                self.check_gamepad_okay()
                if self.gamepad_okay and not self.key_flag:
                    inputs_remote = self.get_gamepad()
                if inputs_remote is None:
                    inputs_remote = self.default_cmd
                return inputs_remote
        except:
            exc_error = sys.exc_info()
            remote_error = debug.Error('remote', '%s, %s, %s' % exc_error)
            self.error_queue.put(remote_error)
    def __init__(self, debug_queue, error_queue):
        self.debug_queue = debug_queue
        self.error_queue = error_queue

        # Flags for errors.
        self.pygame_okay = False
        self.gamepad_okay = False

        # The default command that is sent to the drone.
        self.default_speed = 0.3
        self.default_cmd = {
            'X': 0.0,
            'Y': 0.0,
            'Z': 0.0,
            'R': 0.0,
            'C': 0,
            'T': False,
            'L': False,
            'S': False,
            'A': False
        }
        self.cur_cmd = None
        self.key_flag = False
        self.game_flag = False

        # The keys that should issue a stop command when released.
        self.stop_list = [
            pygame.K_d, pygame.K_a, pygame.K_s, pygame.K_w, pygame.K_q,
            pygame.K_e, pygame.K_r, pygame.K_f
        ]

        # Initialize pygame.
        (_, numfail) = pygame.init()
        if numfail > 0:
            self.error_queue.put(
                debug.Error('remote', 'pygame initialization failed'))
            return

        pygame.display.set_mode((100, 100))
        self.pygame_okay = True
        self.gamepad = None
        self.check_gamepad_okay()
Пример #7
0
 def _parse_trajectory(self):
     trajectory = self.args.trajectory
     if trajectory <= 0:
         raise debug.Error(
             'args', 'trajectory %s is not a positive integer' % trajectory)
Пример #8
0
 def _parse_iteration(self):
     iteration = self.args.iteration
     if iteration <= 0:
         raise debug.Error(
             'args', 'iteration %s is not a positive integer' % iteration)
Пример #9
0
 def _parse_learning(self):
     learning = self.args.learning
     if learning != 'tikhonov' and learning != 'ordinary_least_squares':
         raise debug.Error(
             'args',
             "%s is not 'tikhonov' or 'ordinary_least_squares" % learning)