This is the GNU Radio UHD package. It is the interface to the UHD library to connect to and send and receive data between the Ettus Research, LLC product line. To use the UHD blocks, the Python namespaces is in gnuradio.uhd, which would be normally imported as:
The relevant blocks are listed in the UHD Interface group. The most important components are the gr::uhd::usrp_source and gr::uhd::usrp_sink blocks, which act as receivers/transmitters. Both are derived from gr::uhd::usrp_block, which defines many of the shared functions between those blocks.
Ettus Research maintains the comprehensive documentation to the underlying UHD driver, which can be found at:
http://files.ettus.com/manual/
The list of classes in the UHD Doxygen is located at:
http://files.ettus.com/manual/annotated.html
The UHD sink and source can be controlled by a message port. These message ports take commands, which are PMTs formatted as described in Using messages as commands.
In general, every command consists of one or more key/value pairs (either stored as a PMT pair, or a dictionary). A full list of keys is listed below.
Example:
This PMT would set the frequency to 1.1 GHz on all channels. We make use of the pmt::mp() function which automatically sets the PMT types. Assume we only want to set the frequency on channel 1 (i.e. the second channel). In this case, we must construct a dictionary:
This command structure becomes more intuitive when thinking of sending the command PMT as a function call, where the key/value pairs are argument names and values, respectively. In the above example, the behaviour is the same as if calling
The main difference is that we can add more properties to the same command PMT, e.g. as such:
When the USRP block interprets this command PMT, all properties will be set.
The following command keys are understood by both UHD Source and Sink:
Command name | Value Type | Description |
---|---|---|
chan | int | Specifies a channel. If this is not given, either all channels are chosen, or channel 0, depending on the action. A value of -1 forces 'all channels', where possible. |
gain | double | Sets the Tx or Rx gain (in dB). Defaults to all channels. |
power_dbm | double | Sets the Tx or Rx power reference level (in dBm). Defaults to all channels. Works for certain devices only, and only if calibration data is available. |
freq | double | Sets the Tx or Rx frequency. Defaults to all channels. If specified without lo_offset , it will set the LO offset to zero. |
lo_offset | double | Sets an LO offset. Defaults to all channels. Note this does not affect the effective center frequency. |
tune | tune_request | Like freq, but sets a full tune request (i.e. center frequency and DSP offset). Defaults to all channels. |
mtune | tune_request_t | Like tune, but supports a full manual tune request as uhd::tune_request_t. Defaults to all channels. |
lo_freq | double | For fully manual tuning: Set the LO frequency (RF frequency). Conflicts with freq , lo_offset , and tune . |
dsp_freq | double | For fully manual tuning: Set the DSP frequency (CORDIC frequency). Conflicts with freq , lo_offset , and tune . |
direction | string | Used for timed transceiver tuning to ensure tuning order is maintained. Values other than 'TX' or 'RX' will be ignored. |
rate | double | See usrp_block::set_samp_rate(). Always affects all channels. |
bandwidth | double | See usrp_block::set_bandwidth(). Defaults to all channels. |
time | timestamp | Sets a command time. See usrp_block::set_command_time(). A value of PMT_NIL will clear the command time. |
mboard | int | Specify mboard index, where applicable. |
antenna | string | See usrp_block::set_antenna(). Defaults to all channels. |
gpio | gpio | PMT dictionary including bank, attr, value, mask for GPIO. See notes. |
stream_cmd | dict (stream command) | PMT dictionary mirroring UHD's stream_cmd_t. Supported by RFNoC RX Radio. See below for details. |
Special types:
gpio
command calls set_gpio_attr
with the elements from the dictionary as arguments. Can optionally contain mboard
to specify the mainboard. Defaults to 0
(first mboard).stream_mode
, num_samps
, time_spec
, and stream_now
.Further notes on command mtune
:
The object is of type pmt::dict and has the same fields as uhd::tune_request_t:
dsp_freq
: the dsp frequency as pmt double type.dsp_freq_policy
: policy for DSP tuning. Should be a string "A" (automatic), "M" (manual) or "N" (none). If not set, defaults to "A".rf_freq
: the rf frequency as pmt double type.rf_freq_policy
: policy for RF tuning. Should be a string "A" (automatic), "M" (manual) or "N" (none). If not set, defaults to "A".target_freq
: target frequency (for automatic running) as pmt double typeargs
: string containing additional arguments, for example for integer N tuning.Further notes on command stream_cmd
:
The object is of type pmt::dict and has the same fields as uhd::stream_cmd_t:
stream_mode
: This is a string (not an enum or int) and takes the same values as the UHD Python API uses for stream modes (start_cont
, stop_cont
, num_done
, and num_more
).stream_now
: Booleantime_spec
: When stream_now
is false, this is the absolute time when the stream command is executed.num_samps
: When stream_mode
is num_done
, this is the number of samples that will be received.Example:
Note: Not all commands are affected by time
. See the UHD manual for details on timed commands.
Given the choices, it may be unclear if it's preferable to send multiple commands to the USRP block with a single key/value pair each, or send a single dict with all the values.
In general, the dictionary should be preferred. It has some distinct advantages:
A typical option parser setup for a UHD device looks like
To use these options to create a UHD source object:
Frequently, your application may need a sample rate that is not supported by the UHD device. If you have extra CPU power to spare, you can easily set the sample rate you want, then ask the device what the actual sample rate set was. Then, you can easily create an arbitrary resampler to take care of the difference.
gr-uhd will emit log messages when unexpected events occur.
For under- and overflows, as well as command time errors, since these tend to happen in high-rate scenarios, such errors are counted for logging intervals. The first error after a time longer than the logging interval has passed is logged immediately, but subsequent log entries are accumulated.
The logging interval can be configured using the GNU Radio preferences framework (i.e. gnuradio.conf file), as follows:
It is an integer that defaults to 750, representing the minimum number of milliseconds between logged under-, overflow events or command time errors.