USB port on crazyflie

Firmware/software/electronics/mechanics
Post Reply
pacman
Beginner
Posts: 6
Joined: Sun Nov 09, 2014 12:41 pm

USB port on crazyflie

Post by pacman »

Hello,

I want to use usb feature of the mainboard. But i couldnt find a good example explaining how to implement it. I think STM32_USB-FS-Device_Lib_V4.0.0 is useless and complicated for me. I have tried many times but nothing happens when i connect it to pc.

I want to log sensor values directly to pc. The dongle comm speed is too slow for that.
Could anyone guide me?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: USB port on crazyflie

Post by whoenig »

I am not sure how to use the USB on the STM32 either. However, what is the issue with the communication speed over the crazyradio? Do you have an issue with the latency or with the bandwidth? It is possible to get around 3ms latency. Even if you get USB to work, I am not sure if it would solve your problem. USB has good bandwidth, but only for cost of latency, i.e. if you want to send many small packets in real-time, USB won't help you.
pacman
Beginner
Posts: 6
Joined: Sun Nov 09, 2014 12:41 pm

Re: USB port on crazyflie

Post by pacman »

Whoenig,
Thank you for your reply.

Well, you are right. It comes with latency. But I dont know the latency of crazyradio as well as it also uses usb to communicate to pc.
At this point, there are 2 matters.

1) What is the communication payload of the default firmware on crazyradio link @2Mbps? What is the peak bandwith use on runtime (without logging, with inputs and other stuff).
2) What is the true latency of crazyradio @2Mbps? (if you say 3ms, is it comes default?)

I give the bandwith a higher priority, but the latency may be also important.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: USB port on crazyflie

Post by whoenig »

There is an interesting master thesis which contains bandwidth measurements here: http://liu.diva-portal.org/smash/record ... dswid=8523 (click on fulltext on the top right to access the full thesis).

1) The minimum the crazyflie needs to fly is the control command packet which is about 10 bytes. You can send it as often as you want - once every 10ms (100 Hz) is a good value. If you don't need to fly, nothing is used. There is nothing else required, hence you would have the rest of the bandwith yourself. The default firmware is limited to a 10ms update rate using the onboard logging mechanism. That way, you can send 32 bytes (the size of one packet) every 10ms, which leads to 3200 Bytes/s.
2) The 3ms don't come with the default firmware - you would need to write a custom one. In such the case the packet size is limited to 16 bytes though (if you use the full 32 bytes you achieve only 4ms latency). It is limited by USB which has a latency of 1ms.

Depending on what you want to do, latency or bandwith are more important: If you want a camera (or another sensor which creates a lot of data) you want maximum bandwidth. If you want to stream out the onboard sensors, the lowest latency is important. In fact, with 3ms of latency it is possible to run the control loop on the PC instead of on the flie (assuming that the radiolink is perfectly stable which is not always the case).
pacman
Beginner
Posts: 6
Joined: Sun Nov 09, 2014 12:41 pm

Re: USB port on crazyflie

Post by pacman »

Hi again.
Thank you for the detaied answer.

I'm a newbie to the Crazyflie. Im digging the code and trying to understand whats going on inside. In this case, it may take a few days till i get it.
Do you know a quick and dirty way to achieve 16kBps or much more i.e. 256kBps since the link is 2Mbps and that is theoretically achievable?

The other problem i have is i dont know to use the PC client. I cant log the GYRO+ACC data to a file. Im using latest version of the firmware (untouched) and the 2014.01.0 version of the PC client. I tried every tab, every menu option with no success :(
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: USB port on crazyflie

Post by whoenig »

2Mbps just means 2 Megabits per second, i.e. 2/8=0.25 MB/s = 250 kB/s. You can only achieve that if you buffer a lot (which increases latency again). For starters I would recommend going with the standard way of logging. There are two options:

1) You can write your own python script. There is a great example here: https://github.com/bitcraze/crazyflie-c ... asiclog.py. It would be fairly easy to extend this to write the received data to a file.
2) In the PC client in the Plot tab you can right click and select export. This way you would get the data as well.

The latency/bandwidth you achieve with a stock firmware should be good enough for most cases.
Post Reply