Yes. In fact, that’s the normal way to parameterize a custom Python block in GNU Radio.
There are several ways to do it:
1. Pass a GNU Radio variable as a block parameter (most common)
In GRC, define a variable, e.g.:
threshold = 5
Then in your embedded or out-of-tree Python block:
threshold=threshold
Your block constructor becomes:
class my_block(gr.sync_block):
def __init__(self, threshold=5):
gr.sync_block.__init__(
self,
name=”My Block”,
in_sig=[np.float32],
out_sig=[np.float32]
)
self.threshold = threshold
Now self.threshold contains the value from the GRC variable.
—
2. Update the value while the flowgraph is running
If the variable changes (for example from a QT Range slider), GNU Radio calls a setter method.
Example:
def set_threshold(self, threshold):
self.threshold = threshold
In GRC, the generated code will call:
my_block.set_threshold(threshold)
whenever the variable changes.
—
3. If your “self-written module” is a separate Python file
Suppose your block imports another module:
import myprocessing
Then in work() you can simply do:
result = myprocessing.process(input_data, self.threshold)
or
myprocessing.threshold = self.threshold
although passing it as a function argument is generally cleaner.
—
For your radio astronomy work, this is useful for passing values such as:
FFT size
Integration time
Centre frequency
Detection threshold
Calibration constants
Doppler correction values
without modifying the Python source each time.
If you’re writing an Out-of-Tree (OOT) module, variables are passed into the block constructor in exactly the same way as for standard GNU Radio blocks.