xentara-cpp-control v1.0.1
The Xentara C++ Control Framework
Loading...
Searching...
No Matches
Adding Hardcoded Inputs to an Output

Overview

In this tutorial, we will extend the control class by introducing two hardcoded input values and an output value, which we will set within the step function. This demonstrates a basic control flow where inputs are read and used to determine an output.

In this tutorial, we will:

  • Define two hardcoded input values.
  • Write the result to an output variable based on the input values in the step function.

Step 1: Define Hardcoded Inputs and Output

Create a new header file called BasicControl.hpp. In this file, we will define two double input values, input1 and input2, and a double output variable, output.

Here is the code for BasicControl.hpp:

#pragma once
#include <xentara/cpp-control.h>
class BasicControl final : public xentara::Control
{
public:
void initialize(xentara::InitContext &context) override;
void step(xentara::RunContext &context) override;
private:
double input1 { 12.0 };
double input2 { 8.0 };
double output { 0.0 };
};
An interface class which provides declaration of all the callbacks for this control.
Definition Control.hpp:19
virtual auto initialize(InitContext &context) -> void=0
Callback that is called by the framework to initialize the control object.
virtual auto step(RunContext &context) -> void=0
Main callback responsible for executing the core control logic.
An initialization context with configuration information and access to Xentara Elements.
Definition InitContext.hpp:35
An run context with execution information and is required for the read and write for Input and Output...
Definition RunContext.hpp:46

Step 2: Implement the Control Logic

Now, create the implementation file, BasicControl.cpp. In this file, we will implement the initialize and step methods. The step method will add both the inputs to the output.

Here is the code for BasicControl.cpp:

#include "BasicControl.hpp"
/// Registers the BasicControl with Xentara.
void BasicControl::initialize(xentara::InitContext &context)
{
// No initialization needed for hardcoded inputs
}
void BasicControl::step(xentara::RunContext &context)
{
output = input1 + input2;
}
A class used to export your control class with Xentara.
Definition ControlExporter.hpp:38

In this example, the step method performs an arithmetic operation by adding input1 and input2 and storing the result in output. This simple operation demonstrates how a control function can use input values to perform calculations and set an output value. By assigning the result to output, this example also shows a basic control action, where inputs are processed to determine an output.

Conclusion

In this tutorial, we created a control with hardcoded inputs and a simple output. This example provides a basic control flow that will serve as a foundation for more dynamic input-output operations in future tutorials.