USB Radio: Difference between revisions

From Distributed Autonomous and Networked Control Lab
Jump to navigation Jump to search
Jnoronha (talk | contribs)
m Updated Navigation Bar
Jnoronha (talk | contribs)
m →‎How does it work?: modified directory
 
Line 135: Line 135:


Which is using a libusb command <code> writeControl </code> to find the specific USB address of the Radio and write a new Channel to that USB device. The specific values plugged into this function will need to be looked up if you plan on working at this level.
Which is using a libusb command <code> writeControl </code> to find the specific USB address of the Radio and write a new Channel to that USB device. The specific values plugged into this function will need to be looked up if you plan on working at this level.




----
----
<center> '''Main Directory''' </center>
<center> [[Crazyflie Swarm|Crazyflie Swarm Home]]  |  [[PC Client Software]]  |  [[USB Radio]]  |  [[Firmware]]  |  [[FAQ]] </center>


<center> [[Crazyflie Swarm]] | [[PC Client Software]] | [[USB Radio]] | [[Firmware]] </center>
<center> '''Modifications Directory''' </center>
<center> [[Controller]]  |  [[Logging]] | [[Keyboard Commands]] | [[USB Radio#Changing Radio Channel|Changing Radio Channel]]  |  [[Flight Modes]]  |  [[Callbacks]]  |  [[Adding a Crazyflie]] | [[Firmware]] </center>

Latest revision as of 18:58, 20 July 2016

The USB Radio Dongle acts as the bridge between the Client and the Firmware. It sends control setpoints generated from the Client to the Firmware controllers, as well as receives sensor data from the Firmware to the Client for logging.

Modifying the Radio

The Radio functions can be found in the CCrazyRadio.cpp source file.

Radio Initialization

The following steps are how to Initialize a Radio. This code is currently run at the start of main in eris_vrpn.cpp. The process below can be extended to any number of Radios (currently 2 Radios shown)

1. Create CrazyRadio Pointers and Crazyflie Pointers


CCrazyRadio *crRadio1 = 0;
CCrazyRadio *crRadio2 = 0;

CCrazyflie *cflieCopter1 = 0;
CCrazyflie *cflieCopter2 = 0;
CCrazyflie *cflieCopter3 = 0;
CCrazyflie *cflieCopter4 = 0;

Note: You must have a pointer for EACH Radio you want to initialize.

2. Initialize First CrazyRadio

crRadio1 = new CCrazyRadio(0);   // dongle number (starting at 0)
if( crRadio1->startRadio() )   //assigns pointer to USB location
{
	cflieCopter1 = new CCrazyflie(crRadio1, 5);   //Assigns Crazyflie1 to Radio1 on Channel 5 
	cflieCopter2 = new CCrazyflie(crRadio1, 80);  //Assigns Crazyflie2 to Radio1 on Channel 80
}
else 
{ 
        std::cerr << "Could not connect to dongle 1. Did you plug it in?" << std::endl; 
        exit(-1); 
} 
usleep(10000);

3. Initialize Second CrazyRadio (repeat as necessary...)

crRadio2 = new CCrazyRadio(1); // dongle number

if( crRadio2->startRadio() ) 
{
		cflieCopter3 = new CCrazyflie(crRadio2, 25);   //Assigns Crazyflie3 to Radio2 on Channel 25
		cflieCopter4 = new CCrazyflie(crRadio2, 45);   //Assigns Crazyflie4 to Radio2 on Channel 45
} 
else 
{ 
        std::cerr << "Could not connect to dongle 2. Did you plug it in?" << std::endl; 
        exit(-1); 
} 

usleep(10000);

4. (OPTIONAL) Modify Radio Parameters


crRadio1->setARDTime(2000);     //Sets Wait Time (in μs) between Packet Retries  (**MUST BE IN INCREMENTS OF 250**)
crRadio1->setARC(0);		//Sets Number of times Retries Packet Send
crRadio1->setPower(P_0DBM);     //Sets Radio Power (See CCrazyRadio.h for allowed ENUM values)

5. Always Delete Radio Pointers Before Ending Program


delete crRadio1;
delete crRadio2;

Note: If you don't delete the pointers then you need to unplug the Radio and plug it back into the USB!

How does it work?

The Radio initialization was originally only able to support a single Radio per computer and a single Crazyflie per Radio. This was a result of how the openUSBDongle() function was written.

Originally the code worked as follows:

The issue with this is that if you want to assign another Radio it will always point to the same USB address, thus the different Radio pointers crRadio1 and crRadio2 would point to the same Radio dongle. So we modified the openUSBDongle() to take in the number of Radios you want to start, and then initialize them with a loop.

Changing Radio Channel

Changing the Radio Channel is easy, all you need to do is call the function:


crRadio1->setChannel( cflieCopter1->radioChannel() );     //Sets Radio channel to whatever value cflieCopter1 was assigned (The input can be replaced with a constant if needed)

How does it work?

The low level implementation of the setChannel function looks like this:

 
void CCrazyRadio::setChannel(int nChannel) {
    if( ALL_THE_DEBUG ) printf( "%s(nChannel:%d)\n", __FUNCTION__, nChannel  );

    this->writeControl(NULL, 0, 0x01, nChannel, 0);
}

Which is using a libusb command writeControl to find the specific USB address of the Radio and write a new Channel to that USB device. The specific values plugged into this function will need to be looked up if you plan on working at this level.



Main Directory
Crazyflie Swarm Home | PC Client Software | USB Radio | Firmware | FAQ
Modifications Directory
Controller | Logging | Keyboard Commands | Changing Radio Channel | Flight Modes | Callbacks | Adding a Crazyflie | Firmware