No dongle -- no exception

Post here to get support
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

No dongle -- no exception

Post by hdmathias »

I'm having a strange problem with my Crazyflie under Windows so I've been experimenting. Tonight, I saw very odd behavior.

First, my problem. I have the Crazyflie client installed in Windows and also in a Linux VM. In the VM, I can fly both from the client and from the command line. In Windows, I can fly using the client but not from the command line. When I try, I get the message, "No Crazyflies found, cannot run example." I've posted about that in the Crazyflie Developer forum: http://forum.bitcraze.se/viewtopic.php?f=6&t=1046

Tonight I was checking my installation and it seems like it is OK. So then I decided to try various things. First up, run ramp.py with no Crazyradio attached. I expected to get the exception defined in __inti__ Crazyradio.py: "Cannot find a Crazyradio Dongle." To my surprise, I didn't. Even with no dongle attached, I get the following output:
Scanning interfaces for Crazyflies...
Crazyflies found:
No Crazyflies found, cannot run example

Is this behavior normal? Shouldn't the exception be thrown if no dongle is attached? This has me confused. My students and I would very much like to get the command line working in Windows so that we can develop for the Crazyflie (there are a couple of reasons that we'd like to use Windows rather than Linux at this point). Any help appreciated.

Thanks.

David
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: No dongle -- no exception

Post by whoenig »

I just tested it and this is normal. However, the exception is still thrown but caught by the python program so that it is not visible to the user. Specifically, radiodriver.py line 204 tries to create a Crazyradio object and returns an empty list in case of an failure.

I used the following "trick" to see the exception:
1. Open ramp.py in PyCharm (https://www.jetbrains.com/pycharm/; Community edition is enough but it is also possible to get the Pro version for free if you are in academia)
2. In menu Run/View Breakpoints select under "Activation Policy" the "On Raise" option (at each level preferably to see exactly what happens)
3. Select Run/Debug to start the debugging

This should stop at the first exception and you can inspect the state (variables etc.) in the debugger. This might also help you with your original problem to see how the behavior differs if the dongle is attached.

I did use ramp.py on Windows (7) and Linux successfully before and I can confirm that it should work! Which Windows version are you using?
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

Re: No dongle -- no exception

Post by hdmathias »

Thanks. I'm running Windows 7. It seems as if all of the dependencies are installed correctly. After seeing your reply, I installed PyCharm but I don't have the CrazyRadio and Crazyflie here at home over the holiday weekend. Will have a look at it at work this week.
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

Re: No dongle -- no exception

Post by hdmathias »

After playing with things some more, I have additional information. Previously, the Crazyradio was not being found. It seems that is not currently the case. Looking at values in crazyradio.py when running ramp.py, I see:
pyusb1 is false // output from a print statement I added
device = <usb.core.Device object at 0x026DA830>

It appears to die in the self.handle = self.dev.open() call. I see the result of a print statement immediately before that call but not immediately after. The next output I see is from ramp.py:
Crazyflies found:
No Crazyflies found, cannot run example

So it appears to find the Crazyradio. However, I still get no Crazyflies found. As before, the Crazyflie is found, and can fly, from within the client.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: No dongle -- no exception

Post by whoenig »

Did you happen to use PyCharm to see if there is an exception thrown? It sounds like the open() call triggers some exception and it would be good to know what it is (sometimes it contains additional details). An open call can fail for security reasons or if the device is in use by another applications - both are things which you checked before...
At least it looks like your pyusb installation is fine, which is already a good thing!
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

Re: No dongle -- no exception

Post by hdmathias »

PyCharm shows a lot of exceptions. There are a few "index out of range" exceptions early on but the program continues to run so I suspect that they aren't problematic. Then there are several dozen exceptions while looking for the usb library but it finds the library where I have it installed so I think that's ok. Immediately after it finds the library, I get the exception below and the program terminates soon after with the "No Crazyflies found" message. I find this error strange. It is thrown during the self.dev.open() call in crazyradio.py

Attribute error: 'Device' object has no attribute 'open', traceback object at 0x03830558
device = {Device} <usb.core.Device object at 0x028B3FF0>
devid = {int} 0
self = {instance} Crazyradio: <cflib.drivers.crazyradio.Crazyradio instance at 0x0288E2B0>
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: No dongle -- no exception

Post by whoenig »

Thank you for running all those tests! I believe the issue is that your normal cfclient somehow uses a different pyusb version. One thing which should change things for sure is installing pyusb 1.0. You can find it here: https://github.com/walac/pyusb along with some documentation on how to install it on Windows. Once that is installed, it should use a completely different code path in crazyradio.py. (And hopefully work!)
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

Re: No dongle -- no exception

Post by hdmathias »

Thank you -- I really appreciate your continued support.

I have pyusb1.0.0a2 installed. Thinking that perhaps it wasn't installed properly, this morning I reran the "python setup.py install" command as an administrator. No change in the behavior when I run ramp.py. pyusb is in the directory c:\Python27\Lib\site-packages\pyusb1.0.0a2. Is that the right location. It's from that directory that I've run the installation program. My libusb0.dll is in c:\Windows\System32 (as I mentioned yesterday, the library is found when I run ramp.py).

David
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: No dongle -- no exception

Post by whoenig »

The folder sounds right to me. The issue is that when you run ramp.py, python does not seem to load pyusb correctly (you mentioned earlier that pyusb1==False), it falls back to pyusb0.x, which has another interface. PyUsb1.x does not have the open function, hence that fails later on.
1.) Can you use PyCharm (or add print statements) to find out which part of the pyusb1 detection (line 60 to 65 in crazyradio.py) fails? I believe only one of those import statements should be able to throw an exception.
2.) Try to remove lines 62 to 65. Technically those shouldn't be required as pyusb1 should find its backend automatically.
hdmathias
Member
Posts: 47
Joined: Sat Nov 01, 2014 3:24 pm
Location: Florida, USA

Re: No dongle -- no exception

Post by hdmathias »

OK, I understand a bit better now. I'll figure out why pyusb1 isn't found. I may try to remove pyusb, redownload and reinstall. It may be a couple of days before I'm able to work on it again. Thanks.
Post Reply