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/29 21:48] – [Headline] graf | eeros_architecture:sequencer:subsequence [2015/10/31 09:05] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Simple Example ===== | ===== Simple Example ===== | ||
| - | We first define a class for the sub- or 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 35: | 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 43: | 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. The following figure shows the flow of action. | + | 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 ===== | ===== Nonblocking Call of a Subsequence ===== | ||
| Line 55: | Line 65: | ||
| We first define a class for the sub- or secondary sequence as follows: | We first define a class for the sub- or secondary sequence as follows: | ||
| <code cpp> | <code cpp> | ||
| - | class SequenceB : public Sequence< | + | class SequenceB : public Sequence<> |
| public: | public: | ||
| - | | + | |
| - | void run(double z) { | + | void run() { |
| - | robot.moveXY(z); | + | robot.moveZ(5); |
| + | sleep(3); | ||
| yield(); | yield(); | ||
| - | robot.moveXY(0); | + | robot.moveZ(0); |
| } | } | ||
| Line 70: | Line 81: | ||
| </ | </ | ||
| - | The //run()// method | + | The //run()// method |
| We can now define our first or main sequence with | We can now define our first or main sequence with | ||
| Line 77: | Line 88: | ||
| class SequenceA : public Sequence<> | class SequenceA : public Sequence<> | ||
| public: | public: | ||
| - | SequenceA(std:: | + | SequenceA(std:: |
| void run() { | void run() { | ||
| robot.moveXY(10, | robot.moveXY(10, | ||
| - | | + | |
| - | robot.moveXY(-10, | + | robot.moveXY(-10, |
| - | | + | |
| robot.moveXY(0, | robot.moveXY(0, | ||
| } | } | ||
| Line 89: | Line 100: | ||
| private: | private: | ||
| Robot& robot; | Robot& robot; | ||
| - | | + | |
| }; | }; | ||
| </ | </ | ||
| - | In our main program we declare a sequencer for the main sequence. | + | In our main program we declare a sequencer for the main sequence. |
| + | <code cpp> | ||
| + | int main() { | ||
| + | Sequencer sequencerA, sequencerB; | ||
| + | SequenceB seqB(" | ||
| + | SequenceA seqA(" | ||
| + | sequencerB.addCmdSequence(& | ||
| + | sequencerA.start(& | ||
| + | sequencerA.join(); | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | In the second step of the sequence A the sequence is started in its own thread. After this both run concurrently. | ||
| + | The following figure shows the flow of action. | ||
| + | {{ : | ||
eeros_architecture/sequencer/subsequence.1446151707.txt.gz · Last modified: 2015/10/29 21:48 (external edit)