USB Radio: Difference between revisions

From Distributed Autonomous and Networked Control Lab
Jump to navigation Jump to search
Jnoronha (talk | contribs)
m Formatted code to have boxes around them
Jnoronha (talk | contribs)
Finished Radio Initialization Section
Line 66: Line 66:
</blockquote>
</blockquote>


:4. (OPTIONAL) Modify Radio Parameters
<blockquote>
<code>
<pre>
crRadio1->setARDTime(2000);    //Sets Wait Time (in &mu;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)
</pre>
</code>
</blockquote>
:5. '''Always''' Delete Radio Pointers Before Ending Program
<blockquote>
<code>
<pre>
delete crRadio1;
delete crRadio2;
</pre>
</code>
</blockquote>
'''Note:''' If you don't delete the pointers then you need to unplug the Radio and plug it back into the USB!
=== Changing Radio Channel ===
=== Changing Radio Channel ===

Revision as of 18:42, 9 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

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!

Changing Radio Channel