xentara-cpp-control v1.0.1
The Xentara C++ Control Framework
Loading...
Searching...
No Matches
Using an Input, Configuration Parameter, and Output

Overview

In this tutorial, we will update our control to use one input, one configuration parameter, and one output. The step function will read the input, multiply it by the configuration parameter, and write the result to the output. This demonstrates how to use a configuration parameter to influence control behavior dynamically.

The objectives of this tutorial are to:

  • Define an input and an output as Xentara data points.
  • Introduce a configuration parameter that modifies control behavior.
  • Implement the logic to read the input, apply the configuration parameter, and write to the output.

Step 1: Define the Control Class with Input, Configuration Parameter, and Output

In this version of the control class, we define one xentara::Float64Input for the input, an integer configuration parameter, and one xentara::Float64Output for the output.

Here is the updated code for ConfigMultiplierControl.hpp:

#pragma once
#include <xentara/cpp-control.h>
class ConfigMultiplierControl final : public xentara::Control
{
public:
void initialize(xentara::InitContext &context) override;
void step(xentara::RunContext &context) override;
private:
/// Xentara-managed input data point
xentara::Float64Input input;
/// Xentara-managed output data point
xentara::Float64Output output;
/// Configuration parameter for multiplication
int configParameter {1};
};
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 the Input, Output, and Configuration Parameter

The JSON configuration file below configures the data points and the configuration parameter for this control. The configuration parameter (multiplier) is defined in the "parameters" section, with Input and Output as Xentara data points specified by name.

{
"children": [
{
"@Skill.CPP.Control": {
"name": "Control",
"UUID": "f6e82386-db77-48af-9e3a-14f821a07a15",
"controlPath": "libcontrol.so",
"parameters": {
"multiplier": 2,
"input": "Input",
"output": "Output"
}
}
},
{
"@Skill.SignalFlow.Register": {
"name": "Input",
"UUID": "60729f3b-e54e-4860-ad8a-12614a4b10d5",
"defaultValue": [ "float64", 125.85 ]
}
},
{
"@Skill.SignalFlow.Register": {
"name": "Output",
"UUID": "a1c781ee-af86-4a40-8ea7-49ee9e3a3942",
"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 and Output are Xentara-managed data points.
  • multiplier is the configuration parameter, with a value of 2, which is used in the initialize function to modify control behavior.

Step 3: Implement the Xentara Data Point and Configuration Logic

In the implementation file, ConfigMultiplierControl.cpp, we will initialize the input and output data points and retrieve the configuration parameter in the initialize method. The step function will then read the input, multiply it by the configuration parameter, and write the result to the output.

Here is the updated code for ConfigMultiplierControl.hpp:

#include "ConfigMultiplierControl.hpp"
/// Registers the ConfigMultiplierControl with Xentara.
void ConfigMultiplierControl::initialize(xentara::InitContext &context)
{
// Initialize input and output data points
input = context.config().getDataPoint("input");
output = context.config().getDataPoint("output");
// Retrieve the configuration parameter
configParameter = context.config().getInt("multiplier");
}
void ConfigMultiplierControl::step(xentara::RunContext &context)
{
// Read the input value
auto inputValue = input.read(context);
// Multiply the value
double multipliedValue = inputValue * configParameter;
// Multiply by configuration parameter and write to output
output.write(context, multipliedValue);
}
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 introduced a configuration parameter that influences control behavior by modifying an input value before writing it to the output. This setup demonstrates how to use configuration values alongside inputs and outputs to customize control logic, creating a flexible and dynamic control component in Xentara.