Giter VIP home page Giter VIP logo

crazyflie-lib-python's Introduction

cflib: Crazyflie python library CI

cflib is an API written in Python that is used to communicate with the Crazyflie and Crazyflie 2.0 quadcopters. It is intended to be used by client software to communicate with and control a Crazyflie quadcopter. For instance the Crazyflie PC client uses the cflib.

See below for platform specific instruction. For more info see our documentation.

Installation

See the installation instructions in the github docs folder.

Official Documentation

Check out the Bitcraze crazyflie-lib-python documentation on our website.

Contribute

Go to the contribute page on our website to learn more.

Test code for contribution

Run the automated build locally to test your code

python3 tools/build/build

crazyflie-lib-python's People

Contributors

acxz avatar arjo129 avatar ashwinsushil avatar ataffanel avatar chengliu-lr avatar dolfje avatar dominiknatter avatar elfring avatar evoggy avatar fredg02 avatar gelanchez avatar gemenerik avatar hmllr avatar jancoow avatar jath03 avatar jonasdn avatar kentwills avatar knmcguire avatar krichardsson avatar marios-stam avatar ntamas avatar piggygaga avatar romi2002 avatar s9meboeh avatar simonjwright avatar tobbeanton avatar toverumar avatar trheinfels avatar valeriyvan avatar whoenig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crazyflie-lib-python's Issues

Remove anchor positions from the autonomous examples

The storage of anchor positions have been moved into the anchors in the latest anchor firmware. There is no need to send the position from the example scripts to the crazyflie since it will get them from the anchors in the new solution.
Remove the anchor positions from the examples.

Multiramp question

I have a thesis that needs to control four crazyflies simultaneously. I decided to use the multiramp code here. My question: is it possible to control four crazyflies using that code? Since I can successfully use the code to control two. Can I also use the code to have each crazyflie do their own thing?

Add TOC caching to examples

The examples do not use TOC caching. With caching connection is faster, it might not be super important for examples with one Crazyflie but makes a bigger difference for a swarm.

SyncLogger does not work on python2

The SyncLogger class does not implement the python2 flavour of the iteration method next
In python2 the next method is called next(), in python3 it is next()

Documentation is wrong for commander.py

Angles should be degrees and not rads as the comments state for send_velocity_world_setpoint(), send_zdistance_setpoint() and send_hover_setpoint().
For send_hover_setpoint() vx and vy should be m/s

Add synchronous flavour of the API

The lib is currently based on callbacks which works well in the GUI based client. Callbacks can easily become messy though and adding a synchronous flavour of the API as well would simplify scripting of non GUI based applications.

An example:

  1. Open a connection to a CF
  2. Wait for a log value to reach a specific value
  3. Set a parameter
  4. Close the connection
log_config = LogConfig(name='My data', period_in_ms=100)
log_config.add_variable('my.var', 'float')

with SyncCrazyflie('radio://0/60/2M') as cf:
    with SyncLogger(cf, log_config) as logger:
        for data in logger:
            if data["my.var"] > 10.0:
                break

    cf.set_param('my.param', '4711')

Radio CRTP interface get_status erroneously raising an interrupt when no Crazyradio plugged

When no Crazyradio is plugged, the radio interface driver should return string but instead raise an exception. This crashes the client about box when no radio is connected.

Bug demonstration:

>>> import cflib.crtp
>>> cflib.crtp.init_drivers()
>>> # The problem is that this is raising an exception:
... cflib.crtp.get_interfaces_status()
Traceback (most recent call last):
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 119, in __init__
    device = _find_devices()[devid]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/__init__.py", line 78, in get_interfaces_status
    status[instance.get_name()] = instance.get_status()
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 369, in get_status
    radio_manager = _RadioManager(0)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 98, in __init__
    _RadioManager._radios[self._devid] = _SharedRadio(self._devid)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 67, in __init__
    self.radio = Crazyradio(devid=devid)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 121, in __init__
    raise Exception('Cannot find a Crazyradio Dongle')
Exception: Cannot find a Crazyradio Dongle
>>> # Expecting a string:
... cflib.crtp.usbdriver.UsbDriver().get_status()
'No information available'
>>> # But getting an exception:
... cflib.crtp.radiodriver.RadioDriver().get_status()
Traceback (most recent call last):
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 119, in __init__
    device = _find_devices()[devid]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 369, in get_status
    radio_manager = _RadioManager(0)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 98, in __init__
    _RadioManager._radios[self._devid] = _SharedRadio(self._devid)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/crtp/radiodriver.py", line 67, in __init__
    self.radio = Crazyradio(devid=devid)
  File "/home/arnaud/dev/bitcraze/vanilia/crazyflie-lib-python/cflib/drivers/crazyradio.py", line 121, in __init__
    raise Exception('Cannot find a Crazyradio Dongle')
Exception: Cannot find a Crazyradio Dongle

Writing more the 112 bytes in 1-wire mem hangs cflib

While writing the erase function I accedentely was trying to erase 128 bytes to the 1-wire mem. This forces the lib into an endless retry loop because of status=5 (EIO).

Connected to usb://0 Found 1 1-wire memories Erasing memory 2 INFO:cflib.crazyflie.mem:Writing new chunk of 25bytes at 0x0 INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x0, status=0x0 INFO:cflib.crazyflie.mem:Writing new chunk of 25bytes at 0x19 INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x19, status=0x0 INFO:cflib.crazyflie.mem:Writing new chunk of 25bytes at 0x32 INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x32, status=0x0 INFO:cflib.crazyflie.mem:Writing new chunk of 25bytes at 0x4B INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x4B, status=0x0 INFO:cflib.crazyflie.mem:Writing new chunk of 25bytes at 0x64 INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x64, status=0x5 INFO:cflib.crazyflie.mem:Status 5: write resending... INFO:cflib.crazyflie.mem:Sending write again... INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x64, status=0x5 INFO:cflib.crazyflie.mem:Status 5: write resending... INFO:cflib.crazyflie.mem:Sending write again... INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x64, status=0x5 INFO:cflib.crazyflie.mem:Status 5: write resending... INFO:cflib.crazyflie.mem:Sending write again... INFO:cflib.crazyflie.mem:WRITE: Mem=2, addr=0x64, status=0x5 INFO:cflib.crazyflie.mem:Status 5: write resending... INFO:cflib.crazyflie.mem:Sending write again...

radio driver : Add a way to configure the value of _RadioDriverThread.TRIES_BEFORE_DISCON

Hello,

When working with multiple drones (5) without using broadcast packets, I got drones randomly disconnecting.

This problem was due to packet losses, and the drone being disconnected by this piece of code

I tried hardcoding _RadioDriverThread.TRIES_BEFORE_DISCON to extremely high values, and my problem disapeared, and the drones were still responsive.

It would be great, though, if there was a method call to set this value directly. I did not make a PR as it seems to need some non-trivial changes in order not to be too hacky.

Unable to run ramp.py

I'm trying to run the ramp.py file, but I keep encountering an error that I can't understand.
I'm using windows 10 and a crazyflie 2.0

`Scanning interfaces for Crazyflies...
Crazyflies found:
radio://0/100/2M
ERROR:cflib.crazyflie:Couldn't load link driver: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'

Traceback (most recent call last):
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crazyflie_init_.py", line 218, in open_link
link_uri, self._link_quality_cb, self.link_error_cb)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp_init
.py", line 91, in get_link_driver
instance.connect(uri, link_quality_callback, link_error_callback)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 188, in connect
address)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 98, in init
_RadioManager._radios[self._devid] = _SharedRadio(self._devid)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 67, in init
self.radio = Crazyradio(devid=devid)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\drivers\crazyradio.py", line 126, in init
self.dev.set_configuration(1)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 869, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb0.py", line 493, in set_configuration
_check(_lib.usb_set_configuration(dev_handle, config_value))
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'

Connection to radio://0/100/2M failed: Couldn't load link driver: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'

Traceback (most recent call last):
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crazyflie_init_.py", line 218, in open_link
link_uri, self._link_quality_cb, self.link_error_cb)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp_init
.py", line 91, in get_link_driver
instance.connect(uri, link_quality_callback, link_error_callback)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 188, in connect
address)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 98, in init
_RadioManager._radios[self._devid] = _SharedRadio(self._devid)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\crtp\radiodriver.py", line 67, in init
self.radio = Crazyradio(devid=devid)
File "c:\users\rafael\documents\dlsu\thesis\crazyflie\crazyflie-lib-python-master\crazyflie-lib-python-master\cflib\drivers\crazyradio.py", line 126, in init
self.dev.set_configuration(1)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 869, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb0.py", line 493, in set_configuration
_check(_lib.usb_set_configuration(dev_handle, config_value))
File "C:\Users\RAFAEL\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'

Connecting to radio://0/100/2M`

Print error when callback throws an exception

Currently if a callback throws an exception a warning is emitted. Since warning is not enabled by default in example this causes silently ignored exceptions by default.

Throwing exception is serious enough to trigger an error instead, the warning should be changed in error.

Dropping python 2.X?

The lib supports both python 2.X and 3.X while the client is python 3.X only. I'm suggesting to drop support for python 2.X for the lib as well to make the code cleaner and leaner. It would simplify maintenance and development as well as reduce complexity and risk.

If there are a lot of users that run the lib with python 2.X it would obviously be a bad idea, so please let us know if you do!

virtualenv

'best practice' is usually to install python packages in a virtualenv rather than on the system level, would you accept a pull request that changes the README to provide instructions on installing the cflib package in a virtualenv instead of globally as root? Furthermore, would you be open to having a Makefile that automates these steps for the user?

Improve readme

The readem.md is pretty sparse. We should add more information on how to set up and use the development environment, builder server and so on.

Increase default number of lost packets before disconnect

The current value of lost packets before reconnect on the radio link to the copter is 10. That works well on full power.
In issue bitcraze/crazyflie-firmware#269 the output power of the Crazyflie radio is reduced when the LPS deck is mounted and in this case the risk of packet loss is increased. The limit of 10 packets is a bit too harsh and could be increased to allow for some more slack before disconnecting. This would reduce the risk of disconnects.

Build broken on travis

Seems to be a problem related to pre-commit. Travis is using latest version of everything while pre-commit-config.yaml locks versions that are not compatible any more.

Upgrade to latest versions in config file. Will also require upgrade of the docker builder image.

Cache Crazyradio parameters in low level driver

Since the change #22 to add possibility to connect more than one Crazyflie, the lib is changing channel, datarate and address for each sent packet. This can be quite inefficient since it is triggering USB setup for each set parameters.

We can implement a cache functionality in the Crazyradio driver that sets parameters only if they are changed. This way flying 1 Crazyflie will not generate any more USB trafic than before #22 and flying more will be as efficient as possible.

Swarm example not working when the kalman filter does not converge.

When setting the anchor position in the autonomous flight examples, sometime the kalman filter does not converge which makes the Crazyflie crash as soon as we send the first setpoint. This happens more often if the Crazyflie has been powered-on a long time (ie. 30sec) before running the example.

To solve this we could reset the kalman filter and check that it has converged before sending setpoints.

Add possibility to connect more than 1 Crazyflie per program

Currently the Crazyflie lib is built on the assumption that one Python program connects to only one Crazyflie.

If we want to be able to fly swarm of Crazyflies using the lib, we need to be able to connect more than one Crazyflie.

One solution is to be able to create multiple Crazyflie object and to share Crazyradio.

Can not set height when MotionCommander is used as context manager

It is not possible to set the take off hight when the MotionCommander is used as context manager since the take_off() function is called implicitly. Add the height to the constructor to enable use like this

height = 1.4
with MotionCommander(cf, height) as mc:
    mc.forward(1.0)
    # ...

Pass Flake8

cflib is not passing the Flake8 tests yet, but we are not far!

The code should be fixed and flake8 should be added to tools/build/build to test in in CI.

error when excute the basiclog example

I connected the crazyflie then run the example, but it has this error:


Scanning interfaces for Crazyflies...
Crazyflies found:
No Crazyflies found, cannot run example
Traceback (most recent call last):
  File "basiclog.py", line 143, in <module>
    while le.is_connected:
NameError: name 'le' is not defined


How to fix it?

thank in advance!!

Make debian packages

Now that the project follows pypa recomendation it should be easier to create a Debian package. This would help with installing the client on Ubuntu.

Make flow deck demo smaller

The flow deck demo script (flowsequenceSync.py) runs a figure 8, but it is slightly big and it would be better to reduce the size of the flight path.

Connect to Crazyflies in a swarm in parallel

The connection phase of connecting to the crazyflies of a swarm takes a long time when using the Swarm class. The connections are executed in series and the process could be faster by running in parallel.

Add API for scripting sequences

Add an API with simple primitives that makes it easy to write scripts that flies the Crayzflie in a sequence. Hide the complexity of calling the Crazyflie commander at regular intervals and harmonize by making all dimensions behave in the same way as opposed to the Flow deck where X and Y is velocity while Z is absolute distance.

Tried to run basiclog example: ERROR: No module named examples

(venv) Shawn's Mac:crazyflie-lib-python Research$ python -m examples.basiclog
I am unable to run this example. Also could you please tell me, how should I edit the source code of the Crazyflie? Is there a tutorial? How to connect to crazyflie? GUI is not showing the radio transmitter platform option.
P.S. I don't have XBOX.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.