Exemplo n.º 1
0
# Wait until we see that the port path is available
waiting = True
count = 1

while (waiting):
    try:
        # We don't really care about the actual communication
        # rate because we just want to know if the serial
        # path is available. However, we will set the baud
        # rate to 115200 based on the expected spec for our Arduino function.
        # The timeout value applies to any commands we might
        # choose to send in the future.
        arduino = llap.LLAP(deviceId='--',
                            port=arduinoPort,
                            baudrate=115200,
                            timeout=1.0,
                            xonxoff=True,
                            rtscts=True,
                            dsrdtr=True)
        arduino.flush()
        arduino.start()

        waiting = False

    except (OSError, serial.SerialException):
        # Don't pass the exception to the caller
        # Display a simple message
        print(str(count) + ") Waiting for " + arduinoPort + " ...")
        # Wait a short time then keep looping until the exception stops
        time.sleep(1.0)
        count = count + 1
Exemplo n.º 2
0
    def run(self):

        # Wait until we see that the port path is available
        waiting = True
        connected = False
        count = 1

        while (waiting and (self.on == True)):
            try:
                # We don't really care about the actual communication
                # rate because we just want to know if the serial
                # path is available. However, we will set the baud
                # rate to 115200 based on the expected spec for our device function.
                # The timeout value applies to any commands we might
                # choose to send in the future.
                self.device = llap.LLAP(deviceId='--',
                                        port=self.devicePort,
                                        baudrate=115200,
                                        timeout=1.0,
                                        xonxoff=True,
                                        rtscts=True,
                                        dsrdtr=True)
                self.device.flush()
                self.device.start()

                waiting = False

            except (OSError, serial.SerialException):
                # Don't pass the exception to the caller
                # Display a simple message
                if (self.form != None):
                    self.form.displayMessage(
                        str(count) + ": Waiting for " + self.devicePort)
                # Wait a short time then keep looping until the exception stops
                time.sleep(1.0)
                count = count + 1

        print("Port Wait Complete")
        if (self.on == True):
            try:
                print("Waiting for STARTED")
                message, deviceId = self.device.waitFor("STARTED",
                                                        timeout=2.0,
                                                        displayAll=True)

                if (message == None):
                    self.device.send("ACK")
                    message, deviceId = self.device.waitFor("ACK",
                                                            timeout=2.0,
                                                            displayAll=True)

                if (message == None):
                    raise TimeoutError('Timeout Waiting for STARTED')

                self.displayMessage(message, deviceId)

                self.device.changeDeviceId('AA')

                self.device.send("HELLO")
                message, deviceId = self.device.waitFor("HELLO")
                if (message == None):
                    raise TimeoutError('Timeout Waiting for HELLO')

                self.displayMessage(message, deviceId)

                self.device.send("INTVL010T")
                self.device.send("CYCLE")

                connected = True

                self.displayMessage("RUNNING")

            except (TimeoutError, KeyboardInterrupt) as error:
                print(str(error))
                connected = False
                if (self.form != None):
                    self.form.displayMessage(str(error))

        updateDelta = 1.0 / 12.0
        nextUpdateTime = time.time() + updateDelta

        while (connected and (self.on == True)):
            try:
                message, deviceId = self.device.get(timeout_sec=0.100)
                if (deviceId == 'PP'):
                    c = message[4:].split(',', 13)

                    self.navigator.updateImu(c)

                if (time.time() >= nextUpdateTime):

                    self.displayMessage(message, deviceId)

                    heading = "{:.1f}".format(self.navigator.heading)
                    roll = "{:.1f}".format(self.navigator.roll * 180 / pi)
                    pitch = "{:.1f}".format(self.navigator.pitch * 180 / pi)
                    yaw = "{:.1f}".format(self.navigator.yaw * 180 / pi)

                    self.displayMessage("HEADING = " + heading + "  (" + roll +
                                        ", " + pitch + ", " + yaw + ")")

                    nextUpdateTime += updateDelta

            except (BaseException) as error:
                print(str(error))
                self.displayMessage(str(error))

        print("Connection Loop Exited")
        self.device.send("STOP")
        self.device.stop()
        self.device.close()

        if (self.form != None):
            self.form.clearStatus()
Exemplo n.º 3
0
    def run(self):

        # Wait until we see that the port path is available
        waiting = True
        connected = False
        count = 1

        while (waiting and (self.on == True)):
            try:
                # We don't really care about the actual communication
                # rate because we just want to know if the serial
                # path is available. However, we will set the baud
                # rate to 115200 based on the expected spec for our device function.
                # The timeout value applies to any commands we might
                # choose to send in the future.
                self.device = llap.LLAP(deviceId='--',
                                        port=self.devicePort,
                                        baudrate=115200,
                                        timeout=1.0,
                                        xonxoff=True,
                                        rtscts=True,
                                        dsrdtr=True)
                self.device.flush()
                self.device.start()

                waiting = False

            except (OSError, serial.SerialException):
                # Don't pass the exception to the caller
                # Display a simple message
                if (self.form != None):
                    self.form.displayMessage(
                        str(count) + ": Waiting for " + self.devicePort)
                # Wait a short time then keep looping until the exception stops
                time.sleep(1.0)
                count = count + 1

        if (self.on == True):
            try:
                message, deviceId = self.device.waitFor("STARTED", timeout=2.0)

                if (message == None):
                    raise TimeoutError('Timeout Waiting for STARTED')

                self.displayMessage(message, deviceId)

                self.device.changeDeviceId('AA')

                self.device.send("HELLO")
                message, deviceId = self.device.waitFor("HELLO")
                if (message == None):
                    raise TimeoutError('Timeout Waiting for HELLO')

                self.displayMessage(message, deviceId)

                self.device.send("INTVL010T")
                self.device.send("CYCLE")

                connected = True

                self.displayMessage("RUNNING")

            except (TimeoutError, KeyboardInterrupt) as error:
                connected = False
                if (self.form != None):
                    self.form.displayMessage(str(error))

        updateDelta = 1.0 / 24.0
        nextUpdateTime = time.time() + updateDelta

        while (connected and (self.on == True)):
            try:
                message, deviceId = self.device.get()

                if (time.time() > nextUpdateTime):
                    self.displayMessage(message, deviceId)
                    # temporary parsing of the message to compute
                    # an orientation
                    c = message[5:].split(',', 9)
                    self.form.quad.xDir = int(c[6])
                    self.form.quad.yDir = int(c[7])
                    self.form.quad.zDir = int(c[8])
                    self.form.quad.updateGL()

                    nextUpdateTime += updateDelta

            except:
                pass

        self.device.send("STOP")
        self.device.stop()
        self.device.close()

        if (self.form != None):
            self.form.clearStatus()