Class ControlAlgorithm

Receives prediction vectors and maps them to actuation values using a pluggable IControlAlgorithmStrategy. Supports runtime algorithm switching.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

Block entry for a larger pipeline. Params contains an algorithm:<Name> token. The first matching token selects the strategy. Confirm the input and output dimensions for the receiving device.

{
  "ControlAlgorithm": {
    "Type": "controlalgorithm",
    "Inputs": ["Predictions"],
    "Params": ["algorithm:DirectControl"]
  }
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
ControlAlgorithm
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public sealed class ControlAlgorithm : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

A BaseBlock represents one node in a processing graph. Blocks are typically created and linked based on a JSON configuration (pipeline definition).

Two Rate Properties:

PropertyPurpose
DesiredRate Emission / display rate in Hz. Determines how often a block publishes output. Modified by windowing blocks (e.g. SlidingWindow: input rows/s divided by stride). Used for status monitoring and tick rate display.
SignalRate True sample rate of the underlying signal in Hz. Used for DSP coefficient design (filter cutoffs, FFT bins, spectral resolution). Passes through windowing blocks unchanged — a SlidingWindow with stride 100 at 2000 Hz input still outputs data whose samples are at 2000 Hz, even though the windows arrive at 20 Hz.

Rate Inheritance: Both rates propagate downstream automatically via TryInheritRate(BaseBlock). Publication rates initially fill unset values; use UpdateAndPropagateRate(double, bool) for runtime changes. Sample rates refresh downstream unless a block declares that it derives its own rate.

Publishing: The Publish(object) method is thread-safe and non-blocking. If a publish call is already in progress, the new value is dropped and the block enters a "stumbling" state reflected in Status.

Automatic CSV Logging: Every successful Publish(object) call feeds Dumper whenever one is open. A dumper opens either because the config named a Path — BlockFactory calls InitDumper(IServiceProvider, string?) for every block it builds — or because IsRecording was switched on, which writes to the shared session folder instead. Either way the file is named by DumpFilePrefix. A block whose Path means something other than a recording folder overrides PathIsDumpFolder.

Constructors

ControlAlgorithm(string, double, IControlAlgorithmStrategy)

Declaration
public ControlAlgorithm(string name, double desiredRate, IControlAlgorithmStrategy strategy)
Parameters
Type Name Description
string name
double desiredRate
IControlAlgorithmStrategy strategy

Fields

_algorithmName

Declaration
[ObservableProperty]
private string _algorithmName
Field Value
Type Description
string

_lock

Declaration
private readonly object _lock
Field Value
Type Description
object

_strategy

Declaration
private IControlAlgorithmStrategy _strategy
Field Value
Type Description
IControlAlgorithmStrategy

Properties

AlgorithmName

Declaration
[ExcludeFromCodeCoverage]
public string AlgorithmName { get; set; }
Property Value
Type Description
string

AvailableAlgorithms

Declaration
public static IReadOnlyList<string> AvailableAlgorithms { get; }
Property Value
Type Description
IReadOnlyList<string>

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

Strategy

The currently active strategy. Used by the ViewModel to access strategy-specific properties (e.g. deadband values on DLControlStrategy).

Declaration
public IControlAlgorithmStrategy Strategy { get; }
Property Value
Type Description
IControlAlgorithmStrategy

Methods

ConfigureInput(IServiceProvider, JsonModel)

Declaration
public static ControlAlgorithm ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
ControlAlgorithm

CreateStrategy(string)

Declaration
public static IControlAlgorithmStrategy CreateStrategy(string name)
Parameters
Type Name Description
string name
Returns
Type Description
IControlAlgorithmStrategy

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

OnAlgorithmNameChanged(string)

Executes the logic for when AlgorithmName just changed.

Declaration
private void OnAlgorithmNameChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of AlgorithmName is changed.

OnAlgorithmNameChanged(string?, string)

Executes the logic for when AlgorithmName just changed.

Declaration
private void OnAlgorithmNameChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of AlgorithmName is changed.

OnAlgorithmNameChanging(string)

Executes the logic for when AlgorithmName is changing.

Declaration
private void OnAlgorithmNameChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of AlgorithmName is changed.

OnAlgorithmNameChanging(string?, string)

Executes the logic for when AlgorithmName is changing.

Declaration
private void OnAlgorithmNameChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of AlgorithmName is changed.

OnReceive(object, object)

Processes incoming data from an upstream block. Must be implemented by derived classes.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender

The publishing block, or whatever else delivered the value.

object data
Overrides
BaseBlock.OnReceive(object, object)
Remarks

Called on the dispatching thread, not the UI thread.

ResetStrategy()

Declaration
public void ResetStrategy()

SetStrategy(IControlAlgorithmStrategy)

Declaration
public void SetStrategy(IControlAlgorithmStrategy strategy)
Parameters
Type Name Description
IControlAlgorithmStrategy strategy

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.