Class Trigger
Manual trigger block for on-demand data capture in the pipeline.
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.
Classification JSON (classic, unchanged):
{
"Trigger": {
"Type": "Trigger",
"Params": [ "rest:0;0;0;0;0", "thumb:1;0;0;0;0", "pinch:1;1;0;0;0" ]
}
}
Regression JSON (oscillating mode, sweep at 0.5 Hz, tick at 30 Hz):
{
"Trigger": {
"Type": "Trigger",
"Params": [
"rest:0;0;0;0;0",
"thumb:1;0;0;0;0",
"pinch:1;1;0;0;0",
"mode:oscillating",
"freq:0.5",
"tickrate:30"
]
}
}
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public class Trigger : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Overview: The Trigger block holds a dictionary of named activation vectors (actions) and allows the user to manually start/stop capture via the UI. When StartCapture() is called, the current action's target vector is published downstream (typically to a Buffer or IncrementalPredictor block). When StopCapture() is called, null is published, signalling the buffer to finalise the segment.
Oscillating mode (regression training): When OscillationMode is
true, the published target is the action vector multiplied by
sin²(2π·f·t) at each tick of an internal timer. The active channels sweep
continuously from 0 to 1 and back during the recording; inactive channels stay at
zero. Combined with the TriggerBuffer's per-frame target storage, this
gives the downstream regression model a full sweep of activation intensities for each
gesture in a single recording — so finger flex regression can be trained without ever
needing the user to provide continuous ground-truth themselves.
sin² envelope: The square is intentional — it keeps the output non-negative
(necessary for BCEWithLogitsLoss targets), and sin² has the same period as |sin|
but is smooth at zero crossings, avoiding the V-shape that would otherwise show up at
each sign change. Period = 1/f seconds; e.g. f=0.5 Hz means one full sweep every 2 s.
Source block: No upstream inputs — driven entirely by user interaction. OnReceive(object, object) is a no-op.
Constructors
Trigger(string, double)
Declaration
public Trigger(string name = "Trigger", double desiredRate = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| double | desiredRate |
Fields
_captureStartTicks
Wall-clock anchor for the oscillation phase; resets on each StartCapture().
Declaration
private long _captureStartTicks
Field Value
| Type | Description |
|---|---|
| long |
_collecting
Declaration
private bool _collecting
Field Value
| Type | Description |
|---|---|
| bool |
_liveActivation
Most recently published activation vector. Mirrored from Publish(object) calls in both classic and oscillation modes so a ViewModel can bind to it for a live bar/scope display. Null when no capture is in progress (the buffer's "stop" signal is represented here as a zero vector of the same shape, so bindings stay well-defined and the bars fall to zero on stop instead of holding the last frame).
Declaration
[ObservableProperty]
private Vector<double>? _liveActivation
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_oscillationLock
Lock around oscillation-timer lifecycle so Start/Stop don't race.
Declaration
private readonly object _oscillationLock
Field Value
| Type | Description |
|---|---|
| object |
_oscillationTimer
Timer for oscillation-mode republishing. Null in classic mode or when idle.
Declaration
private Timer? _oscillationTimer
Field Value
| Type | Description |
|---|---|
| Timer |
Properties
ActionCount
Declaration
public int ActionCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Actions
Dictionary of available actions, keyed by name, with activation vectors as values.
Declaration
public Dictionary<string, Vector<double>> Actions { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, Vector<double>> |
CurrentActionName
Declaration
public string CurrentActionName { get; }
Property Value
| Type | Description |
|---|---|
| string |
CurrentActionVector
Declaration
public Vector<double>? CurrentActionVector { get; }
Property Value
| Type | Description |
|---|---|
| Vector<double> |
CurrentIdx
Zero-based index of the currently selected action.
Declaration
public int CurrentIdx { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
DumpFilePrefix
Recordings from this block are named <block>_trigger.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
LiveActivation
Most recently published activation vector. Mirrored from Publish(object) calls in both classic and oscillation modes so a ViewModel can bind to it for a live bar/scope display. Null when no capture is in progress (the buffer's "stop" signal is represented here as a zero vector of the same shape, so bindings stay well-defined and the bars fall to zero on stop instead of holding the last frame).
Declaration
[ExcludeFromCodeCoverage]
public Vector<double>? LiveActivation { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector<double> |
MaxInputs
The Trigger is a standalone source of label/action vectors — it takes no inputs.
Declaration
public override int MaxInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
MinInputs
The Trigger is a standalone source of label/action vectors — it takes no inputs.
Declaration
public override int MinInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
OscillationFrequencyHz
Sweep frequency in Hz. Default 0.5 (one full 0→1→0 cycle every 2 s).
Declaration
public double OscillationFrequencyHz { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
OscillationMode
When true, StartCapture() begins an internal timer
that republishes the action vector at OscillationTickRateHz, modulated
by sin²(2π·f·t) where f = OscillationFrequencyHz.
Active channels sweep 0→1→0 continuously during the recording; inactive channels
stay zero. Pairs with TriggerBuffer's per-frame target storage to
produce regression training data without continuous ground-truth input.
Declaration
public bool OscillationMode { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
OscillationTickRateHz
How often the oscillation timer republishes the modulated target. Should match (or oversample) the data block's rate — at 30 Hz data, 30 Hz tick gives one modulated target per data frame, which is ideal alignment for the buffer's per-frame target store.
Declaration
public double OscillationTickRateHz { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
ConfigureInput(IServiceProvider, JsonModel)
Declaration
public static Trigger ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | |
| JsonModel | m |
Returns
| Type | Description |
|---|---|
| Trigger |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public override void Dispose()
Overrides
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 |
Overrides
NextAction()
Declaration
public void NextAction()
OnLiveActivationChanged(Vector<double>?)
Executes the logic for when LiveActivation just changed.
Declaration
private void OnLiveActivationChanged(Vector<double>? value)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | value | The new property value that was set. |
Remarks
This method is invoked right after the value of LiveActivation is changed.
OnLiveActivationChanged(Vector<double>?, Vector<double>?)
Executes the logic for when LiveActivation just changed.
Declaration
private void OnLiveActivationChanged(Vector<double>? oldValue, Vector<double>? newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | oldValue | The previous property value that was replaced. |
| Vector<double> | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of LiveActivation is changed.
OnLiveActivationChanging(Vector<double>?)
Executes the logic for when LiveActivation is changing.
Declaration
private void OnLiveActivationChanging(Vector<double>? value)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | value | The new property value being set. |
Remarks
This method is invoked right before the value of LiveActivation is changed.
OnLiveActivationChanging(Vector<double>?, Vector<double>?)
Executes the logic for when LiveActivation is changing.
Declaration
private void OnLiveActivationChanging(Vector<double>? oldValue, Vector<double>? newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | oldValue | The previous property value that is being replaced. |
| Vector<double> | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of LiveActivation 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
Remarks
Called on the dispatching thread, not the UI thread.
OscillationTick(object?)
Timer callback — computes the sin²-modulated target for the elapsed phase and publishes it. Bound to the action vector captured at StartCapture() so a mid-recording SelectAction(string) doesn't change which gesture is being recorded.
Declaration
private void OscillationTick(object? state)
Parameters
| Type | Name | Description |
|---|---|---|
| object | state |
PreviousAction()
Declaration
public void PreviousAction()
PublishModulated(Vector<double>, double)
Compute the modulated target baseVec · sin²(2π·f·t) and publish it.
Declaration
private void PublishModulated(Vector<double> baseVec, double phaseSeconds)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | baseVec | |
| double | phaseSeconds |
SelectAction(string)
Declaration
public void SelectAction(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
StartCapture()
Begin a capture segment. In classic mode, publishes the current action's vector once and stays silent for the rest of the segment. In oscillation mode, kicks off an internal timer that republishes the vector at OscillationTickRateHz, modulated by sin²(2π·f·t) — sweeping the action's active channels from 0 to 1 and back continuously until StopCapture().
Declaration
public void StartCapture()
StopCapture()
End the current capture segment. Stops the oscillation timer (if running) and publishes null so the buffer finalises the segment.
Declaration
public void StopCapture()
TryParseConfigParam(string, Trigger)
Parse a config-style parameter ("mode:...", "freq:...", "tickrate:..."). Returns true if the parameter was a config directive (and applied); false if it should be treated as a regular action definition.
Declaration
private static bool TryParseConfigParam(string s, Trigger t)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | |
| Trigger | t |
Returns
| Type | Description |
|---|---|
| bool |