Format of instructions/ack

Firmware/software/electronics/mechanics
Post Reply
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Format of instructions/ack

Post by e-Rok »

I've sifted through the CRTP code to figure out the instructions/ack of the Commander using a Crazyradio to a quadrotor. I have a couple of questions about this process. From my understanding, the packet sent is a CRTPPacket() containing the port that the packet comes from, and the data. The data consists of the format of each log variable followed by each variable value. This is sent in the crazyradio interface to a crazyflie using pyusb.
From pyusb, data is written to a register which is read by the nrf24 dongle and sent to a receiving nrf24 dongle and interpreted. Then, an ack is read, which is sent back from the receiving nrf24 dongle.
The ack format is specified in the crazyradio.py module. How/where is this format formed and sent by the receiving node back to the transmitting node? How can it be changed, can it only be done by editing the firmware, or can it be done at a higher level?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Format of instructions/ack

Post by whoenig »

I think your summary is mostly correct. However, the log data does not contain the data type every time. Once you request which values you want to log, the datatype is looked up in the TOC. Every log chunk just contains the raw values binary packed. The result is formed in the firmware itself, so you would need to change the firmware if you want to update the format. Please also note that sending and receiving is not synchronous. That means, even though you do get an ACK back it is typically not the ACK which was formed based on what you just sent. Instead, the firmware has a queue which is filled and on every ACK one element from that queue is sent. The client makes sure that it sends empty commands from time to time just to be able to receive more data from this queue.
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Re: Format of instructions/ack

Post by e-Rok »

I cloned your edited code from github that allows the crazyradio to be put into PRX mode. In the firmware, am I correct in stating that the following is where acknowledgements are formed and sent?:

from main.c:

Code: Select all

    case RADIO_MODE_PRX:
      {
        if (!radioIsRxEmpty())
        {
          ledSet(LED_GREEN, true);
          IN1BC = radioRxPacket(IN1BUF);
        }
        //Send a packet if something is received on the USB
        if (!(OUT1CS&EPBSY) && !contCarrier)
        {
          //Deactivate the USB IN
          IN1CS = 0x02;

          //Fetch the USB data size. Limit it to 32
          tlen = OUT1BC;
          if (tlen>32) tlen=32;

          radioAckPacket(0, OUT1BUF, tlen);

          //reactivate OUT1
          OUT1BC=BCDUMMY;
        }
from radio.c:

Code: Select all

//Send a packet as acknoledgment payload
void radioAckPacket(char pipe, __xdata char* payload, char len)
{
  int i;

  RADIO_EN_CS();

  /* Send the read command with the address */
  spiRadioSend(CMD_W_ACK_PAYLOAD(pipe));
  /* Read LEN bytes */
  for(i=0; i<len; i++)
    spiRadioSend(payload[i]);

  RADIO_DIS_CS();
}
I see that OUT1BUF is the data sent. I can't figure out two things. How does spiRadioSend() work in the radio.c file? Second, the format of the data packet seems to be decided in commander.py and the format of the ack is decided in crazyradio.py, so why would I need to touch the firmware?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: Format of instructions/ack

Post by whoenig »

Nice progress - I think you are on the right track!

1. I did not write spiRadioSend(). From what I understand, the way it works is that you write a byte to a specific address and wait until the ready flag is clear. The nrf-chip has SPI support in hardware and more details should be in its datasheet.
2. Both communication partners need to agree on a data format. If you would change the format in commander.py or crazyradio.py only and not in the firmware there is no agreement anymore.
Post Reply