☝

Selector

Signal Routing
Run the live example Free · no sign-up · runs in your browser

The 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 NN-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 M=numInputsM = \text{numInputs} be the number of active input channels u0(t),u1(t),…,uM−1(t)u_0(t), u_1(t), \dots, u_{M-1}(t), and let uidx(t)u_{\text{idx}}(t) be the control signal entering the index port idx.

The effective integer channel index kk is computed by rounding the index signal and clamping it to the allowable index range:

k=clamp⁡(round⁡(uidx(t)),  kmin⁡,  kmax⁡)k = \operatorname{clamp}\left( \operatorname{round}(u_{\text{idx}}(t)), \; k_{\min}, \; k_{\max} \right)

where:

[kmin⁡,kmax⁡]={[0,M−1],indexBase="0"[1,M],indexBase="1"[k_{\min}, k_{\max}] = \begin{cases} [0, M - 1], & \text{indexBase} = \text{"0"} \\ [1, M], & \text{indexBase} = \text{"1"} \end{cases}

The output y(t)y(t) routes the selected input channel corresponding to kk:

y(t)={uk(t),indexBase="0"uk−1(t),indexBase="1"y(t) = \begin{cases} u_k(t), & \text{indexBase} = \text{"0"} \\ u_{k-1}(t), & \text{indexBase} = \text{"1"} \end{cases}

If the selected data input port is unconnected, the block safely outputs 0.00.0.

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 11, 22, or 33 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 0,1,2,30, 1, 2, 3. 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 (kmin⁡k_{\min} or kmax⁡k_{\max}). 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 0.00.0 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.

Related Components

  • Switch: Two-input conditional selector with configurable threshold.
  • Relay: Binary threshold switch with hysteresis deadband.
  • Mux: Combines multiple scalar signals into a multiplexed vector.
  • Constant: Fixed signal source often used to feed reference test channels.