CRTP Question

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

CRTP Question

Post by e-Rok »

Hi,

I'm trying to wrap/modify the RadioDriver and Log classes to send/receive instructions and variable values through two CrazyRadio dongles. Threading is a bit over my head. My question is about the threading in the radiodriver.py module.

In the RadioDriver._thread.run() method, the data is sent by the local cradio passed from the RadioDriver class, which is loaded from the dataOut array:

Code: Select all

        dataOut = array.array('B', [0xFF])
        waitTime = 0
        emptyCtr = 0

        while(True):
            if (self.sp):
                break

            try:
                ackStatus = self.cradio.send_packet(dataOut)
In the RadioDriver class, there is a send_packet method, which loads up an out_queue (for tx). This data is then queued in the RadioDriver._thread.run() method. I have a couple of questions about this process.
What does [0xFF] in the data array represent?
Where in this project is the data loaded into the out_queue, because it is not used in the scope of this module or in any of the CRTPDriver classes?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: CRTP Question

Post by whoenig »

1. The array is initialized as unsigned char with one byte as message (0xFF hex is 255 decimal). The radio chip has two modes: PRX and PTX. The Crazyradio operates as PTX, i.e. is the master transmitter. If it does not have to send anything, it still needs to send "fake-messages" in order to receive something back. Those 0xFF are the minimal messages. If you look further in the code, you can see that outData is filled with that message every time the queue is empty.
2. Same file, line 162, i.e. whenever the user calls the send_packet function.
3. I think the threading was mainly done in order to be able to receive data as fast as possible. Since this requires polling (PTX mode), there needs to be a thread to check frequently. Because the Crazyradio is a shared resource, the queue had to be introduced.

If you want 2 Crazyradios to communicate, you will need to put one of them into PRX mode. There was another forum-thread on how to do that recently.
e-Rok
Beginner
Posts: 25
Joined: Fri Sep 12, 2014 4:30 pm

Re: CRTP Question

Post by e-Rok »

You've sort of answered my question. Outside of the scope of this module, where is radiodriver.RadioDriver.send_packet() called? I understand that the user must call it, but which module in this project actually instantiates RadioDrivers and communicates packets with other radios?
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: CRTP Question

Post by whoenig »

There seem to be a number of places. The interface gets initialized in lib/cflib/crazyflie/__init__.py:open_link. This is later on passed down to several places for logging, parameters, and setting the setpoint, e.g. cflib/crazyflie/commander.py.
Post Reply