eeros_architecture:sequencer:sequence
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
eeros_architecture:sequencer:sequence [2017/08/10 21:42] – [Sequence and Step] graf | eeros_architecture:sequencer:sequence [2018/08/07 12:49] – [Waiting for Sequences to Finish] graf | ||
---|---|---|---|
Line 6: | Line 6: | ||
[{{ : | [{{ : | ||
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//. \\ | 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 | + | A nonblocking sequence will run in its own thread of execution while a blocking |
- | IMPORTANT The main sequence must always be defined as nonblocking. Otherwise, the main program | + | IMPORTANT The main sequence must always be defined as nonblocking. Otherwise, the flow of control |
===== Sequence and Step ===== | ===== 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: | + | 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 as described in [[.:define_sequence|]]. |
- | - Extend class // | + | |
- | - Implement the function // | + | |
- | - Implement the ()-operator with parameters. This ensures that calling a sequence or step (e.g. step1(10, 3)) is possible. | + | |
Line 22: | Line 20: | ||
- Every sequence starts by checking the preconditions for this sequence to be met. If the test fails the sequence will immediately stop. | - Every sequence starts by checking the preconditions for this sequence to be met. If the test fails the sequence will immediately stop. | ||
- | - The main work of the sequence is done in the function // | + | - The main work of the sequence is done in the function // |
- 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. | - 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. | ||
- | - In parallel to checking the exit condition the monitors of each sequence are also checked. For monitors see [[sdasd]]. As soon as a monitor fires the sequence or step will terminate. | + | - In parallel to checking the exit condition the monitors of each sequence are also checked. For monitors see [[.:monitors]]. As soon as a monitor fires the sequence or step will terminate. |
===== Simple Example ===== | ===== Simple Example ===== | ||
<code cpp> | <code cpp> | ||
- | class MySequence | + | class Move : public |
public: | public: | ||
- | | + | |
- | + | | |
- | | + | int action() { |
- | log.trace() << " | + | |
- | | + | |
} | } | ||
- | + | | |
- | | + | |
- | | + | |
- | if(robot.getPosZ() < 10) return true; | + | |
- | return false; | + | |
} | } | ||
+ | private: double xPos, yPos; | ||
+ | }; | ||
- | void run() { | + | class MoveSequence : public Sequence { |
- | robot.moveXY(10, | + | public: |
- | | + | MoveSequence(std:: |
- | robot.moveXY(-10, -30); | + | int action() { |
+ | robot.moveXY(10, | ||
+ | | ||
+ | robot.moveXY(22, 35); | ||
} | } | ||
- | + | private: | |
- | bool checkPostCondition() { | + | |
- | log.trace() << " | + | |
- | if(robot.getPosX() < 0) return true; | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | void exit() { | + | |
- | log.trace() << " | + | |
- | sleep(1); | + | |
- | | + | |
- | + | ||
- | private: Robot& robot; | + | |
}; | }; | ||
</ | </ | ||
- | The sequence moves a hypothetical robot in x,y,z direction. | + | The sequence |
+ | |||
+ | ===== Waiting for Sequences to Finish ===== | ||
+ | Usually at some stage in your program you have to wait for a given sequence to finish until the program should continue. There are two methods to accomplish this, '' | ||
+ | The former waits for a given sequence to finish running. It returns as soon as all the steps defined in the sequence have completed to run. However, it does not terminate the associated thread. This allows to restart the same sequence with '' | ||
+ | On the other hand, '' | ||
+ | IMPORTANT | ||
eeros_architecture/sequencer/sequence.txt · Last modified: 2020/05/22 11:08 by ursgraf