eeros_architecture:sequencer:subsequence
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| eeros_architecture:sequencer:subsequence [2015/10/28 11:48] – [Simple Example] graf | eeros_architecture:sequencer:subsequence [2015/10/31 09:05] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| =====Blocking Call of a Subsequence===== | =====Blocking Call of a Subsequence===== | ||
| - | If you want to save your own data in the sequence, | + | If several steps of a sequence |
| - | e.g. in the method // | + | |
| ===== Simple Example ===== | ===== Simple Example ===== | ||
| - | We first define a class for the secondary sequence as follows: | + | We continue with our hypothetical robot from the example in [[eeros_architecture: |
| <code cpp> | <code cpp> | ||
| class SequenceB : public Sequence< | class SequenceB : public Sequence< | ||
| public: | public: | ||
| - | | + | |
| void run(double z) { | void run(double z) { | ||
| - | robot.moveXY(z); | + | robot.moveZ(z); |
| yield(); | yield(); | ||
| - | robot.moveXY(0); | + | robot.moveZ(0); |
| } | } | ||
| Line 25: | Line 24: | ||
| </ | </ | ||
| - | The //run()// method is called with one parameter of type double. There is no return value. For this reason, our class has to extend the class '' | + | The //run()// method is called with one parameter of type double. There is no return value. For this reason, our class has to extend the class '' |
| We can now define our first or main sequence with | We can now define our first or main sequence with | ||
| Line 36: | Line 35: | ||
| void run() { | void run() { | ||
| robot.moveXY(10, | robot.moveXY(10, | ||
| - | | + | |
| - | robot.moveXY(-10, | + | robot.moveXY(-10, |
| - | | + | |
| robot.moveXY(0, | robot.moveXY(0, | ||
| } | } | ||
| Line 44: | Line 43: | ||
| private: | private: | ||
| Robot& robot; | Robot& robot; | ||
| - | SequenceB | + | SequenceB |
| }; | }; | ||
| - | |||
| - | |||
| </ | </ | ||
| + | In our main program we declare a sequencer for the main sequence. The same sequencer will also handle the subsequence. Sequence A and B do not run concurrently. | ||
| + | <code cpp> | ||
| + | int main() { | ||
| + | Sequencer sequencer; | ||
| + | SequenceA seqA(" | ||
| + | sequencerA.start(& | ||
| + | sequencerA.join(); | ||
| + | }; | ||
| + | </ | ||
| + | The following figure shows the flow of action. | ||
| + | {{ : | ||
| + | ===== Nonblocking Call of a Subsequence ===== | ||
| - | ====Non Blocking Call of a Sub-Sequence==== | + | A nonblocking subsequence has to run in its own thread. For this reason you need a separate subsequencer |
| - | Remark: Please use pointer | + | |
| - | A non-blocking sub-sequence has to be created as a thread, so you need a sub-sequencer for starting the new thread. | + | ==== Simple Example ==== |
| - | e.g.: | + | |
| - | <code c> | + | |
| - | MySequencer* subSequencer | + | |
| - | </ | + | |
| - | Here you can reuse an existing | + | We first define a class for the sub- or secondary |
| - | < | + | < |
| - | MyNonBlockingSubSequence* subSequence = dynamic_cast<MyNonBlockingSubSequence*>(eeros::sequencer::Sequence:: | + | class SequenceB : public Sequence<> |
| - | if(!subSequence){ | + | public: |
| - | | + | SequenceB(std::string name, Sequencer* seq, Robot& r) : Sequence< |
| - | } | + | |
| + | void run() { | ||
| + | | ||
| + | | ||
| + | yield(); | ||
| + | robot.moveZ(0); | ||
| + | | ||
| + | |||
| + | private: | ||
| + | Robot& robot; | ||
| + | }; | ||
| </ | </ | ||
| - | **Note:** | + | The //run()// method simply moves in z direction and, after a pause, returns |
| - | *The constructor of the //MyNonBlockingSequence// | + | |
| - | *Do not forget | + | |
| - | As soon as you have created the sub-sequence, | + | We can now define our first or main sequence with |
| - | < | + | < |
| - | | + | class SequenceA : public Sequence<> |
| + | public: | ||
| + | | ||
| + | |||
| + | void run() { | ||
| + | robot.moveXY(10, | ||
| + | sequencerB.start(0U); | ||
| + | robot.moveXY(-10, | ||
| + | sequencerB.join(); | ||
| + | robot.moveXY(0, | ||
| + | } | ||
| + | |||
| + | private: | ||
| + | Robot& robot; | ||
| + | Sequencer& | ||
| + | }; | ||
| </ | </ | ||
| - | + | In our main program we declare a sequencer for the main sequence. A second sequencer will run the subsequence. | |
| - | In an other step of the superior | + | < |
| - | < | + | int main() { |
| - | //Here we wait for the subsequencer Thread | + | Sequencer |
| - | eeros:: | + | SequenceB seqB("Seq B", & |
| - | if(seq && seq-> | + | SequenceA seqA("Seq A", & |
| - | | + | |
| - | } | + | sequencerA.start(&seqA); |
| + | | ||
| + | }; | ||
| </ | </ | ||
| + | |||
| + | In the second step of the sequence A the sequence is started in its own thread. After this both run concurrently. The forth step of sequence A then waits for the sequence B to finish. | ||
| + | The following figure shows the flow of action. | ||
| + | {{ : | ||
eeros_architecture/sequencer/subsequence.1446029326.txt.gz · Last modified: 2015/10/28 11:48 by graf