Runtime Updating Variables: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
No edit summary
 
(29 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div style="float:right">
{{Template:BeginnerTutorials}}
</div>
This tutorial describes how to update variables while a flowgraph is running using QT GUI Widgets.


This section will describe how to update variables while a flowgraph is running using QT GUI Widgets. Please review the previous tutorial,  
Please review the previous tutorial, [[Variables_in_Flowgraphs|Variables in Flowgraphs]], for an introduction to variables. The next tutorial, [[Signal_Data_Types|Signal Data Types]], discusses data types and representing complex and real signals in GNU Radio.
[[Variables_in_Flowgraphs|Variables in Flowgraphs]], for an introduction to variables.


=='''QT GUI Range'''==
==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.
The GNU Radio block library comes with QT GUI widgets. The widgets allow interaction and modification to a flowgraph while running. The ''QT GUI Range'' widget creates a slider bar that can be used to update a variable.


Search for ''range'' in the block library:
Search for ''range'' in the block library:


[[File:SearchQTGUIRange.png|700px]]
[[File:SearchQTGUIRange.png|700px]]


Drag and drop the ''QT GUI Range'' block into the workspace:
Drag and drop the ''QT GUI Range'' block into the workspace:
Line 17: Line 19:




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 ''QT GUI Range'' works like a variable block. The default parameters for the ''QT GUI Range'' need to be set. Double-click on the ''QT GUI Range'' block 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:
The ''Default Value'' is the value when the flowgraph starts. Set the ''Default Value'' 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:


[[File:SetRangeProperties.png|500px]]
[[File:SetRangeProperties.png|500px]]


An error message is displayed:
<pre>ID "frequency" is not unique.</pre>


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.
The error message is displayed because there a variable block and the QT GUI Range are both using the name ''frequency''. This problem will be addressed shortly. Click ''OK'' to save the properties.


Right click on the variable block and select ''Disable'', or press ''D'':
Right click on the variable block and select ''Disable'', or press ''D'' on the keyboard:


[[File:DisableVariableBlock.png|700px]]
[[File:DisableVariableBlock.png|700px]]
Line 35: Line 40:




Run the flowgraph by pressing the arrow or ''Play'' button:
Run the flowgraph by clicking the arrow or ''Play'' button:


[[File:RunFlowgraphButton.png|300px]]
[[File:RunFlowgraphButton.png|300px]]




The flowgraph will start with a frequency of 0, which is the default value entered into the ''QT GUI Range'' block:
The flowgraph starts with a frequency of 0, the default value entered into the ''QT GUI Range'' block:


[[File:QTGUIRangeDefaultValue.png|700px]]
[[File:QTGUIRangeDefaultValue.png|700px]]
Line 48: Line 53:
# Dragging the slider bar
# Dragging the slider bar
# Entering a value
# Entering a value
# Click up or down arrows (which moves by the ''Step'' size)
# Click up or down arrows


[[File:QTGUIRangeDragSlider.png|700px]]
[[File:QTGUIRangeDragSlider.png|700px]]


The frequency has been updated to -5000 which is reflected in the frequency spectrum plot.
The frequency has been updated to -5000 which is reflected in '''<span style="color:orange">orange</span>''' in the frequency spectrum plot.


=='''QT GUI Chooser'''==
==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 ''QT GUI Chooser'' creates 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.


[[File:QTGUIChooserLibraryBlock.png|700px]]
[[File:QTGUIChooserLibraryBlock.png|700px]]




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:
Update the default parameters for the ''Chooser'' block. The ''Chooser'' creates a list of options to select from while the flowgraph is running. In this example three frequencies are used: 0, 1000 and -2000. Update the following properties in the ''Chooser'' block:


# ''Id'': frequency
# ''Id'': frequency
Line 72: Line 77:
# ''Label 2'': Frequency: -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.
The ''Option'' field is the value of the variable, ''Label'' is a text description that is displayed in the drop-down menu. The image shows an example of the ''Option'' being highlighted in '''<span style="color:orange">orange</span>''' and the ''Label'' being highlighted in '''<span style="color:red">red</span>''':


[[File:QTGUIChooserUpdateProperties.png|500px]]
[[File:QTGUIChooserUpdateProperties.png|500px]]
Click ''OK'' to save the parameters. Running the flowgraph will use the default value ''Frequency: 0'' when starting. The drop-down box in the upper left hand corner shows that frequency ''0'' has been selected. The time domain and frequency domain both show a signal with frequency ''0'':
[[File:QTGUIChooserDefaultValue.png|700px]]
The values are selected by clicking on the drop-down menu. Click on ''Frequency: 1000'':
[[File:SelectFromQTGUIChooser.png|700px]]
The updated frequency is seen in the frequency spectrum:
[[File:QTGUIChooserOptionSelected.png|700px]]
The next tutorial, [[Signal_Data_Types|Signal Data Types]], discusses data types and representing complex and real signals in GNU Radio.

Latest revision as of 19:20, 14 March 2022

Beginner Tutorials

Introducing GNU Radio

  1. What is GNU Radio?
  2. Installing GNU Radio
  3. Your First Flowgraph

Flowgraph Fundamentals

  1. Python Variables in GRC
  2. Variables in Flowgraphs
  3. Runtime Updating Variables
  4. Signal Data Types
  5. Converting Data Types
  6. Packing Bits
  7. Streams and Vectors
  8. Hier Blocks and Parameters

Creating and Modifying Python Blocks

  1. Creating Your First Block
  2. Python Block With Vectors
  3. Python Block Message Passing
  4. Python Block Tags

DSP Blocks

  1. Low Pass Filter Example
  2. Designing Filter Taps
  3. Sample Rate Change

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 QT GUI widgets. The widgets allow interaction and modification to a flowgraph while running. The QT GUI Range widget creates a slider bar that can be used to update a variable.

Search for range in the block library:

SearchQTGUIRange.png

Drag and drop the QT GUI Range block into the workspace:

DragDropQTGUIRange.png


The QT GUI Range works like a variable block. The default parameters for the QT GUI Range need to be set. Double-click on the QT GUI Range block 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. Set the Default Value 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:

SetRangeProperties.png

An error message is displayed:

ID "frequency" is not unique.

The error message is displayed because there a variable block and the QT GUI Range are both using the name frequency. This problem will be addressed shortly. Click OK to save the properties.

Right click on the variable block and select Disable, or press D on the keyboard:

DisableVariableBlock.png

The block is now ignored and the error is resolved.

VariableBlockDisabled.png


Run the flowgraph by clicking the arrow or Play button:

RunFlowgraphButton.png


The flowgraph starts with a frequency of 0, the default value entered into the QT GUI Range block:

QTGUIRangeDefaultValue.png


The frequency parameter can then be updated by:

  1. Dragging the slider bar
  2. Entering a value
  3. Click up or down arrows

QTGUIRangeDragSlider.png

The frequency has been updated to -5000 which is reflected in orange in the frequency spectrum plot.

QT GUI Chooser

The QT GUI Chooser creates 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.

QTGUIChooserLibraryBlock.png


Update the default parameters for the Chooser block. The Chooser creates a list of options to select from while the flowgraph is running. In this example three frequencies are used: 0, 1000 and -2000. Update the following properties in the Chooser block:

  1. Id: frequency
  2. Default Option: 0
  3. Option 0: 0
  4. Label 0: Frequency: 0
  5. Option 1: 1000
  6. Label 1: Frequency: 1000
  7. Option 2: -2000
  8. Label 2: Frequency: -2000

The Option field is the value of the variable, Label is a text description that is displayed in the drop-down menu. The image shows an example of the Option being highlighted in orange and the Label being highlighted in red:

QTGUIChooserUpdateProperties.png


Click OK to save the parameters. Running the flowgraph will use the default value Frequency: 0 when starting. The drop-down box in the upper left hand corner shows that frequency 0 has been selected. The time domain and frequency domain both show a signal with frequency 0:

QTGUIChooserDefaultValue.png


The values are selected by clicking on the drop-down menu. Click on Frequency: 1000:

SelectFromQTGUIChooser.png


The updated frequency is seen in the frequency spectrum:

QTGUIChooserOptionSelected.png


The next tutorial, Signal Data Types, discusses data types and representing complex and real signals in GNU Radio.