getting_started:tutorials:mockrobot
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| getting_started:tutorials:mockrobot [2019/03/28 12:10] – [Sequencer] graf | getting_started:tutorials:mockrobot [2026/01/13 08:33] (current) – [Control System] ursgraf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Mock Robot Example ====== | ====== Mock Robot Example ====== | ||
| - | This tutorial demonstrates an EEROS application complete with a control system, a safety system, and a sequencer. You can find the code in the directory | + | This tutorial demonstrates an EEROS application complete with a control system, a safety system, and a sequencer. You can find the code under [[https:// |
| + | |||
| + | Start the program | ||
| + | <code cpp> | ||
| + | $ sudo ./examples/system/ | ||
| + | </ | ||
| ===== The Full Picture ===== | ===== The Full Picture ===== | ||
| - | This example does not need any hardware. | + | This example does not need any hardware. |
| - | The main application defines a control system and a safety system. The safety system is assigned as main task and passed to the executor. Further, a main sequence is defined and added to the sequencer | + | The main application defines a control system and a safety system. The safety system is assigned as main task and passed to the executor. Further, a main sequence is defined and added to the sequencer |
| <code cpp> | <code cpp> | ||
| Line 21: | Line 26: | ||
| MainSequence mainSeq(" | MainSequence mainSeq(" | ||
| sequencer.addSequence(mainSeq); | sequencer.addSequence(mainSeq); | ||
| - | mainSeq.start(); | + | mainSeq(); |
| ... | ... | ||
| Line 38: | Line 43: | ||
| The main program must wait for the sequencer to stop until it can finish, in order to terminate gracefully without any running thread. | The main program must wait for the sequencer to stop until it can finish, in order to terminate gracefully without any running thread. | ||
| ===== Control System ===== | ===== Control System ===== | ||
| - | The control system is very simple. | + | The control system is very simple. |
| + | |||
| + | [{{ : | ||
| In the constructor of the control system the blocks are created, connected, and the integrator are enabled. All of the blocks are added to a time domain which itself is passed to the executor. This time domain runs in parallel to the safety system task. | In the constructor of the control system the blocks are created, connected, and the integrator are enabled. All of the blocks are added to a time domain which itself is passed to the executor. This time domain runs in parallel to the safety system task. | ||
| ===== Safety System ===== | ===== Safety System ===== | ||
| The safety system has four levels and a couple of safety events to switch between these levels. | The safety system has four levels and a couple of safety events to switch between these levels. | ||
| - | [{{ : | + | [{{ : |
| The event '' | The event '' | ||
| ===== Sequencer ===== | ===== Sequencer ===== | ||
| - | The main sequence comprises of two subsequences and a step. The first of the two sequences is responsible for homing while the latter moves the robot up and down. It is defined as blocking, which causes it run in parallel to the main program and notably to the safety system which calls the start method of this sequence. | + | The main sequence comprises of two subsequences and a step. The first of the two sequences is responsible for homing while the latter moves the robot up and down. The main sequence does the following action: |
| <code cpp> | <code cpp> | ||
| int action() { | int action() { | ||
| Line 53: | Line 61: | ||
| if (ss.getCurrentLevel() == sp.slHoming) { | if (ss.getCurrentLevel() == sp.slHoming) { | ||
| homing(); | homing(); | ||
| + | } else if(ss.getCurrentLevel() == sp.slReady) { | ||
| wait(2); | wait(2); | ||
| - | } else if(ss.getCurrentLevel() == sp.slReady) { | + | cs.sw.switchToInput(1); |
| ss.triggerEvent(sp.startMoving); | ss.triggerEvent(sp.startMoving); | ||
| } else if(ss.getCurrentLevel() == sp.slMoving) { | } else if(ss.getCurrentLevel() == sp.slMoving) { | ||
| upDown(); | upDown(); | ||
| } | } | ||
| + | wait(0.1); | ||
| } | } | ||
| + | return 0; | ||
| } | } | ||
| </ | </ | ||
| + | Depending on the safety level the homing or the upDown sequence is started. In '' | ||
| <code cpp> | <code cpp> | ||
| class HomingSequence : public Sequence { | class HomingSequence : public Sequence { | ||
| public: | public: | ||
| - | HomingSequence(std:: | + | HomingSequence(std:: |
| + | | ||
| + | | ||
| int action() { | int action() { | ||
| - | cs.setpointX.setValue(0.1); | + | cs.setpoint.setValue({0.1, 0.1}); |
| - | cs.setpointY.setValue(0.1); | + | } |
| + | bool checkExitCondition() { | ||
| + | | ||
| + | bool done = val[0] >= 1.0 && val[1] >= 1.0; | ||
| + | if (val[0] >= 1.0) cs.setpoint.setValue({0, cs.setpoint.getValue()[1]}); | ||
| + | if (val[1] >= 1.0) cs.setpoint.setValue({cs.setpoint.getValue()[0], | ||
| + | if (done) ss.triggerEvent(sp.homingDone); | ||
| + | return done; | ||
| } | } | ||
| - | bool checkExitCondition() {return cs.iX.getOut().getSignal().getValue() >= 1.0 && cs.iY.getOut().getSignal().getValue() >= 1.0;} | ||
| - | private: | ||
| MockRobotControlSystem& | MockRobotControlSystem& | ||
| + | SafetySystem& | ||
| + | MockRobotSafetyProperties& | ||
| }; | }; | ||
| </ | </ | ||
| - | What does the sequence do? It's action method simply adjusts the set points of the two axis to a small positive value. That causes the position of the robot (represented by the two integrators) to slowly move upwards. The sequence, which in this case is a simple step, terminates as soon as its exit condition is met. That is when both axis reach the position of 1.0. | + | What does the sequence do? It's action method simply adjusts the set points of the two axis to a small positive value. That causes the position of the robot (represented by the two integrators) to slowly move upwards. The sequence, which in this case is a simple step, terminates as soon as its exit condition is met. That is when both axis reach the position of 1.0. As soon as one of the axis reaches the position of 1.0 its setpoint is zeroed in order to stop it moving further. On termination a safety event is triggered. |
| The second sequence " | The second sequence " | ||
| Line 85: | Line 105: | ||
| class MoveUp : public Step { | class MoveUp : public Step { | ||
| public: | public: | ||
| - | MoveUp(std:: | + | MoveUp(std:: |
| int action() { | int action() { | ||
| - | | + | |
| - | cs.setpointY.setValue(0.3); | + | cs.pp.move(dest); |
| + | return | ||
| } | } | ||
| - | bool checkExitCondition() {return cs.iX.getOut().getSignal().getValue() >= 5.0;} | + | bool checkExitCondition() {return cs.pp.endReached();} |
| - | private: | + | |
| MockRobotControlSystem& | MockRobotControlSystem& | ||
| }; | }; | ||
| Line 97: | Line 117: | ||
| class MoveDown : public Step { | class MoveDown : public Step { | ||
| public: | public: | ||
| - | MoveDown(std:: | + | MoveDown(std:: |
| int action() { | int action() { | ||
| - | cs.setpointX.setValue(-0.6); | + | |
| - | | + | |
| + | | ||
| } | } | ||
| - | bool checkExitCondition() {return cs.iX.getOut().getSignal().getValue() <= -5.0;} | + | bool checkExitCondition() {return cs.pp.endReached();} |
| - | private: | + | |
| MockRobotControlSystem& | MockRobotControlSystem& | ||
| }; | }; | ||
| Line 109: | Line 129: | ||
| class UpAndDownSequence : public Sequence { | class UpAndDownSequence : public Sequence { | ||
| public: | public: | ||
| - | UpAndDownSequence(std:: | + | UpAndDownSequence(std:: |
| + | | ||
| + | | ||
| + | | ||
| - | | + | |
| - | while (Sequencer:: | + | while (Sequencer:: |
| - | moveUp(); | + | moveUp(); |
| - | moveDown(); | + | moveDown(); |
| + | } | ||
| + | return 0; | ||
| } | } | ||
| - | } | ||
| - | private: | ||
| - | MockRobotControlSystem& | ||
| MoveUp moveUp; | MoveUp moveUp; | ||
| MoveDown moveDown; | MoveDown moveDown; | ||
getting_started/tutorials/mockrobot.1553771439.txt.gz · Last modified: 2019/03/28 12:10 by graf