Chapter 5 Example 5: condition and nested condition in algorithm
From the principal window,
choose File / Save as
and save your fifth application under your tutorial folder
with the name example5.
5.1 An algorithm with condition
5.1.1 Sensors x and i, actuator o
To create the sensors and the actuator:
- from the algorithm window: + green button
→ dialog window: Sensor x;
- from the algorithm window: + green button
→ dialog window: Sensor i;
- from the algorithm window: + green button
→ dialog window: Actuator o.
5.1.2 Function switch1
To create the switch1 function:
- from the algorithm window: + green button
→ dialog window: switch1;
- in the switch1 definition window:
- contextual menu → Add port
→ dialog window: ? int x ? int i ! int o,
- contextual menu → Create Condition
→ dialog window: x=1 x=2 x=3 x=4
(cf. figure 5.1):
Figure 5.1: Create Condition |
- click on the condition x=1
(cf. figure 5.2)
and create a reference div1<1>
to the definition int/Arit_div,
Figure 5.2: Condition x=1 |
- click on the condition x=2
(cf. figure 5.3)
and create a reference div2<1>
to the definition int/Arit_div,
Figure 5.3: Condition x=2 |
- click on the condition x=3
(cf. figure 5.4)
and connect the port i to the port o,
Figure 5.4: Condition x=3 |
- click on the condition x=4
(cf. figure 5.5)
and create a reference mul4<1>
to the definition int/Arit_mul;
Figure 5.5: Condition x=4 |
- create dependences between the references.
5.1.3 Algorithm AlgorithmMain1
The algorithm looks like the figure 5.6.
Figure 5.6: AlgorithmMain1 of the Example 5 |
5.2 An algorithm with nested condition
5.2.1 Sensors x and i, actuator o
Use previous definitions
(cf. 5.1.1).
5.2.2 Function switch2
To create the switch2 function:
- from the algorithm window: + green button
→ dialog window: switch2;
- in its definition window:
- contextual menu → Add port
→ dialog window: ? int x ? int y ! int o,
- contextual menu → Create Condition
→ dialog window: y=1 y=2,
- click on the condition y=1
(cf. figure 5.7)
and create the function mul1<1>
of the definition Arit_mul from int library,
Figure 5.7: Condition y=1 |
- click on the condition y=2
(cf. figure 5.8)
and create a reference switch1
to the definition switch1;
Figure 5.8: Condition y=2 |
- create dependences between the references.
5.2.3 Algorithm AlgorithmMain2
The algorithm looks like the figure 5.9.
Figure 5.9: AlgorithmMain2 of the Example 5 |
From the principal window,
choose File / Close.
In the dialog window, click on the Save button.