How to use the cflib.crtp function in cflib

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 / 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")
github bitcraze / lps-node-firmware / tools / lpp / set_tx_power.py View on Github external
args.anchor_id_lower, args.anchor_id_upper
        ))

    (power_conf, force, smart) = generate_config(args.power)
    power_pack = generate_lpp_packet(power_conf, force, smart)

    print('Sending anchor transmit power configuration to anchors (%i to %i) '
          'using %s. Setting transmit power to %s%s. Anchors will reset'
          'when configured.' % (
              args.anchor_id_lower,
              args.anchor_id_upper,
              args.uri,
              args.power, unit))

    logging.basicConfig(level=logging.ERROR)
    cflib.crtp.init_drivers(enable_debug_driver=False)
    cf = Crazyflie(rw_cache='./cache')
    with SyncCrazyflie(args.uri, cf=cf) as scf:
        print('Starting transmission. Terminate with CTRL+C.')
        while True:
            for id in range(args.anchor_id_lower, args.anchor_id_upper + 1):
                print('Anchor %i' % id)
                for _ in range(7):
                    scf.cf.loc.send_short_lpp_packet(id, power_pack)
                    time.sleep(0.2)
                time.sleep(0.5)
github bitcraze / crazyflie-clients-python / examples / read-ow.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 = OWExample(available[0][0])
    else:
        print("No Crazyflies found, cannot run example")

    # 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.
    try:
        while le.is_connected:
            time.sleep(1)
    except KeyboardInterrupt:
github bitcraze / crazyflie-clients-python / src / cfclient / ui / dialogs / about.py View on Github external
def showEvent(self, event):
        """Event when the about box is shown"""
        self._interface_text = ""
        interface_status = cflib.crtp.get_interfaces_status()
        for key in list(interface_status.keys()):
            self._interface_text += INTERFACE_FORMAT.format(
                key, interface_status[key])

        self._device_text = ""
        devs = self._helper.inputDeviceReader.available_devices()
        for d in devs:
            self._device_text += DEVICE_FORMAT.format(
                d.reader_name, d.id, d.name)
        if len(self._device_text) == 0:
            self._device_text = "None<br>"

        self._input_readers_text = ""
        # readers = self._helper.inputDeviceReader.getAvailableDevices()
        for reader in cfclient.utils.input.inputreaders.initialized_readers:
            self._input_readers_text += INPUT_READER_FORMAT.format(
github bitcraze / crazyflie-clients-python / src / cfclient / ui / main.py View on Github external
def _keep_alive_changed(self, checked):
        self._keep_alive_enabled = checked
        Config().set("keep_alive", checked)
        logger.info("Keep alive enabled: {}".format(checked))

        if checked:
            cflib.crtp.radiodriver.set_retries_before_disconnect(99999999999999999)  # never disconnect :)
            cflib.crtp.radiodriver.set_retries(3)
        else:
            cflib.crtp.radiodriver.set_retries_before_disconnect(1500) # default
            cflib.crtp.radiodriver.set_retries(3)
github udacity / udacidrone / udacidrone / connection / crazyflie_connection.py View on Github external
def __init__(self, uri, velocity=0.2, threaded=False):
        super().__init__(threaded)

        # set the default velocity
        self._velocity = velocity

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

        # the connection to the crazyflie
        self._scf = SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache'))

        # temp (or maybe will be permanent) state variable
        self._is_open = False
        self._running = False

        self._send_rate = 50  # want to send messages at 5Hz  NOTE: the minimum is 2 Hz
        self._out_msg_queue = queue.Queue()  # a queue for sending data between threads
        self._write_handle = threading.Thread(target=self.command_loop)
        self._write_handle.daemon = True

        # since can only command velocities and not positions, the connection
        # needs some awareness of the current position to be able to do
        # the math necessary
github bitcraze / crazyflie-clients-python / src / cfzmq / __init__.py View on Github external
def __init__(self, base_url):
        """Start threads and bind ports"""
        cflib.crtp.init_drivers(enable_debug_driver=True)
        self._cf = Crazyflie(ro_cache=None,
                             rw_cache=cfclient.config_path + "/cache")

        signal.signal(signal.SIGINT, signal.SIG_DFL)

        self._base_url = base_url
        self._context = zmq.Context()

        cmd_srv = self._bind_zmq_socket(zmq.REP, "cmd", ZMQ_SRV_PORT)
        log_srv = self._bind_zmq_socket(zmq.PUB, "log", ZMQ_LOG_PORT)
        param_srv = self._bind_zmq_socket(zmq.PUB, "param", ZMQ_PARAM_PORT)
        ctrl_srv = self._bind_zmq_socket(zmq.PULL, "ctrl", ZMQ_CTRL_PORT)
        conn_srv = self._bind_zmq_socket(zmq.PUB, "conn", ZMQ_CONN_PORT)

        self._scan_thread = _SrvThread(cmd_srv, log_srv, param_srv, conn_srv,
                                       self._cf)