User Tools

Site Tools


eeros_architecture:safety_system:usage

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
Last revisionBoth sides next revision
eeros_architecture:safety_system:usage [2016/11/03 16:43] grafeeros_architecture:safety_system:usage [2017/01/28 17:33] – [Setup a Safety System] graf
Line 1: Line 1:
-====== Create a Safety System ====== +====== Setup a Safety System ====== 
-The safety system is implemented as singletonIts constructors are private, and you can get an instance by calling +Every EEROS system can have exactly one safety system. As first step you have to define your safety properties as described in [[eeros_architecture:safety_system:properties|]]After this you create an instance of these properties and assign it to your safety system as follows 
 <code cpp> <code cpp>
-  SafetySystem &safetySys = SafetySystem::instance();+MySafetyProperties safetyProperties; 
 +SafetySystem safetySys(safetyProperties, period);
 </code> </code>
  
-The central attribute of the safety system is its //currentLevel//Of course, this level can be queried by everyone but only set by the safety system itself+The executor will later run the safety system as its main taskThe safety system will always be the task with the highest run frequency. The parameter ''period'' determines this frequency
  
-The most important function is its run method. This method is called periodically by a high priority thread. Here's how it works: 
 <code cpp> <code cpp>
-  void SafetySystem::run() { +// Create and run executor 
-   +auto& executor eeros::Executor::instance(); 
-    // 1) Make local copy of currentLevel +executor.setMainTask(safetySys);
-    SafetyLevel* level = currentLevel; +
- +
-    // 2) Read inputs +
-    for(auto ia : level->inputAction) { +
-      if(ia != nullptr) ia->check(&privateContext); +
-    } +
-     +
-    // 3) Execute level action +
-    if(level->action !nullptr) level->action(&privateContext); +
-     +
-    // 4) Set outputs +
-    for(auto oa : level->outputAction) { +
-      if(oa != nullptr) oa->set(); +
-    } +
-  }+
 </code> </code>
 +
  
 ===== Changing the Safety Level ===== ===== Changing the Safety Level =====
-The only possibility to change the safety level is through the method //triggerEvent//.+The central attribute of the safety system is its //currentLevel//. Of course, this level can be queried by everyone but only set by the safety system itself.  
 +The only possibility to change the safety level is through the method //triggerEvent//\\ 
 +Triggering an event can be done by 
 +  * the safety system itself (as a level action or by checking an critical input) 
 +  * the control system through a special ''SignalChecker'' block 
 +  * the sequencer 
  
-====== Safety System Usage ====== +An event can be triggered by the control system or the sequencer by calling: 
-Since the safety system and the HAL (hardware abstraction layer or hardware access layerare strongly coupled it makes sense to show the usage of both systems on this page.+<code cpp> 
 +safetySys.triggerEvent(safetyProperties.seStartRunning)
 +</code> 
 +Please make sure to declare a safety event public if triggered by the control system or the sequencer. Private event can be triggered solely by the safety system itself
  
  
-Sometimes you need to fire an event e.g. swInitDone: 
-<code c> 
-safetySys.triggerEvent(swInitDone, privateContext); 
-</code> 
  
-The C-style definition in class //SafetySystem//: 
-<code c> 
-void triggerEvent(uint32_t event); 
-</code> 
  
-===== Watchdog Output ==== 
-The last thing to do, is to set an watchdog output, which will be toggled on every execution of //run()//. This can easily be done with: 
-<code c> 
-SystemOutput<bool>* watchdog = hal.getLogicSystemOutput("watchdog"); 
-safetySys.setWatchdogOutput(watchdog); 
-</code> 
  
-===== Setting Up The System ===== 
  
-Before the safety system can be started, you have to define the entry level: 
-<code c> 
-safetySys.setEntryLevel(off); 
-</code> 
- 
-Finally assign the safety system as the main task of the executor, so that the //run()// method will be called periodically (every millisecond, for example).  
-<code c> 
-executor.setMainTask(safetySys); 
-</code>  
eeros_architecture/safety_system/usage.txt · Last modified: 2017/01/28 17:33 by 127.0.0.1