Primary Pipeline example
This example shows how to use the Pipeline
class for the robot’s primary interface.
It reads all packages coming in from the robot’t primary interface and prints their contents.
At the current time parsing primary interface data is very limited, so this example will print the raw binary data for most package types. The example serves to demonstrate the basic control flow used for reading data from the robot.
In this library, a “pipeline” uses a producer / consumer architecture. A producer is reading data from a stream, parses that data and puts it into a queue. A consumer reads data from the queue and can do whatever its purpose is.
Producer setup
To setup the producer, we need to create a stream, a parser and create a producer with those:
Consumer setup
The consumer can be any consumer that is able to consume data produced by the producer, in this
case urcl::primary_interface::PrimaryPackage
. Here, we use a ShellExecutor
that will try to
print each package’s content to the shell output:
Assemble the pipeline
Finally, we need to assemble the pipeline by connecting the producer to the consumer:
You can setup a custom notifier that can handle start and stop events of the pipeline. In this
example we use the basic INotifier
which doesn’t do anything.
With all that, we can create the pipeline
by passing the producer, consumer, a name and the
notifier to it’s constructor.
From this point on, the producer will read the data coming on from the stream and that data will be processed by the consumer. We keep the example program alive for a while to see some data: