User Tools

Site Tools


eeros_architecture:sequencer:subsequence

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
eeros_architecture:sequencer:subsequence [2015/10/29 21:55] – [Simple Example] grafeeros_architecture:sequencer:subsequence [2015/10/31 09:05] (current) – external edit 127.0.0.1
Line 14: Line 14:
   
   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, -20);     robot.moveXY(10, -20);
-    seqB(5); +    sequenceB(5); 
-    robot.moveXY(-10, -30); +    robot.moveXY(-10, 30); 
-    seqB(5);+    sequenceB(5);
     robot.moveXY(0, 0);     robot.moveXY(0, 0);
   }   }
Line 43: Line 43:
 private:  private: 
   Robot& robot;   Robot& robot;
-  SequenceB seqB;+  SequenceB sequenceB;
 }; };
 </code> </code>
-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("Seq A", &sequencer, robot); 
 +  sequencerA.start(&seqA); 
 +  sequencerA.join(); 
 +}; 
 +</code> 
 +The following figure shows the flow of action. 
 +{{ :eeros_architecture:sequencer:subsequenceblocking.png?400 |}}
 ===== Nonblocking Call of a Subsequence ===== ===== Nonblocking Call of a Subsequence =====
  
Line 61: Line 71:
   void run() {   void run() {
     robot.moveZ(5);     robot.moveZ(5);
-    sleep();+    sleep(3);
     yield();     yield();
     robot.moveZ(0);     robot.moveZ(0);
Line 71: Line 81:
 </code> </code>
  
-The //run()// method is called with one parameter of type double. There is no return value. For this reasonour class has to extend the class ''sequence'' with the template parameters ''<void,double>''. To keep the example as simple as possible we omit the implementation of //init()/////exit()// functions and pre and post condition check functions.+The //run()// method simply moves in z direction andafter a pause, returns to the original position.
  
 We can now define our first or main sequence with  We can now define our first or main sequence with 
Line 78: Line 88:
 class SequenceA : public Sequence<> { class SequenceA : public Sequence<> {
 public: public:
-  SequenceA(std::string name, Sequencer* seq, Robot& r) : Sequence<>(name, seq), robot(r), seqB("Seq B", seq, r) { }+  SequenceA(std::string name, Sequencer* seq, Robot& r, Sequencer& seqB) : Sequence<>(name, seq), robot(r), seqB(seqB) { }
   
   void run() {   void run() {
     robot.moveXY(10, -20);     robot.moveXY(10, -20);
-    seqB(5); +    sequencerB.start(0U); 
-    robot.moveXY(-10, -30); +    robot.moveXY(-10, 30); 
-    seqB(5);+    sequencerB.join();
     robot.moveXY(0, 0);     robot.moveXY(0, 0);
   }   }
Line 90: Line 100:
 private:  private: 
   Robot& robot;   Robot& robot;
-  SequenceB seqB;+  Sequencer& sequencerB;
 }; };
 </code> </code>
-In our main program we declare a sequencer for the main sequence. The same sequencer will also handle the subsequence. Sequence A and do not run concurrently. The following figure shows the flow of action.+In our main program we declare a sequencer for the main sequence. A second sequencer will run the subsequence.  
 +<code cpp> 
 +int main() { 
 +  Sequencer sequencerA, sequencerB; 
 +  SequenceB seqB("Seq B", &sequencerB, robot); 
 +  SequenceA seqA("Seq A", &sequencerA, robot, sequencerB); 
 +  sequencerB.addCmdSequence(&seqB); 
 +  sequencerA.start(&seqA); 
 +  sequencerA.join(); 
 +}; 
 +</code> 
 + 
 +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:subsequencenonblocking.png?400 |}}
eeros_architecture/sequencer/subsequence.1446152130.txt.gz · Last modified: 2015/10/29 21:55 by graf