How to use cflib - 10 common examples

To help you get started, we’ve selected a few cflib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitcraze / crazyflie-clients-python / cfclient / ui / tabs / ServiceTab.py View on Github external
def initiateColdBoot(self, linkURI):
        self.connectingSignal.emit()
        self.link = cflib.crtp.get_link_driver("radio://0/110")
        self.loader = Cloader(self.link, "radio://0/110")
        #self.link = CRTP.get_link_driver("debug://0/110")
        #self.loader = Cloader(self.link, "debug://0/110")

        if self.loader.coldboot():
            logger.info("Connected in coldboot mode ok")
            self.updateCpuIdSignal.emit(self.loader.cpuid)
            self.readConfigAction()
            self.connectedSignal.emit()
        else:
            self.connectionFailedSignal.emit()
            logger.info("Connected in coldboot mode failed")
            self.link.close()
github bitcraze / crazyflie-clients-python / examples / basiclog.py View on Github external
self.is_connected = False

    def _connection_lost(self, link_uri, msg):
        """Callback when disconnected after a connection has been made (i.e
        Crazyflie moves out of range)"""
        print("Connection to %s lost: %s" % (link_uri, msg))

    def _disconnected(self, link_uri):
        """Callback when the Crazyflie is disconnected (called in all cases)"""
        print("Disconnected from %s" % link_uri)
        self.is_connected = False


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)
    # Scan for Crazyflies and use the first one found
    print("Scanning interfaces for Crazyflies...")
    available = cflib.crtp.scan_interfaces()
    print("Crazyflies found:")
    for i in available:
        print(i[0])

    if len(available) > 0:
        le = LoggingExample(available[0][0])
    else:
        print("No Crazyflies found, cannot run example")
        sys.exit(1)

    # The Crazyflie lib doesn't contain anything to keep the application alive,
    # so this is where your application should do something. In our case we
    # are just waiting until we are disconnected.
github bitcraze / crazyflie-clients-python / src / cfloader / __init__.py View on Github external
def main():
    # Initialise the CRTP link driver
    link = None
    try:
        cflib.crtp.init_drivers()
        link = cflib.crtp.get_link_driver("radio://")
    except Exception as e:
        print("Error: {}".format(str(e)))
        if link:
            link.close()
        sys.exit(-1)

    # Set the default parameters
    clink = None
    action = "info"
    boot = "cold"

    if len(sys.argv) < 2:
        print()
        print("==============================")
        print(" CrazyLoader Flash Utility")
        print("==============================")
github bitcraze / crazyflie-clients-python / src / cfloader / __init__.py View on Github external
def main():
    # Initialise the CRTP link driver
    link = None
    try:
        cflib.crtp.init_drivers()
        link = cflib.crtp.get_link_driver("radio://")
    except Exception as e:
        print("Error: {}".format(str(e)))
        if link:
            link.close()
        sys.exit(-1)

    # Set the default parameters
    clink = None
    action = "info"
    boot = "cold"

    if len(sys.argv) < 2:
        print()
        print("==============================")
        print(" CrazyLoader Flash Utility")
github bitcraze / crazyflie-clients-python / lib / cfclient / ui / dialogs / connectiondialogue.py View on Github external
def scan(self, address):
        self.interfaceFoundSignal.emit(cflib.crtp.scan_interfaces(address))
github bitcraze / crazyflie-clients-python / src / cfclient / ui / main.py View on Github external
def scan(self, address):
        self.interfaceFoundSignal.emit(cflib.crtp.scan_interfaces(address))
github bitcraze / crazyflie-clients-python / examples / basiclog.py View on Github external
"""Callback when disconnected after a connection has been made (i.e
        Crazyflie moves out of range)"""
        print("Connection to %s lost: %s" % (link_uri, msg))

    def _disconnected(self, link_uri):
        """Callback when the Crazyflie is disconnected (called in all cases)"""
        print("Disconnected from %s" % link_uri)
        self.is_connected = False


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)
    # Scan for Crazyflies and use the first one found
    print("Scanning interfaces for Crazyflies...")
    available = cflib.crtp.scan_interfaces()
    print("Crazyflies found:")
    for i in available:
        print(i[0])

    if len(available) > 0:
        le = LoggingExample(available[0][0])
    else:
        print("No Crazyflies found, cannot run example")
        sys.exit(1)

    # The Crazyflie lib doesn't contain anything to keep the application alive,
    # so this is where your application should do something. In our case we
    # are just waiting until we are disconnected.
    while le.is_connected:
        time.sleep(1)
github bitcraze / lps-node-firmware / tools / lpp / set_positions.py View on Github external
print("usage: {} [URI]".format(sys.argv[0]))
    print("  URI - the URI to use to connect to the Crazyflie, default value is  radio://0/80/2M/E7E7E7E7E7")
    sys.exit(1)

uri = 'radio://0/80/2M/E7E7E7E7E7'
if len(sys.argv) > 1:
    uri = sys.argv[1]

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)

# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)

cf = Crazyflie(rw_cache='./cache')
with SyncCrazyflie(uri, cf=cf) as scf:
    print("Setting positions")

    for packet in yaml.load_all(sys.stdin, Loader=yaml.CLoader):
        if not packet:
            continue

        while True:
            for id, position in packet.items():
                x = position['x']
                y = position['y']
                z = position['z']

                print("Anchor {}, ({}, {}, {})".format(id, x, y, z))
                LPP_SHORT_ANCHOR_POSITION = 0x01
                position_pack = struct.pack("
github bitcraze / crazyflie-clients-python / src / cfloader / __init__.py View on Github external
[target, type] = t.split("-")
            if target in targetnames:
                targetnames[target] += (type,)
            else:
                targetnames[target] = (type,)
    else:
        print("Action", sys.argv[0], "unknown!")
        link.close()
        sys.exit(-1)

    # Currently there's two different targets available
    targets = ()

    try:
        # Initialise the bootloader lib
        bl = Bootloader(clink)

        #########################################
        # Get the connection with the bootloader
        #########################################
        # The connection is done by reseting to the bootloader (default)
        if boot == "reset":
            print("Reset to bootloader mode ..."),
            sys.stdout.flush()
            if bl.start_bootloader(warm_boot=True):
                print(" done!")
            else:
                print("Failed to warmboot")
                bl.close()
                sys.exit(-1)
        else:  # The connection is done by a cold boot ...
            print("Restart the Crazyflie you want to bootload in the next"),
github bitcraze / crazyflie-clients-python / src / cfloader / __init__.py View on Github external
bl.close()
                sys.exit(-1)
        else:  # The connection is done by a cold boot ...
            print("Restart the Crazyflie you want to bootload in the next"),
            print(" 10 seconds ..."),

            sys.stdout.flush()
            if bl.start_bootloader(warm_boot=False):
                print(" done!")
            else:
                print("Cannot connect the bootloader!")
                bl.close()
                sys.exit(-1)

        print("Connected to bootloader on {} (version=0x{:X})".format(
            BootVersion.to_ver_string(bl.protocol_version),
            bl.protocol_version))

        if bl.protocol_version == BootVersion.CF2_PROTO_VER:
            targets += (bl.get_target(TargetTypes.NRF51),)
        targets += (bl.get_target(TargetTypes.STM32),)

        ######################################
        # Doing something (hopefully) useful
        ######################################

        # Print information about the targets
        for target in targets:
            print(target)
        if action == "info":
            None  # Already done ...
        elif action == "reset":