def get_status(self):
        if self.cfusb is None:
            try:
                self.cfusb = CfUsb()
            except USBError as e:
                return "Cannot open Crazyflie. Permission problem?"\
                       " ({})".format(str(e))
            except Exception as e:
                return str(e)

        return "Crazyradio version {}".format(self.cfusb.version)
示例#2
0
    def connect(self, uri, link_quality_callback, link_error_callback):
        """
        Connect the link driver to a specified URI of the format:
        radio://<dongle nbr>/<radio channel>/[250K,1M,2M]

        The callback for linkQuality can be called at any moment from the
        driver to report back the link quality in percentage. The
        callback from linkError will be called when a error occues with
        an error message.
        """

        # check if the URI is a radio URI
        if not re.search("^usb://", uri):
            raise WrongUriType("Not a radio URI")

        # Open the USB dongle
        if not re.search("^usb://([0-9]+)$",
                         uri):
            raise WrongUriType('Wrong radio URI format!')

        uri_data = re.search("^usb://([0-9]+)$",
                             uri)

        self.uri = uri

        if self.cfusb is None:
            self.cfusb = CfUsb(devid=int(uri_data.group(1)))
            if self.cfusb.dev:
                self.cfusb.set_crtp_to_usb(True)
                # Wait for the blocking queues in the firmware to time out
                time.sleep(1)
            else:
                self.cfusb = None
                raise Exception("Could not open {}".format(self.uri))

        else:
            raise Exception("Link already open!")

        # Prepare the inter-thread communication queue
        self.in_queue = queue.Queue()
        # Limited size out queue to avoid "ReadBack" effect
        self.out_queue = queue.Queue(50)

        # Launch the comm thread
        self._thread = _UsbReceiveThread(self.cfusb, self.in_queue,
                                         link_quality_callback,
                                         link_error_callback)
        self._thread.start()

        self.link_error_callback = link_error_callback
示例#3
0
    def scan_interface(self, address):
        """ Scan interface for Crazyflies """
        if self.cfusb is None:
            try:
                self.cfusb = CfUsb()
            except Exception as e:
                logger.warn("Exception while scanning for Crazyflie USB: {}".format(str(e)))
                return []
        else:
            raise Exception("Cannot scan for links while the link is open!")

        # FIXME: implements serial number in the Crazyradio driver!
        #serial = "N/A"

        found = self.cfusb.scan()

        self.cfusb.close()
        self.cfusb = None

        return found