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:02] – [The Full Picture] graf | getting_started:tutorials:mockrobot [2021/03/31 17:45] (current) – [Safety 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. The moving of a robot is pretended by using integrators summing up. This represents the position on an axis. Before a robot can be moved it has usually to be homed. | This example does not need any hardware. The moving of a robot is pretended by using integrators summing up. This represents the position on an axis. Before a robot can be moved it has usually to be homed. | ||
- | 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 43: | Line 48: | ||
===== 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 ===== | ||
+ | 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> | ||
- | | + | |
- | if (slHoming.getNofActivations() == 1) | + | while(Sequencer:: |
- | | + | if (ss.getCurrentLevel() == sp.slHoming) { |
- | if (cs.iX.getOut().getSignal().getValue() >= 1.0) cs.setpointX.setValue(0); | + | |
- | if (cs.iY.getOut().getSignal().getValue() >= 1.0) cs.setpointY.setValue(0); | + | } else if(ss.getCurrentLevel() == sp.slReady) { |
- | if (Sequencer:: | + | wait(2); |
- | | + | cs.sw.switchToInput(1); |
- | }); | + | ss.triggerEvent(sp.startMoving); |
+ | } else if(ss.getCurrentLevel() == sp.slMoving) { | ||
+ | upDown(); | ||
+ | | ||
+ | wait(0.1); | ||
+ | } | ||
+ | return 0; | ||
+ | } | ||
</ | </ | ||
- | + | Depending on the safety level the homing or the upDown sequence | |
- | As a first step the sequence " | + | |
- | This sequence moves the robot slowly to its limit, see next chapter. As soon as one of the axis reaches this limit, the movement | + | |
- | This level does nothing except | + | |
- | + | ||
- | <code cpp> | + | |
- | slReady.setLevelAction([=](SafetyContext* privateContext) { | + | |
- | if (slReady.getNofActivations() * ts >= 2) | + | |
- | privateContext-> | + | |
- | }); | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | This level simply starts the " | + | |
- | <code cpp> | + | |
- | slMoving.setLevelAction([& | + | |
- | if (slMoving.getNofActivations() == 1) | + | |
- | Sequencer:: | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | ===== Sequencer ===== | + | |
- | The main programm registered two sequences. The first of the two is responsible | + | |
<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 101: | Line 102: | ||
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 113: | Line 114: | ||
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 125: | Line 126: | ||
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.1553770962.txt.gz · Last modified: 2019/03/28 12:02 by graf