⊕

Switch

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

Routes one of two input signals (in1 or in2) to the output terminal based on the evaluation of a control signal on the selector port against a configurable threshold and comparison criterion. Essential for conditional signal multiplexing, manual versus automatic control mode selection, emergency override logic, scheduled trajectory branching, and piecewise dynamic system modeling.

Mathematical Model

The output signal depends on the value of the selector input usel(t)u_{\text{sel}}(t), the configured threshold TT, and the active criteria:

y(t)={u1(t),if condition is trueu2(t),if condition is falsey(t) = \begin{cases} u_1(t), & \text{if condition is true} \\ u_2(t), & \text{if condition is false} \end{cases}

The specific boolean condition is selected via the criteria parameter:

  • For criteria = "u2 >= threshold":
y(t)={u1(t),if usel(t)≥Tu2(t),if usel(t)<Ty(t) = \begin{cases} u_1(t), & \text{if } u_{\text{sel}}(t) \ge T \\ u_2(t), & \text{if } u_{\text{sel}}(t) < T \end{cases}
  • For criteria = "u2 > threshold":
y(t)={u1(t),if usel(t)>Tu2(t),if usel(t)≤Ty(t) = \begin{cases} u_1(t), & \text{if } u_{\text{sel}}(t) > T \\ u_2(t), & \text{if } u_{\text{sel}}(t) \le T \end{cases}
  • For criteria = "u2 ~= 0":
y(t)={u1(t),if ∣usel(t)∣>10−9u2(t),if ∣usel(t)∣≤10−9y(t) = \begin{cases} u_1(t), & \text{if } |u_{\text{sel}}(t)| > 10^{-9} \\ u_2(t), & \text{if } |u_{\text{sel}}(t)| \le 10^{-9} \end{cases}

Inputs & Outputs

Direction ID Label Type Status
→ In selector Selector number Required
→ In in1 If ≥ 0 number Required
→ In in2 If < 0 number Required
← Out out Output number Output

Parameters

Parameters Label Type Default Description
threshold Threshold number 0
criteria Criteria select u2 >= threshold

Usage Examples

Example 1: Manual vs. Automatic Controller Mode Transfer

In industrial process automation, control systems allow human operators to toggle between manual setpoint control and automatic closed-loop feedback. Wiring a manual slider signal to in2, a PID controller output to in1, and a binary toggle switch (00 or 11) to selector routes the selected control command directly to the actuator, providing a clean operational mode switch.

Example 2: Emergency Safety Override and Shutdown Routing

In turbomachinery and offshore wind turbine control, an overspeed alarm flag (11 for alarm, 00 for normal) drives the selector port. Under normal operation (00), normal power regulation commands on in2 pass through. When overspeed is detected (11), the Switch block immediately overrides the actuator command with full aerodynamic blade feathering on in1 (90∘90^\circ pitch) to prevent catastrophic overspeed runaway.

Remarks & Best Practices

  • Input Port Correspondence: When the condition evaluates to true, the block outputs in1 (top signal); when false, it routes in2 (bottom signal).
  • Zero Switching Delay: Evaluated instantaneously within the current simulation step, introducing zero computational latency or transport delay into the signal path.
  • Solver Step Transients: Abruptly switching between signals with differing magnitudes creates step discontinuities that adaptive ODE solvers (e.g. RK45 or TR-BDF2) must resolve by reducing their local step size.
  • Glitch-Free Boundary Evaluation: Implemented in Rust with IEEE-754 precision to guarantee reliable switching behavior without numerical chatter around the threshold.

Related Components

  • Selector: Multi-channel index-based signal multiplexing.
  • Relay: Two-state switching block with hysteresis deadband between on and off thresholds.
  • Comparator: Compares inputs against thresholds to generate binary logic signals (00 or 11).
  • MinMax: Dynamically selects signals based on mathematical extrema (min⁡\min or max⁡\max).