sot-doc  1.1.0
Documentation entry point for the Stack-Of-Tasks
doc/Tutorial_Dyn_Graph_101.md
1 # Dynamic-graph 101 {#tutorial_dyn_graph_101}
2 
3 \section tutorial_first_introduction Introduction
4 
5 We assume that the stack of tasks has been installed using the installation instruction provided \ref c_installation_detailed.
6 
7 \section tutorial_dyngrp_101 First steps with dynamic graph
8 
9 This first tutorial focuses on the dynamic-graph mecanism, which is the backbone of the stack of tasks framework.
10 
11 As a toy example, let’s realize this operation res=(a+b)*(c+d) using dynamic-graph elements. The corresponding code would be this:
12 
13  from dynamic_graph import plug
14  from dynamic_graph.sot.core.operator import Add_of_double
15  from dynamic_graph.sot.core.operator import Multiply_of_double
16  a=1
17  b=2
18  c=3
19  d=4
20 
21  # Create the entities
22  ad1 = Add_of_double('ad1')
23  ad2 = Add_of_double('ad2')
24  mult = Multiply_of_double('mult')
25 
26  # Fix the values of the input for the first operation
27  ad1.sin1.value = a
28  ad1.sin2.value = b
29 
30  # Fix the values of the input for the second operation
31  ad2.sin1.value = c
32  ad2.sin2.value = d
33 
34  # plug all the signals
35  plug(ad1.sout, mult.sin0)
36  plug(ad2.sout, mult.sin1)
37 
38 In order to obtain the result of the multiplication, let’s do:
39 
40  mult.sout.value
41  #> 0
42 
43 This is normal. At the creation of an entity, each of the signals has a default value associated to the time 0. In order to have the new value, it is necessary to increment the time, so as to trigger the recomputation.
44 
45  mult.sout.time
46  #> 0
47  mult.sout.recompute(1)
48  mult.sout.value
49  #> 21
50 
51 Let’s now change one of the inputs of the entity ad1.
52 
53  ad1.sin1.value = 0
54 
55 The result becomes:
56 
57  mult.sout.recompute(2)
58  mult.sout.value
59  #> 14
60 
61 Note that the intermediary signal ad1.sout, has been updated, while ad2.sout hasn’t:
62 
63  ad1.sout.time
64  #> 2
65  ad2.sout.time
66  #> 1
67 
68 \section tutorials_dyngrp_operations Dynamic-graph operations
69 
70 Here is a list of some basic operations that can be run on the entities/signals.
71 
72 \subsection tutorial_first_entity Entity manipulation
73 
74 entity.help(): Displays the help for an entity, namely the commands with their description
75 
76  ad1.help()
77  Linear combination of inputs
78  - input double
79  - double
80  - output double
81  sout = coeff1 * sin0 + coeff2 * sin1
82  Coefficients are set by commands, default value is 1.
83 
84  List of commands:
85  -----------------
86  setCoeff1: Set the coeff1.
87  setCoeff2: Set the coeff2.
88 
89 entity.help('command'): Displays the complete help for the command (number of argument…)
90 
91  ad1.help('setCoeff1')
92  setCoeff1:
93 
94  Set the coeff1.
95 
96  Input:
97  - a double.
98  Void return.
99 
100 entity.commands() Returns the list of commands of an entity, without description
101 
102  ad1.commands()
103  ('setCoeff1', 'setCoeff2')
104 
105 entity.displaySignals(): Lists the signals of an entity, indicates whether they are plugged or not.
106 
107 AUTOPLUGGED: the signal is plugged to a signal of this entity, eventually internal</li>
108 PLUGGED: the signal is plugged to another one, from an other entity</li>
109 UNPLUGGED: the signal is not plugged. Requiring its recomputation will cause some issues</li>
110 
111  ad1.displaySignals()
112  --- <ad1> signal list:
113  |-- <Sig:Add_of_double(ad1)::input(double)::sin0> (Type Cst) AUTOPLUGGED
114  |-- <Sig:Add_of_double(ad1)::input(double)::sin1> (Type Cst) AUTOPLUGGED
115  `-- <Sig:Add_of_double(ad1)::output(double)::sout> (Type Fun)
116 
117 \subsection tutorial_first_signal_manipulation Signal manipulation
118 
119 entity.signal.value: Returns the current value of a signal
120 
121  ad1.sin0.value
122  0.0
123 
124 entity.signal.time: Returns the current time of a signal
125 
126  ad1.sin1.time
127  2
128 
129 entity.signal.recompute(T): Force the recomputation of the signal for time T (only effective it the given time is greater than the current time).
130 
131 
132 \section tutorial_going_further Going further
133 
134 More details on the internal graph structure used in the stack of tasks framework are provided in the dynamic-graph-tutorial.
135