bitcraze / crazyflie-lib-python Goto Github PK
View Code? Open in Web Editor NEWPython library to communicate with Crazyflie
License: Other
Python library to communicate with Crazyflie
License: Other
Related to bitcraze/crazyradio-firmware#28, when running the lib in virtualbox the USB communication sometime crash because reading the radio ack returns None. Since it does not seem to crash completely the communication there might be a way to ignore the communication error and continue communicating.
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.
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
We need an example to show how to control a swarm of Crazyflie using cflib. This requires #22 to be fixed.
Add support for the packet defined by bitcraze/crazyflie-firmware#197.
I notice you add the printing position in autonomousSequence.py, it's worked. But I try to add the printing in swarmSequence.py, I failed. I don's know how to add the callback to each crazyflie. Thanks.
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!!
There is a typo that broke sending external position to the Crazyflie
In issue bitcraze/crazyflie-firmware#198, the memory sub system is used to transfer Loco Positioning anchor positions to a client. Add support in the lib to read that memory.
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.
Add support for new commander packet, see bitcraze/crazyflie-firmware#113
Also related to bitcraze/crazyflie-clients-python#280
Some log data has changed when altitude hold was updated.
See bitcraze/crazyflie-firmware#98 and bitcraze/crazyflie-clients-python#246
Update names in the debug driver to match the FW.
Names to update:
baro.aslLong -> posEstimatorAlt,estimatedZ
altHold.target -> posCtlAlt.targetZ
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)
# ...
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.
We should add the external position message implemented by bitcraze/crazyflie-firmware#147 in the lib to allow python programs to send to the Crazyflie its current measured position (for example to implement a camera-base Crazyflie tracking).
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.
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.
The issue bitcraze/lps-node-firmware#22 implements a LPP packet that can be used to set the anchor mode. It should be supported by the lib.
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.
Based on my issue that I created in the client, are you interested in using any of these tools for the package?
The crazyflie bootloader code seems to be calling the radio link close method when the link is not connected. This should be ignored instead of crashing.
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()
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.
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.
Add support for the new localization generic packet type and for the LPS ranging report implemented by bitcraze/crazyflie-firmware#196
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.
There should be support for: bitcraze/crazyflie-firmware@eae6093
The lib seems to be broken on python2. At least the ramp.py example is not working. See https://forum.bitcraze.io/viewtopic.php?f=6&t=2522&e=1.
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.
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
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.
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`
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...
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!
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.
(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.
Create a basic example showing the functionality of the multi-ranger/OA deck.
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:
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')
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?
The ZDistance commander packet added in the firmware for bitcraze/crazyflie-firmware#211 should be supported by the lib.
The version here is 0.1.2, but cfclient is looking for 0.1.3.
'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?
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.
On request from the forum, print the estimated position when the sequence is executing.
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.
There has been a couple of power-management related bootloader packet added by the pull request bitcraze/crazyflie2-nrf-firmware#18. These should be added to be usable in the lib.
Add support to send a message to reboot the anchors to bootloader or firmware mode.
Related to bitcraze/lps-node-firmware#13.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.