Selector
Signal RoutingThe Selector block dynamically routes one signal from a set of multiple incoming data channels to a single output port based on a numeric control index. It operates as an -to-1 multiplexing switch. The block supports configurable input channel counts (from 2 up to 10) and allows selecting between 0-based indexing (common in computer science and programming) and 1-based indexing (standard in control engineering and matrix math). Out-of-bounds indices are safely clamped to the valid port range, preventing simulation runtime exceptions.
Mathematical Model
Let be the number of active input channels , and let be the control signal entering the index port idx.
The effective integer channel index is computed by rounding the index signal and clamping it to the allowable index range:
where:
The output routes the selected input channel corresponding to :
If the selected data input port is unconnected, the block safely outputs .
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | idx |
Idx | number | Required |
| → In | in |
In | number | Required |
| ← Out | out |
Out | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
numInputs |
Number of Inputs | number | 2 |
|
indexBase |
Index Base | select | 1 |
Usage Examples
Example 1: Multi-Mode Flight Guidance Channel Selection
Selecting between three guidance trajectories (Manual, Waypoint Navigation, Emergency Return-to-Home) in an autopilot. Configuring numInputs = 3 and indexBase = "1". A supervisory finite-state machine commands index values , , or to seamlessly switch the reference signal feeding the flight controller.
Example 2: Periodic Multi-Sensor Commutation and Round-Robin Polling
Routing signals from four telemetry sensors into a single transmission channel. A modulo-4 counter generates cyclical index values . Using a Selector block with numInputs = 4 and indexBase = "0" sequentially routes each sensor channel in synchrony with the digital polling clock.
Remarks & Best Practices
- Index Rounding and Clamping: Non-integer index inputs are rounded to the nearest integer, and values exceeding the valid range are clamped automatically to the nearest boundary index ( or ). This eliminates undefined states and prevents NaN propagation.
- Dynamic Real-Time Routing: The index input can be a continuous or discrete time-varying signal, enabling dynamic switching between channels on any simulation time step without restarting the simulation.
- Unconnected Port Protection: If a chosen data input wire is disconnected, the block emits rather than raising a null reference error.
- Zero Computational Delay: Implemented as a direct stateless pointer dereference in WebAssembly, introducing zero phase delay or arithmetic latency into the signal path.