eeros_architecture:sequencer:define_sequence
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
eeros_architecture:sequencer:define_sequence [2019/03/20 11:49] – [Waiting in Sequences or Steps] graf | eeros_architecture:sequencer:define_sequence [2023/02/26 00:25] (current) – [Add Parameters] ursgraf | ||
---|---|---|---|
Line 7: | Line 7: | ||
class MyStep : public Step { | class MyStep : public Step { | ||
public: | public: | ||
- | MyStep(std:: | + | MyStep(std:: |
... | ... | ||
}; | }; | ||
Line 13: | Line 13: | ||
class MySequence : public Sequence { | class MySequence : public Sequence { | ||
public: | public: | ||
- | MySequence(std:: | + | MySequence(std:: |
... | ... | ||
}; | }; | ||
</ | </ | ||
- | Your constructor usually includes a name for the sequence or step, a reference to the sequencer, and a reference to the caller of this object. The latter point is very important, because every step or sequence must know its caller or owner. \\ | + | Your constructor usually includes a name for the sequence or step, a reference to the caller of this object. The latter point is very important, because every step or sequence must know its caller or owner. \\ |
- | You then initialize the sequence in the initializer list by writing '' | + | You then initialize the sequence in the initializer list by writing '' |
In the body of your constructor you define the attributes of your sequence. This includes: | In the body of your constructor you define the attributes of your sequence. This includes: | ||
Line 28: | Line 28: | ||
class MySequence : public Sequence { | class MySequence : public Sequence { | ||
public: | public: | ||
- | MySequence(std:: | + | MySequence(std:: |
// this sequence will run in its own thread and concurrently to its caller | // this sequence will run in its own thread and concurrently to its caller | ||
setTimeoutTime(2.5); | setTimeoutTime(2.5); | ||
Line 37: | Line 37: | ||
</ | </ | ||
- | If you define a main sequence which has no calling sequence and which must be nonblocking per default, you can make use of a simpler | + | If you define a main sequence which has no calling sequence and which must be nonblocking per default, you can make use of another |
<code cpp> | <code cpp> | ||
class MainSequence : public Sequence { | class MainSequence : public Sequence { | ||
Line 53: | Line 53: | ||
step2(); | step2(); | ||
step3(); | step3(); | ||
+ | return 0; | ||
} | } | ||
</ | </ | ||
- | Its mandatory to implement this function. If not, no work is done and the step or sequence terminates immediately. \\ | + | Its mandatory to implement this function. If not, no work is done and the step or sequence terminates immediately. |
+ | A step or blocking sequence can return a value of type '' | ||
There might be sequences which should never stop. This must be done as shown below: | There might be sequences which should never stop. This must be done as shown below: | ||
<code cpp> | <code cpp> | ||
public: | public: | ||
int action() { | int action() { | ||
- | while (Sequencer::running) step1(); | + | while (state == SequenceState::running) step1(); |
// while (true) step1(); | // while (true) step1(); | ||
+ | return 0; | ||
} | } | ||
</ | </ | ||
- | This guarantees that the sequence could be stopped by the main program | + | This guarantees that the sequence could be aborted, resumed or restarted |
===== Define Preconditions ===== | ===== Define Preconditions ===== | ||
You may want to start a sequence or step only if a certain precondition is met. Override the function // | You may want to start a sequence or step only if a certain precondition is met. Override the function // | ||
Line 83: | Line 87: | ||
<code cpp> | <code cpp> | ||
int operator() (double x, double y) { | int operator() (double x, double y) { | ||
- | this.x = x; // store the first parameter into a local variable for further use | + | this->x = x; // store the first parameter into a local variable for further use |
- | this.y = y; // store the second parameter into a local variable for further use | + | this->y = y; // store the second parameter into a local variable for further use |
return start(); | return start(); | ||
} | } | ||
Line 109: | Line 113: | ||
===== Waiting in Sequences or Steps ===== | ===== Waiting in Sequences or Steps ===== | ||
- | As mentioned before you should never wait by using //sleep// in a action method. However, quite often it is desirable to wait for some time to pass when running sequences. How to do properly? Use the predefined step '' | + | As mentioned before you should never wait by using //sleep// in a action method. However, quite often it is desirable to wait for some time to pass when running sequences. How to do properly? Use the predefined step '' |
- | Contrary to a simple //sleep// it does not block the sequencer and the checking of monitors of this step or sequence continues unhindered. | ||
- | ===== Returning Values ===== | ||
- | A step or blocking sequence can return a value of type '' |
eeros_architecture/sequencer/define_sequence.1553078955.txt.gz · Last modified: 2019/03/20 11:49 by graf