User Tools

Site Tools


getting_started:tutorials:mockrobot

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
getting_started:tutorials:mockrobot [2019/04/25 11:17] – [Mock Robot Example] grafgetting_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 with examplesNavigate to ''examples/mockRobotExample''. Start the program with +This tutorial demonstrates an EEROS application complete with a control system, a safety system, and a sequencer. You can find the code under [[https://github.com/eeros-project/eeros-framework/blob/master/examples/system/MockRobotExample.cpp|MockRobotExample.cpp]]. 
 + 
 +Start the program with 
 <code cpp> <code cpp>
-./mockRobotExample+$ sudo ./examples/system/mockRobotExample
 </code> </code>
  
Line 8: Line 10:
 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 ans started. After this the executor starts running.+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 and started. After this the executor starts running.
  
 <code cpp> <code cpp>
Line 24: Line 26:
   MainSequence mainSeq("Main Sequence", sequencer, cs, ss, sp);   MainSequence mainSeq("Main Sequence", sequencer, cs, ss, sp);
   sequencer.addSequence(mainSeq);   sequencer.addSequence(mainSeq);
-  mainSeq.start();+  mainSeq();
   
   ...   ...
Line 46: 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.
-[{{ :getting_started:tutorials:mockrobotsafetysystem.png?400 |//Safety system with levels and events.//}}]+[{{ :getting_started:tutorials:mockrobotss.jpg?220 |//Safety system with levels and events.//}}]
 The event ''abort'' can be triggered in all levels except ''slOff''. The safety system starts in the level ''slHoming''. As soon as the homing is complete the safety level switches to ''slReady''. The sequencer can then cause the safety system to change to level ''slMoving'' The event ''abort'' can be triggered in all levels except ''slOff''. The safety system starts in the level ''slHoming''. As soon as the homing is complete the safety level switches to ''slReady''. The sequencer can then cause the safety system to change to level ''slMoving''
  
Line 58: Line 60:
       } else if(ss.getCurrentLevel() == sp.slReady) {       } else if(ss.getCurrentLevel() == sp.slReady) {
         wait(2);         wait(2);
 +        cs.sw.switchToInput(1);
         ss.triggerEvent(sp.startMoving);         ss.triggerEvent(sp.startMoving);
       } else if(ss.getCurrentLevel() == sp.slMoving) {       } else if(ss.getCurrentLevel() == sp.slMoving) {
Line 64: Line 67:
       wait(0.1);       wait(0.1);
     }     }
 +    return 0;
   }   }
 </code> </code>
Line 76: Line 80:
   
   int action() {   int action() {
-    cs.setpointX.setValue(0.1); +    cs.setpoint.setValue({0.10.1});
-    cs.setpointY.setValue(0.1);+
   }   }
   bool checkExitCondition() {   bool checkExitCondition() {
-  bool done = cs.iX.getOut().getSignal().getValue() >= 1.0 && cs.iY.getOut().getSignal().getValue() >= 1.0; +    Matrix<2,1,double> val = cs.i.getOut().getSignal().getValue()
-    if (cs.iX.getOut().getSignal().getValue() >= 1.0) cs.setpointX.setValue(0); +    bool done = val[0] >= 1.0 && val[1] >= 1.0; 
-    if (cs.iY.getOut().getSignal().getValue(>= 1.0) cs.setpointY.setValue(0);+    if (val[0] >= 1.0) cs.setpoint.setValue({0cs.setpoint.getValue()[1]})
 +    if (val[1] >= 1.0) cs.setpoint.setValue({cs.setpoint.getValue()[0], 0});
     if (done) ss.triggerEvent(sp.homingDone);     if (done) ss.triggerEvent(sp.homingDone);
     return done;     return done;
   }   }
-private: 
   MockRobotControlSystem& cs;   MockRobotControlSystem& cs;
 +  SafetySystem& ss;
 +  MockRobotSafetyProperties& sp;
 }; };
 </code> </code>
Line 99: Line 104:
   MoveUp(std::string name, Sequence* caller, MockRobotControlSystem& cs) : Step(name, caller), cs(cs) { }   MoveUp(std::string name, Sequence* caller, MockRobotControlSystem& cs) : Step(name, caller), cs(cs) { }
   int action() {   int action() {
-    cs.setpointX.setValue(0.7)+    Matrix<2,1,double> dest{8.2, 27.0}
-    cs.setpointY.setValue(0.3);+    cs.pp.move(dest); 
 +    return 0;
   }   }
-  bool checkExitCondition() {return cs.iX.getOut().getSignal().getValue() >= 5.0;} +  bool checkExitCondition() {return cs.pp.endReached();}
-private:+
   MockRobotControlSystem& cs;   MockRobotControlSystem& cs;
 }; };
Line 111: Line 116:
   MoveDown(std::string name, Sequence* caller, MockRobotControlSystem& cs) : Step(name, caller), cs(cs) { }   MoveDown(std::string name, Sequence* caller, MockRobotControlSystem& cs) : Step(name, caller), cs(cs) { }
   int action() {   int action() {
-    cs.setpointX.setValue(-0.6); +    Matrix<2,1,double> dest{-5, 3}; 
-    cs.setpointY.setValue(-0.3);+    cs.pp.move(dest); 
 +    return 0;
   }   }
-  bool checkExitCondition() {return cs.iX.getOut().getSignal().getValue() <= -5.0;} +  bool checkExitCondition() {return cs.pp.endReached();}
-private:+
   MockRobotControlSystem& cs;   MockRobotControlSystem& cs;
 }; };
Line 131: Line 136:
         moveDown();         moveDown();
       }       }
 +      return 0;
     }     }
-private: 
   MoveUp moveUp;   MoveUp moveUp;
   MoveDown moveDown;   MoveDown moveDown;
getting_started/tutorials/mockrobot.1556183833.txt.gz · Last modified: 2019/04/25 11:17 by graf