Lesson 5: Conditional Behaviors and Behavior Compositions

Behavior Definition and Conditional Behaviors

A behavior is defined in <behaviors> section with a name bname

<behaviors>

    ...

    <bname macros="mname1, mname2,...">

        ...

        <aname group = "gname" .../>

        ...

    </bname>

    ...

</behaviors>

where aname  is the name of an automaton defined in <automata> and gname  is the name of a group defined in <robot>. Attribute "macros" is optional which defines a set of macros that can be used in the expressions of behavior specification attributes, including "group", "start", "offset", "phase", "period" and "cycles", as well as in conditional expressions described below. Unlike parameters, macros are set at the time when the program is loaded and remain constant.

A behavior can have conditional components. A conditional behavior is represented by

<bname macros="mname1, mname2,...">

    ...

<if cond = "C"

    ...

    <aname group = "gname" .../>

    ...

</if>

...

</bname>

where C  is a logical expression. Conditional behaviors are mostly used with control and sensors to steer different behaviors at run time; an automaton would only run while the condition is true. Without the explicit condition, the default is true. Fig. 5.1 shows a snake gait with conditional behaviors, by defining two separate custom controls: one for turning and the other for direction. The conditional behaviors switch between forward and backward gaits. A radio button control input is used here.

Figure 5.1 An example of conditional behaviors with radio button control input: snake_condition.xml

Behavior Compositions and Macros

Multiple behaviors can be composed sequentially in the <main> section:

<main cycles = "C">

    ...

    <bname time = "T" exit = "E" mname1 = "M1" mname2 = "M2" .../>

    ...

</main>

where bname  is the name of the behavior defined in <behaviors>, C, T  and E  are expressions, mname1, mname2  etc. are macro names in the "macros" attribute for behavior bname, and M1, M2  etc. are strings or constants that replace the macro names in this composition. Examples of macros will be shown in the next two lessons.

Just like phase automata, when there is no cycles, the cyclic mode is assumed. The default running time for a behavior is infinite and the default exit condition is false (i.e. never exit). The program sequentially runs each behavior, until its time expires or its exit condition becomes true. It runs for C  cycles if non-cyclic, otherwise, it loops forever. Fig. 5.2 shows an example of a behavior composition, which is composed of two behaviors: standup and walk. The walk gait is the same as "centipede_group.xml", except parameters are introduced for a better code.

Figure 5.2 An example of behavior composition: centipede_sequence.xml

Exercise 5.1 Modify centipede_sequence.xml so that it starts walking by a control input. [Median]

Exercise 5.2 Modify centipede_sequence.xml so that it can turn by a control input. [Median]


< Previous Lesson | Next Lesson >

Index