Part 2 (Pipelines)

In this section of the tutorial, we’ll take the stage that you just built, and create a pipeline, so that it can execute.

Creating a Pipeline

A pipeline is a collection of stages which communicate with each other. This is typically just a C++ file.

Let’s make a directory for the pipeline:

mkdir -p ${APP_ROOT}/tutorial/pipeline

Place the following in ${APP_ROOT}/tutorial/pipeline/tutorial_pipeline.cc:

#include "tutorial/first_stage/first_stage.hh"

#include "ark/main/main_offboard.hh"

int main(int argc, const char **argv)
{
    // First, form the pipeline. This creates a pipeline
    // object and adds our stage to the pipeline.
    ark::pipeline::Pipeline pipeline;

    pipeline.add_stage<FirstStage>();

    // Next, we execute it. We use the "main" helper. This will
    // automatically instantiate a real time executor and handle
    // common configuration options.
    return ark::main::execute_realtime_pipeline(argc, argv, std::move(pipeline));
}

Compiling

Let’s create a CMakeLists.txt file so we can build.

Place the following in ${APP_ROOT}/tutorial/pipeline/CMakeLists.txt:

add_executable(tutorial_pipeline tutorial_pipeline.cc)

target_link_libraries(
    tutorial_pipeline
    PRIVATE first_stage ark::main_offboard)

Then add this to the end of ${APP_ROOT}/CMakeLists.txt:

add_subdirectory(tutorial/pipeline)

Now just invoke ‘make.sh’ to build:

./make.sh

Running

Now that you have compiled your stage and pipeline, you can execute it:

./build/tutorial_pipeline

The Ark build system, by default, places everything into the ${APP_ROOT}/build directory. This makes it convenient to find binaries, and keeps them from cluttering up your source tree.

You should see output that looks like this:

~/ark$ ./build/tutorial_pipeline
(2022-02-02 10:50:30.999) [warn] (context.cc:786) The publisher /my_strings (in stage FirstStage) was not connected to any subscribers.
(2022-02-02 10:50:30.999) [warn] (context.cc:786) The publisher /debuglog (in stage DebugLoggerStage) was not connected to any subscribers.
(2022-02-02 10:50:30.999) [warn] (context.cc:786) The publisher /scope_timing_reports (in stage TracerCollectorStage) was not connected to any subscribers.

Note that the pipeline is alerting you that your channel /my_strings is not connected to anything. We’ll rectify that shortly.

Another thing to note is two additional channels, /debuglog, and /scope_timing_reports. These are added automatically by the main_offboard module, and allow you to spy on the debuglog and profiling information automatically.

Right now, there is no way to interact with the pipeline. It’s running, but we don’t have communications setup yet.

Continue to Part 3.