コード例 #1
0
    def __init__(self, port, asynchronous=False, timeout=0.5, max_tries=10):
        """Create new controller.

        Arguments:
            port -- The device where e-puck robot is connected (e.g. /dev/rfcomm0).
            asynchronous -- Set True to use asynchronous communication.
                Synchronous communication is default.
            timeout -- How long to wait before the message is sent again.
            max_tries -- How many tries before raising an exception (in async).

        """

        try:
            if asynchronous:
                self.comm = AsyncComm(port, timeout, max_tries)
                self.comm.start()
            else:
                self.comm = SyncComm(port, timeout)
        except CommError as e:
            raise ControllerError(e)

        self.command_index = random.randrange(len(string.printable))
        self.command_i = string.printable[self.command_index]

        self.motor_speed = [0, 0]
        self.body_led = False
        self.front_led = False
        self.leds = 8 * [False]

        self.logger = logging.getLogger('Controller')