Lesson 6: Sensors and Conditional Transitions

Sensors

The use of sensors is similar to the use of control inputs. The current reading of a sensor that is specified in the robot's description can be referenced in two ways: 1. global: $n_name_arg where n is the logical ID of the module, name is the sensor name and arg is the argument for the sensor; or 2. local: $_n_name_arg where n is the relative position of the module in the group (type 1), or with respect to the current module (type 2). In addition to physical sensors, logical sensors can be defined as well, such as clocks, phases, etc. Sensors, like control inputs and parameters, can be used anywhere expression is allowed.

Fig. 6.1 shows a snake with one accelerometer for module with ID 0, and Fig. 6.2 shows an example of reference global sensors. In this example, macros are used to avoid writing the same type of behavior twice. At the behavior composition level, it switches the groups at run-time, according to the orientations of modules with respect to the gravity vector. (Here the accelerometer readings are from -100 to 100, and accel_z is the projection of the module's rotational axis to the gravity.)

Figure 6.1 A snake with one accelerometer: snake_with_accel.xml

Figure 6.2 An orientation-sensitive snake: snake_accel.xml
 

Conditional Transitions

Sensors and control can also be used in automata transitions, so that sensor-driven or control-driven transitions can be specified. In general, a phase automaton is specified in the section <automata> in the following format:

<aname states="sname1, sname2,..." times="T1[E1], T2[E2],..." />

where aname  is the name of the automata and sname1, sname2, etc. are names of the states defined in the  <states> section. Attribute "times" is optional; when it is absent, 1 is assumes for all states. If there is "times", the number of states in "states" and the number of time elements in "times" have to be the same. The nominal duration for the i'th state in "states" is specified by the i'th time element in "times", i.e., it is T  unless its exit condition E  becomes true before T  expires. The total nominal period for such an automaton is the sum of T' s. Both T  and E  are mathematical or logical expressions; T  evaluates to a numeric value and E  is Boolean. In the absence of an exit condition, the default expression is false, i.e., reducing to a time-driven transition.

Fig. 6.3 shows an example of a sensor-driven transition automaton. In this example, the modules in the "turn" group bend according to their interface orientation (obtained by accel_x) with respect to the gravity. The result is that they are straighten at the bending sections of the "loop" and are bent in the straight sections of the "loop", the whole loop would make left or right turns according to the control input.

Figure 6.3 An example of a sensor-driven automaton: loop_turn.xml

Exercise 6.1 Write a loop turning gait without the use of accelerometer sensors. [Hard]

Exercise 6.2 Modify centipede_sequence.xml so that it is reactive to the gravity like snake_accel.xml. [Median]

Exercise 6.3 Modify loop_turn.xml so that it reconfigure itself after falling to the ground. [Hard]


< Previous Lesson | Next Lesson >

Index