Crazyflie Python Library

Firmware/software/electronics/mechanics
Post Reply
danielsamuels
Beginner
Posts: 14
Joined: Sun May 05, 2013 3:21 pm

Crazyflie Python Library

Post 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.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie Python Library

Post 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 :)
danielsamuels
Beginner
Posts: 14
Joined: Sun May 05, 2013 3:21 pm

Re: Crazyflie Python Library

Post 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!
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie Python Library

Post 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.
danielsamuels
Beginner
Posts: 14
Joined: Sun May 05, 2013 3:21 pm

Re: Crazyflie Python Library

Post 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.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie Python Library

Post 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 :)
danielsamuels
Beginner
Posts: 14
Joined: Sun May 05, 2013 3:21 pm

Re: Crazyflie Python Library

Post 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.
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Crazyflie Python Library

Post by marcus »

Nice work on fixing some of the errors on the page and creating a good example :D
jamisnemo
Beginner
Posts: 9
Joined: Fri May 10, 2013 10:23 pm

Re: Crazyflie Python Library

Post 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...
danielsamuels
Beginner
Posts: 14
Joined: Sun May 05, 2013 3:21 pm

Re: Crazyflie Python Library

Post 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.
Post Reply