Runtime Updating Variables
Beginner Tutorials
Introducing GNU Radio Flowgraph Fundamentals
Creating and Modifying Python Blocks DSP Blocks
SDR Hardware |
This tutorial describes how to update variables while a flowgraph is running using QT GUI Widgets.
Please review the previous tutorial, Variables in Flowgraphs, for an introduction to variables. The next tutorial, Signal Data Types, discusses data types and representing complex and real signals in GNU Radio.
QT GUI Range
The GNU Radio block library comes with a handful of QT GUI widgets which allow a user to interact and change a flowgraph while it is running. The QT GUI Range creates a slider bar that can be used to update a variable.
Search for range in the block library:
Drag and drop the QT GUI Range block into the workspace:
The QT GUI Range acts similarly to a variable block. The default parameters for the QT GUI Range need to be set. Double-click on it to edit the properties. The QT GUI Range block will replace the frequency variable, so first change the Id field to frequency.
The Default Value is the value when the flowgraph starts. This can be set to 0. The Start and Stop are the start and stop values of the slider. Enter -samp_rate/2 as the start value, and samp_rate/2 as the stop value. The Step value is the resolution of the slider. In this example the Step is set to 100 Hz:
You will notice the message, ID "frequency" is not unique. This is because there is a variable and QT GUI Range both using the name frequency, which will be addressed shortly. Click OK to save the properties.
Right click on the variable block and select Disable, or press D:
The block is now ignored and the error is resolved.
Run the flowgraph by pressing the arrow or Play button:
The flowgraph will start with a frequency of 0, which is the default value entered into the QT GUI Range block:
The frequency parameter can then be updated by:
- Dragging the slider bar
- Entering a value
- Click up or down arrows (which moves by the Step size)
The frequency has been updated to -5000 which is reflected in the frequency spectrum plot.
QT GUI Chooser
The QT GUI Chooser allows a user to create a drop-down menu of options for a variable. Navigate the block library: Core, GUI Widgets, QT, and drag and drop QT GUI Chooser into the workspace.
The default parameters for the Chooser need to be updated. The Chooser allows the user to create a pre-made list of options for a user to select from in real time. As an example, three frequencies will be used: 0, 1000 and -2000. Update the following properties:
- Id: frequency
- Default Option: 0
- Option 0: 0
- Label 0: Frequency: 0
- Option 1: 1000
- Label 1: Frequency: 1000
- Option 2: -2000
- Label 2: Frequency: -2000
The Option field is the actual value of the variable, whereas Label is a text description that will be displayed to the user in a drop-down menu.
Click OK to save the parameters. Running the flowgraph will select the default value, Frequency: 0 which can be seen in the frequency spectrum as well as the drop-down box in the upper left hand corner:
The values can be selected drop-down menu by clicking on the drop-down menu. In this case, click on Frequency: 1000:
The frequency is then updated to the value entered into the QT GUI Chooser, which is 1000, seen in the frequency spectrum:
The next tutorial, Signal Data Types, discusses data types and representing complex and real signals in GNU Radio.