The Companion
The GNU Radio Companion is the graphical editor: a canvas, a library of blocks down the side, wires you draw between them. This chapter tells you what the Companion really is — a code generator wearing a friendly face — and proves it the way this guide proves things: the lab built the same flowgraph twice, once as a picture and once as hand-written Python, and the two produced byte-identical output.
The picture is not the program
Draw blocks on the canvas, set their
parameters in their Properties dialogs,
and the Companion does two things with
your drawing. It saves it as a .grc
file — readable text, in a format called
YAML, which chapter 13 opens up and
reads. And when you ask it to run, it
generates a Python program from the
drawing and runs that. The Python is
the program. The picture is a way of
writing it.
The lab's evidence
(gnu-radio-lab/transcripts/t05-companion.txt):
the Companion's command-line compiler,
grcc, took the lab's drawing
(gnu-radio-lab/fg1_tone_filter.grc)
and generated fg1_tone_filter.py.
The lab ran the generated program
(t05b-companion-run.txt) and compared:
its raw output file and the output of
the hand-written twin of chapter 6 are
the same bytes, and the filtered
measurements agree to the last digit
shown. Two notations, one program. Keep
that in your pocket whenever the canvas
feels like magic or the code feels like
a betrayal: they are two handwritings
of the same letter.
Reading the canvas
Three conventions carry the whole editor:
- Blocks are boxes; ports are the small squares on their edges. Inputs on the left, outputs on the right. Click one port, click another, and a wire joins them.
- Port colour is type. In the standard theme, blue is complex, orange is float (real numbers), other colours mark integers, bytes, and messages. A wire between colours is refused or demands a converter block, and that refusal is the editor doing you a kindness: the types would not have survived the journey (chapter 16 returns to this).
- Variables are blocks too. The
sample rate sits on the canvas as a
variable block named
samp_rate, and other blocks refer to it by name. One definition, every block in step — change it in one place and the whole graph's arithmetic follows. Every flowgraph in this guide keeps its rate in exactly one such block, for exactly that reason.
Generate, run, and the warning worth meeting
Generating the lab's drawing, grcc printed a warning every beginner meets sooner or later:
>>> Warning: This flow graph may not have flow control:
no audio or RF hardware blocks found. Add a
Misc->Throttle block to your flow graph to avoid
CPU congestion.
It is the throttle question of chapter 7
arriving early: nothing in this graph
is paced by hardware, so what stops it
running at a hundred times real time?
In the lab's graph, a head block
caps the work at 48,000 samples and the
run ends. The generated program also
shows the other honest difference
between the notations: where the
hand-written twin calls run() and
stops when the samples run out, the
generated program starts the graph and
waits at "Press Enter to quit:" —
the Companion expects a human at a
keyboard, supervising. Both are right,
for their audiences.
The editor itself, honestly
The lab's build machine has no screen.
The Companion there first refused to
open at all — Namespace Gtk not
available, a missing piece of the GTK
windowing toolkit that the package had
not pulled in — and, once the bindings
were installed, the editor opened the
lab's flowgraph under a virtual display
and sat in it happily until it was
closed (t06-companion-gui.txt). That
is the truth and the limit of it: the
lab verified that the editor installs,
opens, and holds the lab's drawing.
The click-by-click craft of canvas
editing — dragging, wiring, nudging
parameters — is described in this guide
from the project's documentation, not
from a transcript, because a canvas
leaves no transcript worth keeping.
criteria.md files it under
documented-only, where it belongs.
Check: if you have the Companion
open, save any drawing and look at the
.grc file in a text editor. You
should find your blocks listed by name
and every wire in a connections: list
at the end. Chapter 13 teaches you to
read that file like a book.