Chapter 2 Example 2: parameters and hierarchy in algorithm
From the principal window,
choose File / Save as
and save your second application under your tutorial folder
with the name example2.
2.1 Definition of the function A
To create the A function definition:
- from the algorithm window:
- click on the + green button
→ dialog window: check Function
then type A
and click OK,
- click on the + green button
→ dialog window: check Constant
then type constante<X>
and click OK.
Create an integer output port o inside;
- in the A definition window:
- create a reference cst<T>
to the definition constante,
- create an integer input port a,
an integer output port o
(Contextual menu → Add port
cf. 1.1.3);
- from the algorithm window,
create a function definition calcul1,
with two integer input ports a and b
and an integer output port o; - in the A definition window:
- create a reference calc1
to the definition calcul1,
- add a parameter name
(cf. figure 2.1):
Field Parameters → T.
The function A
looks like the figure 2.2.
2.2 Definition of the function B
To create the B function definition:
- from the algorithm window: + green button
→ dialog window: B<X;Y>;
- in the B definition window:
- create references A1 and A2
to the definition A
(A1<X> A2<Y>),
- create
two integer input ports a and b,
one integer output port o,
and the function calc1
of the definition calcul1,
- add the parameters names X and Y
(field Parameters).
The function B
looks like the figure 2.3.
2.3 Definition of the algorithm with hierarchy
To create the Main algorithm:
- from the algorithm window: + green button
→ dialog window: Main;
- from the definition window,
define it as main;
- create a sensor input
with an integer output port o
and an actuator output
with an integer input port i;
- in the Main algorithm window,
create a reference B<1;2>
to the definition B,
a reference i1 i2
to the definition input,
and a reference out
to the definition output;
- create dependences between the references.
The algorithm looks like the figure 2.4.
Figure 2.4: Algorithm of the Example 2 |
From the principal window,
choose File / Close.
In the dialog window, click on the Save button.