User Tools

Site Tools


eeros_architecture:sequencer:sequence

This is an old revision of the document!


Sequence

A sequence is a well defined course of steps. These steps run in a strictly sequential order until the sequence has finished or some condition causes the sequence to stop. In such a case the sequence could be repeated or another sequence could be started.

Blocking and Nonblocking Sequences

A main feature of a sequence is whether it blocks the flow of control during running through its steps or whether the steps run in parallel to the main flow of control.

Sequence B is blocking, sequence C is nonblocking

Sequence A runs. That is, all its steps run consecutively. After step 1 is done the sequence B is called. As B is blocking its two steps run while A is being blocked. Only after B finishes does the control return back to A where step 2 and step 3 are then executed. After this sequence C is called. As C is nonblocking its two steps run in parallel to the remaining steps of sequence A. A must wait for C to finish by calling join.
A nonblocking sequence will run in its own thread of execution while a nonblocking sequence always runs in the same thread as the calling sequence.

IMPORTANT The main sequence must always be defined as nonblocking. Otherwise, the main program would not return after calling start().

Sequence and Step

Every step is itself basically a sequence. However, a step is always blocking. All the other features such as preconditions and exit conditions as well as monitors are identical, see below. A user has to define her own sequences or steps with:

  1. Extend class Sequence or Step, respectively.
  2. Implement the function action(). This comprises the work which should be done. In case of a sequence this might be a sequence of steps. In case of a step it might be setting a new set position.
  3. Implement the ()-operator with parameters. This ensures that calling a sequence or step with parameters (e.g. step1(10, 3)) is possible.

Process Flow of a Sequence or Step

Each sequence or step runs as follows

Flow of a sequence or step
  1. Every sequence starts by checking the preconditions for this sequence to be met. If the test fails the sequence will immediately stop.
  2. The main work of the sequence is done in the function action(). Such a function can include any amount of work. However, this function should not block (do not use sleep, do not wait for some condition, do not wait for user input). This point is highly important, because a blocking action-function does not allow for checking exit conditions and monitors, see next point.
  3. The sequence than repetively checks for its exit condition to become true. As long as this is not the case, the sequence or step stays in this loop.
  4. In parallel to checking the exit condition the monitors of each sequence are also checked. For monitors see Conditions and Monitors. As soon as a monitor fires the sequence or step will terminate.

Simple Example

class MoveSequence : public Sequence {
public:
  MySequence(std::string name, Sequencer& seq, BaseSequence* caller, Robot& r) : Sequence<>(name, seq, this), robot(r) {setNonBlocking();}
 
  bool checkPreCondition() {
    log.trace() << "Checking precondition";
    return (robot.getPosZ() < 10);
  }
 
  int action() {
    robot.moveXY(10, -20);
    robot.moveXY(-10, -30);
    robot.moveXY(-10, -30);
  }
 
  bool checkPostCondition() {
    log.trace() << "Checking postcondition";
    if(robot.getPosX() < 0) return true;
    return false;
  }
 
  void exit() {
    log.trace() << "Sequence '" << getName() << "': " << "Exit running";
    sleep(1);
  }
 
private: Robot& robot;
};

The sequence moves a hypothetical robot in x,y,z direction.

eeros_architecture/sequencer/sequence.1502724303.txt.gz · Last modified: 2017/08/14 17:25 (external edit)