1 # Dynamic-graph 101 {#tutorial_dyn_graph_101}
3 \section tutorial_first_introduction Introduction
5 We assume that the stack of tasks has been installed using the installation instruction provided \ref c_installation_detailed.
7 \section tutorial_dyngrp_101 First steps with dynamic graph
9 This first tutorial focuses on the dynamic-graph mecanism, which is the backbone of the stack of tasks framework.
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:
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
22 ad1 = Add_of_double('ad1')
23 ad2 = Add_of_double('ad2')
24 mult = Multiply_of_double('mult')
26 # Fix the values of the input for the first operation
30 # Fix the values of the input for the second operation
34 # plug all the signals
35 plug(ad1.sout, mult.sin0)
36 plug(ad2.sout, mult.sin1)
38 In order to obtain the result of the multiplication, let’s do:
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.
47 mult.sout.recompute(1)
51 Let’s now change one of the inputs of the entity ad1.
57 mult.sout.recompute(2)
61 Note that the intermediary signal ad1.sout, has been updated, while ad2.sout hasn’t:
68 \section tutorials_dyngrp_operations Dynamic-graph operations
70 Here is a list of some basic operations that can be run on the entities/signals.
72 \subsection tutorial_first_entity Entity manipulation
74 entity.help(): Displays the help for an entity, namely the commands with their description
77 Linear combination of inputs
81 sout = coeff1 * sin0 + coeff2 * sin1
82 Coefficients are set by commands, default value is 1.
86 setCoeff1: Set the coeff1.
87 setCoeff2: Set the coeff2.
89 entity.help('command'): Displays the complete help for the command (number of argument…)
100 entity.commands() Returns the list of commands of an entity, without description
103 ('setCoeff1', 'setCoeff2')
105 entity.displaySignals(): Lists the signals of an entity, indicates whether they are plugged or not.
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>
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)
117 \subsection tutorial_first_signal_manipulation Signal manipulation
119 entity.signal.value: Returns the current value of a signal
124 entity.signal.time: Returns the current time of a signal
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).
132 \section tutorial_going_further Going further
134 More details on the internal graph structure used in the stack of tasks framework are provided in the dynamic-graph-tutorial.