getting_started:tutorials:sequencer4
This is an old revision of the document!
How to Organize Sequences and Steps
Sometimes its not obvious what sould go into a separate step and what to pack directly into a sequence. Let's study the following example.
A robot finished a homing sequence. It should move to a ready position before further action can happen. For this purpose a sequence readying
is implemented as follows:
class Readying : public Sequence { public: Readying(std::string name, Sequencer& seq) : Sequence(name, seq) {setNonBlocking();} int action() { cs.pathPlanner.move(readyPos); // we assume that the control system comprises of a path planner } bool checkExitCondition() { bool end = cs->pathPlanner.endReached(); if (end) safetySystem->triggerEvent(safetyProperties->readyDone); return end; } };
The sequence consists of a single action - set the final destination of the path planner. It will terminate as soon as the path planner has reached this position. Before returning it will trigger a safety event which causes the safety system to switch to the next level.
Alternative Solution
The same goal as above could be achieved as follows:
class Move : public Step { Move(std::string name, Sequencer& seq, BaseSequence* caller) : Step(name, seq, caller) { } int action() { cs.pathPlanner.move(readyPos); // we assume that the control system comprises of a path planner } bool checkExitCondition() { return cs->pathPlanner.endReached(); } } class Readying : public Sequence { public: Readying(std::string name, Sequencer& seq) : Sequence(name, seq), move("move", seq, this) {setNonBlocking();} int action() { move(readyPos); safetySystem->triggerEvent(safetyProperties->readyDone); } private: Move move; };
getting_started/tutorials/sequencer4.1530185781.txt.gz · Last modified: 2018/06/28 13:36 (external edit)