Page 1 of 1

Crazyflie Python Library

Posted: Sun May 05, 2013 3:31 pm
by danielsamuels
Hello,

I've been playing around with the Python library for the Crazyflie, unfortunately the documentation is a bit lacking so it's a bit of a challenge. I was just wondering if anyone else has used the library yet and if you've managed to get thrust into the Crazyflie?

I put together a very simple script to check if things were working, but I'm getting an interesting output. Here's the code I'm using:

Code: Select all

from cflib.crazyflie import Crazyflie
from cflib.utils import callbacks
import cflib.crtp

def connected(linkURI):
    print "Connected!"

def connectSetupFinished(linkURI):
    print "connectSetupFinished"

    roll    = 0.0
    pitch   = 0.0
    yawrate = 0
    thrust  = 9
    crazyflie.commander.send_setpoint(roll, pitch, yawrate, thrust)


crazyflie = Crazyflie()
cflib.crtp.init_drivers()

crazyflie.open_link("radio://0/10/250K")

crazyflie.connected.add_callback(connected)
crazyflie.connectSetupFinished.add_callback(connectSetupFinished)
..and here's what I'm getting back:

Code: Select all

G:\Python\Sites\crazyflie>main2.py
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while scheduling new one on [5]
Connected!
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will probably not succeed
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
connectSetupFinished
I'm getting the logging output because I put logging.basicConfig() into cfib.crazyflie.__init__. Anyone had any luck with the library / does anyone have any suggestions on where I should be looking to get some thrust going?

Cheers,
Daniel.

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 5:35 pm
by tobias
Hi Daniel,

It might actually be that the Crazyflie firmware doesn't do anything before the trust is above 10000 (decimal). https://bitbucket.org/bitcraze/crazyfli ... ault#cl-35
Try increasing the thrust in your code to 10001 and try again and I think it will work. Ohh and 10001 will not be enough for the Crazyflie to take off :)

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 6:03 pm
by danielsamuels
Perfect, that's given me a great place to start. Propellers are now spinning! Don't know why I didn't try a higher number to be honest.

Thanks!

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 6:15 pm
by tobias
And the 10000 min limit I can't recall why it is there. I think it is an inheritance from the time we used analog sensors over a year ago... :)
Ohh, and you need to send values at least twice a second, 2Hz, or the commander watchdog will go in. I would recommend at least 25Hz. I think we are using 100Hz in the cfclient.

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 6:25 pm
by danielsamuels
I calculated the cut-out to be after 2 seconds (0.5Hz), is this not the case? This number is from both reading the firmware commander and from physical testing.

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 6:42 pm
by tobias
There are actually two steps. After 500ms it will try to level itself and after 2000ms it will cut the power.
https://bitbucket.org/bitcraze/crazyfli ... ault#cl-31
http://wiki.bitcraze.se/projects:crazyf ... _behaviour

It is nice to be able to link to at least some documentation :)

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 9:46 pm
by danielsamuels
I've posted a little code example onto the Wiki so people new to developing for the Crazyflie can get going a bit quicker. You can see it here.

Re: Crazyflie Python Library

Posted: Sun May 05, 2013 10:20 pm
by marcus
Nice work on fixing some of the errors on the page and creating a good example :D

Re: Crazyflie Python Library

Posted: Mon May 13, 2013 3:41 am
by jamisnemo
How did you actually import the python libraries into your own code? I'm kinda new to python so I don't know the best practice here.

I wanted to make a file named "stand_alone_thrust_test.py" in the root directory of the existing client repo but I can't figure out what import statements to use...

Do I need to set a path variable in my environment? Or "install" these libraries somehow?

Thanks for the help...

Re: Crazyflie Python Library

Posted: Mon May 13, 2013 9:09 am
by danielsamuels
jamisnemo wrote:How did you actually import the python libraries into your own code? I'm kinda new to python so I don't know the best practice here.

I wanted to make a file named "stand_alone_thrust_test.py" in the root directory of the existing client repo but I can't figure out what import statements to use...

Do I need to set a path variable in my environment? Or "install" these libraries somehow?

Thanks for the help...
For the most part, you should be able to download the client library from here, then just run ./setup.py install. You should then be able to import the modules as shown in the code example.