xentara-cpp-control v1.0.1
The Xentara C++ Control Framework
Loading...
Searching...
No Matches
Using Xentara Inputs and Outputs

Overview

In this tutorial, we will update our control by replacing the hardcoded input and output values with Xentara-managed data points. The initialize function will configure these data points to allow the control to interact with Xentara input and output system. This demonstrates how to set up Xentara-specific inputs and outputs within a control.

The objectives of this tutorial are to:

  • Replace the hardcoded input and output variables with Xentara data points.
  • Configure these data points within the initialize function.
  • Implement a basic control operation in the step function using the Xentara data points.

Step 1: Define the Control Class with Xentara Data Points

In this version of the control class, we replace input1 and input2 with xentara::Float64Input data points. We also replace output with a xentara::Float64Output data point. These changes will allow us to interact with the Xentara framework for dynamic input and output handling.

Here is the updated code for XentaraBasicControl.hpp:

#pragma once
#include <xentara/cpp-control.h>
class XentaraBasicControl final : public xentara::Control
{
public:
void initialize(xentara::InitContext &context) override;
void step(xentara::RunContext &context) override;
private:
/// Xentara-managed input data points for demonstration
xentara::Float64Input input1;
xentara::Float64Input input2;
/// Xentara-managed output data point representing the result of adding input1 and input2
xentara::Float64Output output;
};
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: JSON Configuration for Xentara Data Points

The following JSON file configures the data points for this control. Input 1, Input 2, and Output are Xentara data points defined within the control configuration. In the initialize function, these data points are retrieved by their names as specified in the JSON configuration.

{
"children": [
{
"@Skill.CPP.Control": {
"name": "Control",
"UUID": "79dec6e4-261d-498e-b87c-6a24df6b9f7c",
"controlPath": "libcontrol.so",
"parameters": {
"input1": "Input 1",
"input2": "Input 2",
"output": "Output"
}
}
},
{
"@Skill.SignalFlow.Register": {
"name": "Input 1",
"UUID": "2072c151-ef29-4952-a673-0c98c2e09ba2",
"defaultValue": [ "float64", 15.55 ]
}
},
{
"@Skill.SignalFlow.Register": {
"name": "Input 2",
"UUID": "e869e62d-5a12-4c99-926c-5a3291879d2c",
"defaultValue": [ "float64", 125.85 ]
}
},
{
"@Skill.SignalFlow.Register": {
"name": "Output",
"UUID": "b15d89b6-a9d9-4306-aa49-a2b1d617688c",
"defaultValue": [ "float64", 0.0 ]
}
},
{
"@Track": {
"name": "Control Track",
"UUID": "fb0a26f8-7d84-4af9-9345-4145263d09c7",
"children": [
{
"@Timer": {
"name": "Timer",
"UUID": "e6580c24-dbf9-43a0-aa81-c5ed8da6f734",
"period": "50ms"
}
},
{
"@Pipeline": {
"name": "Pipeline",
"UUID": "040f156e-2744-4008-8195-cd7f17078668",
"triggers": [
"Control Track.Timer.expired"
],
"checkpoints": [
{},
{}
],
"segments": [
{
"start": 0,
"end": 1,
"tasks": [
{
"function": "Control.step"
}
]
}
]
}
}
]
}
}
]
}

In this configuration:

  • Input 1, Input 2, and Output are data points in the Xentara model.
  • The control gets these elements by their names, specified as input1, input2, and output in the configuration section of the JSON file.

Step 3: Implement the Xentara Data Point Initialization and Logic

In the implementation file, XentaraBasicControl.cpp, we will initialize the input and output data points using the initialize method. We will retrieve these data points from the Xentara configuration context, allowing them to interact with other parts of the Xentara system. In the step function, we will read the inputs, add their values, and write the result to the output data point.

Here is the updated code for XentaraBasicControl.cpp:

#include "XentaraBasicControl.hpp"
/// Registers the XentaraBasicControl with Xentara.
void XentaraBasicControl::initialize(xentara::InitContext &context)
{
// Initialize input and output data points using the context configuration
input1 = context.config().getDataPoint("input1");
input2 = context.config().getDataPoint("input2");
output = context.config().getDataPoint("output");
}
void XentaraBasicControl::step(xentara::RunContext &context)
{
// Read values from the Xentara-managed inputs
auto value1 = input1.read(context);
auto value2 = input2.read(context);
// Add the inputs and write the result to the Xentara-managed output
output.write(context, value1 + value2);
}
A class used to export your control class with Xentara.
Definition ControlExporter.hpp:38
auto config() const -> const Config &
Gets the configuration.

Conclusion

In this tutorial, we updated our control by replacing hardcoded values with Xentara-managed inputs and outputs. We also configured these data points within the initialize function to interact with the Xentara system. This setup now enables dynamic input-output handling, laying the groundwork for more complex control logic.