Switch
LogicRoutes 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 , the configured threshold , and the active criteria:
The specific boolean condition is selected via the criteria parameter:
- For
criteria = "u2 >= threshold":
- For
criteria = "u2 > threshold":
- For
criteria = "u2 ~= 0":
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 ( or ) 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 ( for alarm, for normal) drives the selector port. Under normal operation (), normal power regulation commands on in2 pass through. When overspeed is detected (), the Switch block immediately overrides the actuator command with full aerodynamic blade feathering on in1 ( 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 routesin2(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 ( or ).
- MinMax: Dynamically selects signals based on mathematical extrema ( or ).