CrazyFlie 2 packet loss

Firmware/software/electronics/mechanics
Post Reply
ViktorChyzhdzenka
Beginner
Posts: 2
Joined: Tue Feb 14, 2017 11:59 am

CrazyFlie 2 packet loss

Post by ViktorChyzhdzenka »

Hello

I try to write communication in Win7x64 in C++ (libusb1.0.20, usb driver libusbK).

Almost all are work OK. But sometimes I lost packets from CrazyFlie2 (through radio dongle).
Log is below. (XXXX) - time on PC in ms, Tmsp - time from packet. I set 10ms period on logblock starting. '>' sent packet, '<' received packet.

Code: Select all

> (14972): Dummy
< (14992): Port: 5 Channel: 2 Id: 0 Tmsp: 4235890 Data(19): 00-72-A2-40-57-D2-59-3D-7C-0C-26-3F-1B-24-1B-43-11-27-2E- ack.pow: 0 ack.rtr: 4 ack.ack: 1
> (14993): Dummy
< (15009): Port: 5 Channel: 2 Id: 1 Tmsp: 4235897 Data(16): 01-79-A2-40-00-C0-DA-3E-00-40-1C-3F-00-A0-0C-40- ack.pow: 0 ack.rtr: 12 ack.ack: 1
> (15010): Dummy
< (15022): Port: 5 Channel: 2 Id: 0 Tmsp: 4235900 Data(19): 00-7C-A2-40-FB-EB-53-3D-97-22-26-3F-1A-24-1B-43-11-27-2E- ack.pow: 0 ack.rtr: 4 ack.ack: 1
> (15023): Dummy
< (15027): Port: 5 Channel: 2 Id: 1 Tmsp: 4235907 Data(16): 01-83-A2-40-00-30-F2-3F-00-00-FA-BE-00-BC-B1-40- ack.pow: 0 ack.rtr: 4 ack.ack: 1
> (15028): Dummy
< (15048): Port: 5 Channel: 2 Id: 0 Tmsp: 4235910 Data(19): 00-86-A2-40-56-95-4D-3D-C8-64-26-3F-FA-26-1B-43-11-27-2E- ack.pow: 0 ack.rtr: 4 ack.ack: 1
> (15049): Dummy
< (15069): Port: 5 Channel: 2 Id: 1 Tmsp: 4235917 Data(16): 01-8D-A2-40-00-B0-B3-3F-00-40-9C-BF-00-B4-DC-40- ack.pow: 0 ack.rtr: 4 ack.ack: 1
> (15070): Dummy
< (15092): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15093): Dummy
< (15115): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15116): Dummy
< (15138): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15139): Dummy
< (15161): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15162): Dummy
< (15184): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15185): Dummy
< (15201): Port: 5 Channel: 2 Id: 1 Tmsp: 4235947 Data(16): 01-AB-A2-40-00-80-3B-BF-00-00-7A-3F-00-C8-AF-C0- ack.pow: 0 ack.rtr: 12 ack.ack: 1
> (15202): Dummy
< (15224): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15225): Dummy
< (15243): Port: 5 Channel: 2 Id: 1 Tmsp: 4235957 Data(16): 01-B5-A2-40-00-C0-DA-3F-00-80-3B-BE-00-A0-0C-3F- ack.pow: 0 ack.rtr: 0 ack.ack: 1
> (15244): Dummy
< (15266): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
> (15267): Dummy
< (15269): Port: 5 Channel: 2 Id: 1 Tmsp: 4235967 Data(16): 01-BF-A2-40-00-00-7A-3F-00-A0-0C-BF-00-48-6E-40- ack.pow: 0 ack.rtr: 0 ack.ack: 1
> (15270): Dummy
< (15292): 0 byte_readed: 1 val: 0 ack.pow: 0 ack.rtr: 0 ack.ack: 0
Between (15069): Port: 5 Channel: 2 Id: 1 Tmsp: 4235917 and (15201): Port: 5 Channel: 2 Id: 1 Tmsp: 4235947 I have lost 2 packets for logblock with id=1.

This output after some parsing results of
libusb_bulk_transfer(hndl_, (0x01 | LIBUSB_ENDPOINT_OUT), data, size, &sz_written, 1000);
and
libusb_bulk_transfer(hndl_, (0x81 | LIBUSB_ENDPOINT_IN), data, size, &sz_read, 0)
is.


What the problem can be?
What can I did incorrect during initialization?
How can I fix this trouble?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: CrazyFlie 2 packet loss

Post by arnaud »

Hi,

It is normal to loose some downlink packets: the main reason will be that the Crazyflie comes with Bluetooth enabled and the bluetooth stack will take-over the radio at regular interval. When that happens communicating with the crazyradio will fail until the stack releases the radio. Downlink packet are implemented in using the ack messages and there is a chance that the uplink packet makes it and not the downlink, if that happens the downlink packet is lost. The communication algorithm in the Crazyflie have been designed to accepts safe uplink and unsafe downlink, for the log packet the concequence is to loose some packet sometime.

That said, I have implemented something I called "safelink" a while ago, it is implemented by the python lib and it is using the 2 spare bits of the CRTP header. The 2 bits are used as a packet counter that allows to detect lost or duplicated packet in any direction, this allows to have both a safe uplink and downlink.

Unfortunatly there is no documentation (yet) of how that work but there is the python implementation as reference: https://github.com/bitcraze/crazyflie-l ... #L418-L433. Safelink can be enabled by sending a 'magic' packet to the Crazyflie: https://github.com/bitcraze/crazyflie-l ... #L443-L452.

I have been meaning to implement safelink in the Crazyserver GO crazyflie client, when I do so I can write some documentation on how the safelink more works.
ViktorChyzhdzenka
Beginner
Posts: 2
Joined: Tue Feb 14, 2017 11:59 am

Re: CrazyFlie 2 packet loss

Post by ViktorChyzhdzenka »

Hi.

When I try to run 10 sends: FF 05 01.
I received:
size: 20 i: 0 data: 01-52-E-3C-31-21-C3-5A-38-BC-63-54-2A-3F-14-4D-5-C3-0-0-
size: 22 i: 1 data: 01-52-F-42-31-21-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
size: 20 i: 2 data: 01-52-E-A0-31-21-D7-5D-2F-BC-A7-3F-29-3F-24-4F-5-C3-0-0-
size: 22 i: 3 data: 01-52-F-A6-31-21-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
size: 20 i: 4 data: 01-52-E-4-32-21-42-DD-36-BC-1-E9-28-3F-54-51-5-C3-0-0-
size: 22 i: 5 data: 01-52-F-A-32-21-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
size: 20 i: 6 data: 01-52-E-68-32-21-BB-76-58-BC-37-F5-29-3F-65-53-5-C3-0-0-
size: 22 i: 7 data: 01-52-F-6E-32-21-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
size: 11 i: 8 data: 01-52-2-B7-32-21-64-C4-84-40-0-
size: 20 i: 9 data: 01-52-E-CC-32-21-7F-DF-56-BC-27-71-2A-3F-F6-54-5-C3-0-0-

Code: Select all

		for(int i=0; i<10; ++i)
		{
			uint8_t data[3] = {0xff, 0x05, 0x01};
			devs_[dev_index]->WriteData(data, 3);
			const int sz_buffer = 128;
			uint8_t buffer[sz_buffer];
			int bytes_readed = devs_[dev_index]->ReadData(buffer, sz_buffer);
			...
WriteData and ReadData is simple wrapper on
libusb_bulk_transfer(hndl_, (0x01 | LIBUSB_ENDPOINT_OUT), data, size, &sz_written, 1000);
and libusb_bulk_transfer(hndl_, (0x81 | LIBUSB_ENDPOINT_IN), data, size, &sz_read, 0).

May be this functionality is able only on some versions of firmware?
What firmware should be for CrazyFlie and RadioDoungle?

For now I have:
Device Descriptor Crazyradio PA USB Dongle
0 bLength 1 12h
1 bDescriptorType 1 01h Device
2 bcdUSB 2 0200h USB Spec 2.0
4 bDeviceClass 1 00h Class info in Ifc Descriptors
5 bDeviceSubClass 1 00h
6 bDeviceProtocol 1 00h
7 bMaxPacketSize0 1 40h 64 bytes
8 idVendor 2 1915h Linksys
10 idProduct 2 7777h
12 bcdDevice 2 0053h 0.53
14 iManufacturer 1 01h "Bitcraze"
15 iProduct 1 02h "Crazyradio PA USB Dongle"
16 iSerialNumber 1 1Dh "E7FD3CE7D5"
17 bNumConfigurations 1 01h

Is it possible to get firmware version form CrazyFlie?
Post Reply