Class ControlStrategyBase

Base class for control strategies with helper methods for safe, clean code. Extend this class to create custom control algorithms.

Namespace: MOSAIC.Components.Manager.ControlAlgorithm
Assembly: MOSAIC.dll
Syntax
public abstract class ControlStrategyBase : IControlAlgorithmStrategy
Examples
public class MyStrategy : ControlStrategyBase
{
    public override string Name => "MyStrategy";

    protected override void InitializeDefaults()
    {
        Set(DegreesOfActuation.Index, 0);
        Set(DegreesOfActuation.Middle, 0);
    }

    public override void ProcessPrediction(Vector<double> prediction)
    {
        Set(DegreesOfActuation.Index, Get(prediction, 0) * 100);
        Set(DegreesOfActuation.Middle, Get(prediction, 1) * 100);
    }
}

Constructors

ControlStrategyBase()

Declaration
protected ControlStrategyBase()

Fields

ControlDict

Declaration
protected readonly Dictionary<DegreesOfActuation, double> ControlDict
Field Value
Type Description
Dictionary<DegreesOfActuation, double>

Properties

Name

Name of this strategy (used for JSON export and UI display).

Declaration
public abstract string Name { get; }
Property Value
Type Description
string

Methods

Add(DegreesOfActuation, double)

Adds to a DOA value, result clamped to [0, 100].

Declaration
protected void Add(DegreesOfActuation doa, double delta)
Parameters
Type Name Description
DegreesOfActuation doa
double delta

Get(Vector<double>, int)

Safely gets a value from the prediction vector. Returns 0 if index is out of bounds.

Declaration
protected static double Get(Vector<double> prediction, int index)
Parameters
Type Name Description
Vector<double> prediction
int index
Returns
Type Description
double

GetControlDict()

Gets the current DOA actuation values (typically [0,100]).

Declaration
public Dictionary<DegreesOfActuation, double> GetControlDict()
Returns
Type Description
Dictionary<DegreesOfActuation, double>

InitializeDefaults()

Initialize DOA default values. Override this in derived classes.

Declaration
protected abstract void InitializeDefaults()

MapBipolar(DegreesOfActuation, Vector<double>, int, bool, double)

Maps a single bipolar prediction in [−1, +1] to DOA [0, 100]. 0.0 maps to 50 (neutral), −1 maps to 0, +1 maps to 100. Use this for regression outputs where a single channel encodes both directions (e.g. wrist flex/ext as one signed value). Set invert to true to flip the sign when the model's positive direction is opposite to the DOA convention. deadband suppresses values near zero — any absolute value below this threshold maps to 50 (neutral).

Declaration
protected void MapBipolar(DegreesOfActuation doa, Vector<double> prediction, int index, bool invert = false, double deadband = 0)
Parameters
Type Name Description
DegreesOfActuation doa
Vector<double> prediction
int index
bool invert
double deadband

MapDirect(DegreesOfActuation, Vector<double>, int)

Maps a prediction value [0,1] directly to DOA [0,100].

Declaration
protected void MapDirect(DegreesOfActuation doa, Vector<double> prediction, int index)
Parameters
Type Name Description
DegreesOfActuation doa
Vector<double> prediction
int index

MapOpposing(DegreesOfActuation, Vector<double>, int, int)

Maps two opposing predictions to a centered DOA value. Result: 50 when equal, 0 when negative dominates, 100 when positive dominates.

Declaration
protected void MapOpposing(DegreesOfActuation doa, Vector<double> prediction, int positiveIdx, int negativeIdx)
Parameters
Type Name Description
DegreesOfActuation doa
Vector<double> prediction
int positiveIdx
int negativeIdx

ProcessPrediction(Vector<double>)

Processes a prediction vector and updates actuation values.

Declaration
public abstract void ProcessPrediction(Vector<double> prediction)
Parameters
Type Name Description
Vector<double> prediction

Reset()

Resets all DOA values to defaults.

Declaration
public void Reset()

Set(DegreesOfActuation, double)

Sets a DOA value, clamped to [0, 100].

Declaration
protected void Set(DegreesOfActuation doa, double value)
Parameters
Type Name Description
DegreesOfActuation doa
double value

StepControl(DegreesOfActuation, double, double, double, double)

Applies incremental step control with deadband. Only changes value if activation exceeds deadband threshold.

Declaration
protected void StepControl(DegreesOfActuation doa, double positive, double negative, double deadband, double stepSize)
Parameters
Type Name Description
DegreesOfActuation doa
double positive
double negative
double deadband
double stepSize

Implements

IControlAlgorithmStrategy

Search documentation

Start typing to search the documentation.