# Real-Time Robotics Framework

### Sidebar

eeros_architecture:control_system:available_blocks:switch

# Switch

A switch block allows to select one of several input signals to write to its output. The code below shows a switch with 3 inputs where the second input is selected.

Switch<3> sw;
sw.switchToInput(1);

You can also query the index of the selected input with

int index = sw.getCurrentInput();

By calling

setActiveLevel(safetySystem, safetyLevel);

the switch will only switch if the current safety level is equal or greater than the safety level set by this method.

### Auto Switching

It is possible to configure a switch in such a way, that if the selected input reaches a given level within a small margin the switch does switch automatically. For this purpose you have to specify a condition with

setCondition(T switchLevel, T delta, uint8_t index)

where switchlevel is the level the switch has to reach within the margin delta. index is the new index of the input. As soon as the signal type of the input is no longer the default type (double) but, for instance, a vector (Vectors and Matrices) you have to keep in mind that the condition for the switching has to be met for each single element of the vector!
Before the switching can take place the switch must be armed with

arm();

The function

triggered();

queries the state of the switch function. It will return true as soon as the auto switching happened.
The switching might lead to a change in the safety level. In order to be able to trigger a safety event you have to register such an event beforehand.

registerSafetyEvent(SafetySystem* ss, SafetyEvent* e);

### Combining

Switched can be combined. If switch 1 is combined with switch 2 and switch one changes its position then switch 2 will simultaneously change its position as well. To combine switches you have to call

s1.combine(s2)

where s2 is the switch whose position will follow the position of s1. You can combine as many switches as you want.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.228859543800354, "perplexity": 1039.1275585955468}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-39/segments/1631780055601.25/warc/CC-MAIN-20210917055515-20210917085515-00603.warc.gz"}