GNURadioCompanion: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(Redirected page to Guided Tutorial GRC)
 
Line 1: Line 1:
[[Category:Usage Manual]]
#REDIRECT [[Guided Tutorial GRC]]
= GNU Radio Companion =
 
GNU Radio Companion (GRC) is a graphical tool for creating signal flow graphs and generating flow-graph source code.
 
== Execution ==
 
Open a terminal and enter the following:
 
<pre>
gnuradio-companion
</pre>
 
 
 
== Hierarchical Blocks ==
 
GRC can create hierarchical blocks out of the built-in blocks. Hierarchical blocks can be instantiated inside of other grc flow graphs. The python code generated from a hierarchical block can itself be used in non-GRC flow graphs. Four important blocks are used in the creation of a hierarchical block: The options block, parameter blocks, and the pad source and pad sink.
 
=== The Options Block ===
 
In order to make a hierarchical block, the parameters in the options block must be set properly. The id of the options block sets the module name, and must be unique among the entire library of blocks (built-in and custom). The title parameter sets the display name for the block. The generate options must be set to "Hier Block". The category parameter sets the category for the new block. This category can be an existing category in the block selection window or a new category. Categories may be nested by specifying a name with slashes, ex: Custom/Filters. To put blocks into the root category, specify a single slash "/" (a blank category will hide your block).
 
=== Parameter Blocks ===
 
Parameter blocks specify variables in your hierarchical block that should be configurable in the top level block. Parameter blocks work much like variable blocks with a few exceptions: Parameters blocks cannot depend on variable blocks or other parameter blocks. Parameter blocks have a label parameter for display purposes. Parameter blocks take the place of a variable block, do not try to create a variable block with the same id as your parameter block.
 
=== Pad Source and Sink Blocks ===
 
The pad source and sink blocks create inputs and outputs for the hierarchical block. The pad blocks have configurable data types, vector lengths, and number of ports. A flow graph can have at most, one pad source, and one pad sink. A hierarchical block may have one pad sink and no pad source or no pad sink and one pad source, but it must have at least one pad block.
 
=== Creating and Instantiating ===
 
* Start with a blank slate and create a new (empty) flow graph.
 
* Setup the options block as described above, with the id, title, generate options, and category.
 
* Add parameter blocks for all variables you wish to configure/control outside of the block.
 
* Create at most one pad source and one pad sink to match the IO type and connect them.
 
* When finished, click the generate button, and close/reopen GRC.
 
* The hierarchical block will appear in the block selection window.
 
* Add the hierarchical block to a flow graph as your would any other block.
 
=== Notes ===
 
* After making changes to your hierarchical block, make sure to regenerate, and reopen GRC before usage.
 
* The ID parameter of the block must be unique. If two blocks share the same ID, the last one to be generated will overwrite the other.
 
* Custom hierarchical blocks may instantiate other custom hierarchical blocks. Just don't have a block instantiate itself!
 
== Adding Custom Blocks ==
 
Every block in GRC corresponds to an XML file that describes the block's parameters, inputs, outputs, and other attributes. Adding a custom block into GRC is simply a matter of creating one of these XML block definition files. A few caveats:
 
* The block should be accessible from the python path. Meaning that the block can be accessed via an import statement.
* The block follows the block diagram model: it has parameters, inputs, and outputs. If the block requires some kind of listening thread, or special callback methods to move the data (as in the blks2 packet stuff), it cannot be used in GRC (unless this "special" functionality can be encapsulated into a block that is block-diagram-safe).
* If GRC is missing a block definition for a block that is currently in the trunk, or one of the block definitions is missing functionality, please mail the list. The block definitions in the GRC trunk must stay in sync with the actual GNU Radio blocks.
 
=== Creating the XML Block Definition ===
 
The best way to learn how to create the xml file is to learn by example. See the block definitions (source:grc/blocks) packaged with GRC, and read through a few files. Essentially, all block definitions are structured as follows:
 
<pre>
    My Block Name
    my_package_my_block_ff
        Filters
    from gnuradio import my_package
    my_package.my_block_ff($param1, $param2)
        set_param1($param1)
   
        Parameter 1
        param1
        real
   
   
        Parameter 2
        param2
        1
        int
   
   
        in
        float
                part
   
   
        out
        float
   
       
        out
        float
</pre>
 
* The example above will make a block with 2 parameters, 1 input, and 2 outputs.
* The ordering of the tags is important, if tags are not ordered properly, the block will fail validation. See [https://github.com/gnuradio/gnuradio/blob/master/grc/core/block.dtd block.dtd] for specifics.
* The '''name''' tags dictate the label text for the block, parameters, and ports.
* The '''key''' tags are unique identifiers, they may not contain spaces. The block key must be globally unique among all blocks in GRC. The parameter keys must be unique only within the block.
* The '''category''' tag is a unix-style path that represents the location of the block inside the block selection window. The path can be a new category (Custom), or represent a sub-category (Filters/Custom). To put a block into the root category, just use a single slash (/) for the root path.
* The '''import''' tag (there can be multiple) must be a valid python import statement to the module containing your block.
* The '''make''' tag contains the code necessary to construct your block. This code is essentially a cheetah template nested inside an xml tag. Upon code generation, the template performs a text substitution on the "$" parameters. For more advanced capabilities, see the [http://cheetahtemplate.org/users_guide/index.html cheetah template documentation.]
* The '''callback''' tag registers a set-method from your custom block. Once the set-method is registered, the set-method can be called at runtime when a variable is changed. There can be any number of '''callback''' tags, one for each set-method of your block. Or no '''callback''' tags if this is not applicable.
* For the '''param''' tags, the commonly used values for the '''type''' tags are: complex, real, int, complex_vector, real_vector, int_vector, string, and raw. The ''raw'' type allows any value to be used without performing type checking. The ''real'' type should be used for single and double precision floating point numbers. The ''int'' type should be used for longs, ints, shorts, and chars.
* The hide tag controls how the parameter is displayed in GRC. It's either none, part (show in the prop dialog, not in the block on the canvas) or all.
* The '''sink''' tag represents an input port, and the '''source''' tag represents an output port. The allowed values for the '''type''' tags are: complex, float, int, short, and byte. For ports with a vector length, specify a '''vlen''' tag after the '''type''' tag.
* In case you want to create a block definition as done for the FECAPI, the '''key''' tag has to start with '''variable_''' in order to work correctly in GRC.
 
=== Some Example Definitions ===
 
* Simple Example: "Complex to Real" source:[https://github.com/gnuradio/gnuradio/blob/master/gr-blocks/grc/blocks_complex_to_real.xml|gr-blocks/grc/blocks_complex_to_real.xml]
* Multiple Callbacks: "Costas Loop" source:[https://github.com/gnuradio/gnuradio/blob/master/gr-digital/grc/digital_costas_loop_cc.xml|gr-digital/grc/digital_costas_loop_cc.xml]
* Vlen Example: "Throttle" source:[https://github.com/gnuradio/gnuradio/blob/master/gr-digital/grc/blocks_throttle.xml|gr-digital/grc/blocks_throttle.xml]
* Advanced Make: "FFT" source:[https://github.com/gnuradio/gnuradio/blob/master/gr-fft/grc/fft_fft_vxx.xml|gr-fft/grc/fft_fft_vxx.xml]
 
=== Installing the XML Block Definition ===
 
There are many methods to tell grc about your new xml file. Choose one of the following methods...
 
==== Method 1: Default Hier Block Location ====
 
Create the _'''.xml_ file inside'''<sub>/.grc_gnuradio/* where</sub> is your home directory. If the directory does not exist, create it: ''mkdir ~/.grc_gnuradio/''
 
==== Method 2: Configuration File ====
 
Create or edit '''~/.gnuradio/config.conf''' and add the following lines:
 
<pre>[grc]
local_blocks_path=/path/to/my/blocks</pre>
The local_blocks_path can contain multiple paths separated by colons: local_blocks_path=/path/to/blocks1:/path/to/blocks2
 
==== Method 3: Environment Variable ====
 
Set the '''GRC_BLOCKS_PATH''' environment variable to a path that contains your custom block wrapper. The GRC_BLOCKS_PATH can contain multiple paths separated by colons: GRC_BLOCKS_PATH=/path/to/blocks1:/path/to/blocks2
 
== Special Thanks ==
 
* '''[http://www.cer.jhu.edu/ CER Technology Fellowship]:''' initial funding
* '''[http://www.ece.jhu.edu/~cooper/ A. Brinton Cooper]:''' starting the project
* '''Patrick Mulligan:''' starting the project
* '''William R. Kenan Jr. Fund:''' usrp & computers
* '''Patrick Strasser:''' the GRC icon
 
== Screen Shots ==
 
[http://www.joshknows.com/grc#screenshots Screen Shots]
 
Feel free to submit your own screen shots or flow graphs.

Latest revision as of 02:28, 1 May 2020